Skip to content

Commit 3edcf83

Browse files
committed
fix(rspack): fix issue where optimization options are removed from rspack config (nrwl#31268)
1 parent c8a6ffb commit 3edcf83

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

packages/rspack/src/plugins/utils/apply-base-config.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -147,42 +147,44 @@ function applyNxIndependentConfig(
147147
...(config.ignoreWarnings ?? []),
148148
];
149149

150-
config.optimization = !isProd
151-
? undefined
152-
: {
153-
...(config.optimization ?? {}),
154-
sideEffects: true,
155-
minimize:
156-
typeof options.optimization === 'object'
157-
? !!options.optimization.scripts
158-
: !!options.optimization,
159-
minimizer: [
160-
new SwcJsMinimizerRspackPlugin({
161-
extractComments: false,
162-
minimizerOptions: {
163-
// this needs to be false to allow toplevel variables to be used in the global scope
164-
// important especially for module-federation which operates as such
165-
module: false,
166-
mangle: {
167-
keep_classnames: true,
150+
config.optimization = {
151+
...(config.optimization ?? {}),
152+
...(isProd
153+
? {
154+
sideEffects: true,
155+
minimize:
156+
typeof options.optimization === 'object'
157+
? !!options.optimization.scripts
158+
: !!options.optimization,
159+
minimizer: [
160+
new SwcJsMinimizerRspackPlugin({
161+
extractComments: false,
162+
minimizerOptions: {
163+
// this needs to be false to allow toplevel variables to be used in the global scope
164+
// important especially for module-federation which operates as such
165+
module: false,
166+
mangle: {
167+
keep_classnames: true,
168+
},
169+
format: {
170+
ecma: getTerserEcmaVersion(
171+
path.join(options.root, options.projectRoot)
172+
),
173+
ascii_only: true,
174+
comments: false,
175+
webkit: true,
176+
safari10: true,
177+
},
168178
},
169-
format: {
170-
ecma: getTerserEcmaVersion(
171-
path.join(options.root, options.projectRoot)
172-
),
173-
ascii_only: true,
174-
comments: false,
175-
webkit: true,
176-
safari10: true,
177-
},
178-
},
179-
}),
180-
],
181-
concatenateModules: true,
182-
runtimeChunk: isDevServer
183-
? config.optimization?.runtimeChunk ?? undefined
184-
: false,
185-
};
179+
}),
180+
],
181+
concatenateModules: true,
182+
runtimeChunk: isDevServer
183+
? config.optimization?.runtimeChunk ?? undefined
184+
: false,
185+
}
186+
: {}),
187+
};
186188

187189
config.stats = {
188190
hash: true,

0 commit comments

Comments
 (0)