From 1449d1acc1d32f93670e40ce278db448e85f57e5 Mon Sep 17 00:00:00 2001 From: Mike Peters Date: Wed, 8 May 2024 07:12:08 -0700 Subject: [PATCH] fix(webpack): don't overwrite output config (#22116) ## Current Behavior Some webpack output options, like `filename` are overwritten when using the `NxWebpackPlugin`, e.g. ```ts module.exports = { output: { path: join(__dirname, '../../dist/apps/my-app'), // this has no affect: filename: ({ runtime }) => migrationEntryPoints.some(({ entryName }) => entryName === runtime) ? 'migrations/[name].js' : '[name].js', }, plugins: [ new NxWebpackPlugin({ ... }), ] }; ``` ## Expected Behavior The `NxWebpackPlugin` should preserve base config where it makes sense. I think this is the intended behaviour, but required some extra parentheses to behave correctly. --- .../lib/apply-base-config.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts b/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts index 88cbebc5a4..802114b9c7 100644 --- a/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts +++ b/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts @@ -96,30 +96,25 @@ function applyNxIndependentConfig( ...config.output, libraryTarget: (config as Configuration).output?.libraryTarget ?? - options.target === 'node' - ? 'commonjs' - : undefined, + (options.target === 'node' ? 'commonjs' : undefined), path: config.output?.path ?? (options.outputPath ? path.join(options.root, options.outputPath) : undefined), filename: - config.output?.filename ?? options.outputHashing - ? `[name]${hashFormat.script}.js` - : '[name].js', + config.output?.filename ?? + (options.outputHashing ? `[name]${hashFormat.script}.js` : '[name].js'), chunkFilename: - config.output?.chunkFilename ?? options.outputHashing - ? `[name]${hashFormat.chunk}.js` - : '[name].js', + config.output?.chunkFilename ?? + (options.outputHashing ? `[name]${hashFormat.chunk}.js` : '[name].js'), hashFunction: config.output?.hashFunction ?? 'xxhash64', // Disabled for performance pathinfo: config.output?.pathinfo ?? false, // Use CJS for Node since it has the widest support. scriptType: - config.output?.scriptType ?? options.target === 'node' - ? undefined - : 'module', + config.output?.scriptType ?? + (options.target === 'node' ? undefined : 'module'), }; config.watch = options.watch;