diff --git a/docs/generated/packages/webpack/executors/webpack.json b/docs/generated/packages/webpack/executors/webpack.json index 9f5587e366..5f56c5a8d5 100644 --- a/docs/generated/packages/webpack/executors/webpack.json +++ b/docs/generated/packages/webpack/executors/webpack.json @@ -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." diff --git a/packages/webpack/src/executors/dev-server/dev-server.impl.ts b/packages/webpack/src/executors/dev-server/dev-server.impl.ts index 0dea24c63e..1256c304b9 100644 --- a/packages/webpack/src/executors/dev-server/dev-server.impl.ts +++ b/packages/webpack/src/executors/dev-server/dev-server.impl.ts @@ -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 }, { diff --git a/packages/webpack/src/executors/webpack/schema.d.ts b/packages/webpack/src/executors/webpack/schema.d.ts index 79a8257aac..1bed74dd8a 100644 --- a/packages/webpack/src/executors/webpack/schema.d.ts +++ b/packages/webpack/src/executors/webpack/schema.d.ts @@ -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; diff --git a/packages/webpack/src/executors/webpack/schema.json b/packages/webpack/src/executors/webpack/schema.json index 885df98c24..9182d4e5b0 100644 --- a/packages/webpack/src/executors/webpack/schema.json +++ b/packages/webpack/src/executors/webpack/schema.json @@ -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." diff --git a/packages/webpack/src/executors/webpack/webpack.impl.ts b/packages/webpack/src/executors/webpack/webpack.impl.ts index 5b51215417..3d060bc830 100644 --- a/packages/webpack/src/executors/webpack/webpack.impl.ts +++ b/packages/webpack/src/executors/webpack/webpack.impl.ts @@ -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,