fix(webpack): add standardWebpackConfigFunction option when users opts for a standard config function (#20702)

This commit is contained in:
Jack Hsu 2023-12-11 22:18:27 -05:00 committed by GitHub
parent 99ec7d81cc
commit b527158ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 2 deletions

View File

@ -313,6 +313,11 @@
"default": true,
"x-deprecated": "Automatic configuration of Webpack is deprecated in favor of an explicit 'webpack.config.js' file. This option will be removed in Nx 18. See https://nx.dev/recipes/webpack/webpack-config-setup."
},
"standardWebpackConfigFunction": {
"type": "boolean",
"description": "Set to true if the webpack config exports a standard webpack function, not an Nx-specific one. See: https://webpack.js.org/configuration/configuration-types/#exporting-a-function",
"default": false
},
"extractLicenses": {
"type": "boolean",
"description": "Extract all licenses in a separate file, in the case of production builds only."

View File

@ -81,7 +81,11 @@ export async function* devServerExecutor(
// Only add the dev server option if user is composable plugin.
// Otherwise, user should define `devServer` option directly in their webpack config.
if (isNxWebpackComposablePlugin(userDefinedWebpackConfig)) {
if (
typeof userDefinedWebpackConfig === 'function' &&
isNxWebpackComposablePlugin(userDefinedWebpackConfig) &&
!buildOptions.standardWebpackConfigFunction
) {
config = await userDefinedWebpackConfig(
{ devServer },
{

View File

@ -50,6 +50,7 @@ export interface WebpackExecutorOptions {
// TODO(v18): Remove this option
/** @deprecated set webpackConfig and provide an explicit webpack.config.js file (See: https://nx.dev/recipes/webpack/webpack-config-setup) */
isolatedConfig?: boolean;
standardWebpackConfigFunction?: boolean;
main?: string;
memoryLimit?: number;
namedChunks?: boolean;

View File

@ -237,6 +237,11 @@
"default": true,
"x-deprecated": "Automatic configuration of Webpack is deprecated in favor of an explicit 'webpack.config.js' file. This option will be removed in Nx 18. See https://nx.dev/recipes/webpack/webpack-config-setup."
},
"standardWebpackConfigFunction": {
"type": "boolean",
"description": "Set to true if the webpack config exports a standard webpack function, not an Nx-specific one. See: https://webpack.js.org/configuration/configuration-types/#exporting-a-function",
"default": false
},
"extractLicenses": {
"type": "boolean",
"description": "Extract all licenses in a separate file, in the case of production builds only."

View File

@ -58,7 +58,11 @@ async function getWebpackConfigs(
? composePluginsSync(withNx(options), withWeb(options))
: withNx(options))({}, { options, context });
if (isNxWebpackComposablePlugin(userDefinedWebpackConfig)) {
if (
typeof userDefinedWebpackConfig === 'function' &&
isNxWebpackComposablePlugin(userDefinedWebpackConfig) &&
!options.standardWebpackConfigFunction
) {
// Old behavior, call the Nx-specific webpack config function that user exports
return await userDefinedWebpackConfig(config, {
options,