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,
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;