Skip to content

Commit a12fff2

Browse files
Coly010FrozenPandaz
authored andcommitted
fix(module-federation): use runtimeChunk false when not in dev mode (#31256)
## Current Behavior In #30637 `runtimeChunk: false` was removed to allow HMR for styles. ## Expected Behavior We need to set runtimeChunk to false or multiple when working with MF. #31114 (comment) ## Related Issue(s) Fixes #31114 (cherry picked from commit 1ab77c8)
1 parent a52a435 commit a12fff2

File tree

7 files changed

+28
-0
lines changed

7 files changed

+28
-0
lines changed

packages/module-federation/src/with-module-federation/angular/with-module-federation-ssr.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export async function withModuleFederationForSSR(
1111
if (global.NX_GRAPH_CREATION) {
1212
return (config) => config;
1313
}
14+
const isDevServer = process.env['WEBPACK_SERVE'];
1415

1516
const { sharedLibraries, sharedDependencies, mappedRemotes } =
1617
await getModuleFederationConfig(options, {
@@ -27,6 +28,9 @@ export async function withModuleFederationForSSR(
2728
},
2829
optimization: {
2930
...(config.optimization ?? {}),
31+
runtimeChunk: isDevServer
32+
? config.optimization?.runtimeChunk ?? undefined
33+
: false,
3034
},
3135
resolve: {
3236
...(config.resolve ?? {}),

packages/module-federation/src/with-module-federation/angular/with-module-federation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function withModuleFederation(
1212
if (global.NX_GRAPH_CREATION) {
1313
return (config) => config;
1414
}
15+
const isDevServer = process.env['WEBPACK_SERVE'];
1516

1617
const { sharedLibraries, sharedDependencies, mappedRemotes } =
1718
await getModuleFederationConfig(options);
@@ -26,6 +27,9 @@ export async function withModuleFederation(
2627
},
2728
optimization: {
2829
...(config.optimization ?? {}),
30+
runtimeChunk: isDevServer
31+
? config.optimization?.runtimeChunk ?? undefined
32+
: false,
2933
},
3034
resolve: {
3135
...(config.resolve ?? {}),

packages/module-federation/src/with-module-federation/rspack/with-module-federation-ssr.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function withModuleFederationForSSR(
1212
if (global.NX_GRAPH_CREATION) {
1313
return (config) => config;
1414
}
15+
const isDevServer = process.env['WEBPACK_SERVE'];
1516

1617
const { sharedLibraries, sharedDependencies, mappedRemotes } =
1718
getModuleFederationConfig(options, {
@@ -26,6 +27,9 @@ export async function withModuleFederationForSSR(
2627
};
2728
config.optimization = {
2829
...(config.optimization ?? {}),
30+
runtimeChunk: isDevServer
31+
? config.optimization?.runtimeChunk ?? undefined
32+
: false,
2933
};
3034

3135
config.plugins.push(

packages/module-federation/src/with-module-federation/rspack/with-module-federation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function withModuleFederation(
2424
return config;
2525
};
2626
}
27+
const isDevServer = process.env['WEBPACK_SERVE'];
2728

2829
const { sharedDependencies, sharedLibraries, mappedRemotes } =
2930
getModuleFederationConfig(options);
@@ -42,6 +43,9 @@ export async function withModuleFederation(
4243

4344
config.optimization = {
4445
...(config.optimization ?? {}),
46+
runtimeChunk: isDevServer
47+
? config.optimization?.runtimeChunk ?? undefined
48+
: false,
4549
};
4650

4751
if (

packages/module-federation/src/with-module-federation/webpack/with-module-federation-ssr.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function withModuleFederationForSSR(
1212
if (global.NX_GRAPH_CREATION) {
1313
return (config) => config;
1414
}
15+
const isDevServer = process.env['WEBPACK_SERVE'];
1516

1617
const { sharedLibraries, sharedDependencies, mappedRemotes } =
1718
await getModuleFederationConfig(options, {
@@ -23,6 +24,9 @@ export async function withModuleFederationForSSR(
2324
config.output.uniqueName = options.name;
2425
config.optimization = {
2526
...(config.optimization ?? {}),
27+
runtimeChunk: isDevServer
28+
? config.optimization?.runtimeChunk ?? undefined
29+
: false,
2630
};
2731

2832
config.plugins.push(

packages/module-federation/src/with-module-federation/webpack/with-module-federation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export async function withModuleFederation(
1616
if (global.NX_GRAPH_CREATION) {
1717
return (config) => config;
1818
}
19+
const isDevServer = process.env['WEBPACK_SERVE'];
1920

2021
const { sharedDependencies, sharedLibraries, mappedRemotes } =
2122
await getModuleFederationConfig(options);
@@ -27,6 +28,9 @@ export async function withModuleFederation(
2728
config.output.scriptType = 'text/javascript';
2829
config.optimization = {
2930
...(config.optimization ?? {}),
31+
runtimeChunk: isDevServer
32+
? config.optimization?.runtimeChunk ?? undefined
33+
: false,
3034
};
3135

3236
if (

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function applyNxIndependentConfig(
6464
): void {
6565
const isProd =
6666
process.env.NODE_ENV === 'production' || options.mode === 'production';
67+
const isDevServer = process.env['WEBPACK_SERVE'];
6768
const hashFormat = getOutputHashFormat(options.outputHashing as string);
6869
config.context = path.join(options.root, options.projectRoot);
6970
config.target ??= options.target as 'async-node' | 'node' | 'web';
@@ -178,6 +179,9 @@ function applyNxIndependentConfig(
178179
}),
179180
],
180181
concatenateModules: true,
182+
runtimeChunk: isDevServer
183+
? config.optimization?.runtimeChunk ?? undefined
184+
: false,
181185
};
182186

183187
config.stats = {

0 commit comments

Comments
 (0)