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.
This commit is contained in:
Mike Peters 2024-05-08 07:12:08 -07:00 committed by GitHub
parent 4cc3dc6960
commit 1449d1acc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -96,30 +96,25 @@ function applyNxIndependentConfig(
...config.output, ...config.output,
libraryTarget: libraryTarget:
(config as Configuration).output?.libraryTarget ?? (config as Configuration).output?.libraryTarget ??
options.target === 'node' (options.target === 'node' ? 'commonjs' : undefined),
? 'commonjs'
: undefined,
path: path:
config.output?.path ?? config.output?.path ??
(options.outputPath (options.outputPath
? path.join(options.root, options.outputPath) ? path.join(options.root, options.outputPath)
: undefined), : undefined),
filename: filename:
config.output?.filename ?? options.outputHashing config.output?.filename ??
? `[name]${hashFormat.script}.js` (options.outputHashing ? `[name]${hashFormat.script}.js` : '[name].js'),
: '[name].js',
chunkFilename: chunkFilename:
config.output?.chunkFilename ?? options.outputHashing config.output?.chunkFilename ??
? `[name]${hashFormat.chunk}.js` (options.outputHashing ? `[name]${hashFormat.chunk}.js` : '[name].js'),
: '[name].js',
hashFunction: config.output?.hashFunction ?? 'xxhash64', hashFunction: config.output?.hashFunction ?? 'xxhash64',
// Disabled for performance // Disabled for performance
pathinfo: config.output?.pathinfo ?? false, pathinfo: config.output?.pathinfo ?? false,
// Use CJS for Node since it has the widest support. // Use CJS for Node since it has the widest support.
scriptType: scriptType:
config.output?.scriptType ?? options.target === 'node' config.output?.scriptType ??
? undefined (options.target === 'node' ? undefined : 'module'),
: 'module',
}; };
config.watch = options.watch; config.watch = options.watch;