nx/packages/react/plugins/with-react.ts
Jack Hsu 9234fb30a6
feat(react): undeprecate svgr option for Next.js apps since --turbo supports it (#30909)
This PR delays deprecation of `svgr` for `@nx/next`, as Turbopack
supports it now.

This PR also deprecates all SVGR support for v22. It is not a well-used
feature, and the webpack plugin is not maintained. We'll ensure in v22
to add the SVGR webpack plugin to userland configs, but we'll not
maintain it ourselves moving forward.

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-04-29 08:44:21 -04:00

42 lines
1.2 KiB
TypeScript

import type { Configuration } from 'webpack';
import type { NxWebpackExecutionContext, WithWebOptions } from '@nx/webpack';
import { applyReactConfig } from './nx-react-webpack-plugin/lib/apply-react-config';
const processed = new Set();
export interface SvgrOptions {
svgo?: boolean;
titleProp?: boolean;
ref?: boolean;
}
export interface WithReactOptions extends WithWebOptions {
/**
* @deprecated Add SVGR support in your Webpack configuration without relying on Nx. See https://react-svgr.com/docs/webpack/
* TODO(v22): Remove this option and migrate userland webpack config to explicitly configure @svgr/webpack
* */
svgr?: boolean | SvgrOptions;
}
/**
* @param {WithReactOptions} pluginOptions
* @returns {NxWebpackPlugin}
*/
export function withReact(pluginOptions: WithReactOptions = {}) {
return function configure(
config: Configuration,
context: NxWebpackExecutionContext
): Configuration {
const { withWeb } = require('@nx/webpack');
if (processed.has(config)) return config;
// Apply web config for CSS, JSX, index.html handling, etc.
config = withWeb(pluginOptions)(config, context);
applyReactConfig(pluginOptions, config);
processed.add(config);
return config;
};
}