Files
Jack Hsu 346353de5c feat(webpack)!: deprecate webpack/rspack config compose helpers (#35867)
## Current Behavior

The `composePlugins`, `withNx`, `withWeb` (`@nx/webpack`, `@nx/rspack`)
and `withReact` (`@nx/rspack`, `@nx/react/webpack`) config helpers emit
an Nx-specific config function that only runs under the
`@nx/webpack:webpack` / `@nx/rspack:rspack` executors. There is no
deprecation signal steering users toward the inferred plugins.

## Expected Behavior

The helpers are deprecated for removal in Nx v24. They keep working in
v23 but log a warn-once-per-package message pointing at the real plugin
classes
(`NxAppWebpackPlugin`/`NxAppRspackPlugin`/`NxReactWebpackPlugin`/`NxReactRspackPlugin`)
and `nx g @nx/<bundler>:convert-to-inferred`. `@deprecated` JSDoc is
added to each helper, plus caution asides on the webpack config/plugins
and react asset docs. The warning fires only for user-authored configs:
the rspack executor, storybook preset, and next.js component-testing
preset compose these helpers internally and are wrapped in a suppression
scope. Warn-only, no codemod, no generator changes.

## Related Issue(s)

NXC-4324

<!-- polygraph-session-start -->
---
[View session information
↗](https://snapshot.app.trypolygraph.com/orgs/69cdc268b6aa527e4129c2b4/sessions/nxc-4324-2bacd010)
<!-- polygraph-session-end -->
2026-06-04 12:50:56 -04:00

37 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';
import { warnReactWithReactDeprecation } from '../src/utils/deprecation';
const processed = new Set();
export interface WithReactOptions extends WithWebOptions {}
/**
* @deprecated Will be removed in Nx v24. Use `NxReactWebpackPlugin` from
* `@nx/react/webpack-plugin` in a standard webpack config and run
* `nx g @nx/webpack:convert-to-inferred`. See
* https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.
* @param {WithReactOptions} pluginOptions
* @returns {NxWebpackPlugin}
*/
export function withReact(pluginOptions: WithReactOptions = {}) {
warnReactWithReactDeprecation();
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({}, config);
processed.add(config);
return config;
};
}