Skip to content

Commit c343589

Browse files
authored
fix: only inject ipv4 str in dev mode (#3813)
1 parent 43c1729 commit c343589

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

.changeset/beige-apricots-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
fix(dts-plugin): only inject ipv4 str in dev mode

.changeset/rare-rockets-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/modern-js': patch
3+
---
4+
5+
fix(modern-js-plugin): only inject ipv4 str in dev mode

packages/dts-plugin/src/plugins/DevPlugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ export class DevPlugin implements WebpackPluginInstance {
117117
const {
118118
_options: { name, dev, dts },
119119
} = this;
120-
new compiler.webpack.DefinePlugin({
121-
FEDERATION_IPV4: JSON.stringify(getIPV4()),
122-
}).apply(compiler);
120+
123121
const normalizedDev =
124122
normalizeOptions<moduleFederationPlugin.PluginDevOptions>(
125123
true,
@@ -135,6 +133,10 @@ export class DevPlugin implements WebpackPluginInstance {
135133
return;
136134
}
137135

136+
new compiler.webpack.DefinePlugin({
137+
FEDERATION_IPV4: JSON.stringify(getIPV4()),
138+
}).apply(compiler);
139+
138140
if (
139141
normalizedDev.disableHotTypesReload &&
140142
normalizedDev.disableLiveReload &&

packages/modernjs/src/cli/configPlugin.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export const patchMFConfig = (
144144
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions,
145145
isServer: boolean,
146146
remoteIpStrategy?: 'ipv4' | 'inherit',
147+
enableSSR?: boolean,
147148
) => {
148149
replaceRemoteUrl(mfConfig, remoteIpStrategy);
149150
if (mfConfig.remoteType === undefined) {
@@ -161,7 +162,7 @@ export const patchMFConfig = (
161162
runtimePlugins,
162163
);
163164

164-
if (isDev) {
165+
if (enableSSR && isDev) {
165166
injectRuntimePlugins(
166167
require.resolve('@module-federation/modern-js/resolve-entry-ipv4'),
167168
runtimePlugins,
@@ -393,6 +394,7 @@ export const moduleFederationConfigPlugin = (
393394
targetMFConfig,
394395
!isWeb,
395396
userConfig.remoteIpStrategy || 'ipv4',
397+
enableSSR,
396398
);
397399

398400
patchBundlerConfig({
@@ -451,6 +453,12 @@ export const moduleFederationConfigPlugin = (
451453
'Access-Control-Allow-Headers': '*',
452454
}
453455
: undefined;
456+
const defineConfig = {
457+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy),
458+
};
459+
if (enableSSR && isDev) {
460+
defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
461+
}
454462
return {
455463
tools: {
456464
devServer: {
@@ -464,10 +472,7 @@ export const moduleFederationConfigPlugin = (
464472
'@module-federation/modern-js/runtime',
465473
),
466474
},
467-
define: {
468-
FEDERATION_IPV4: JSON.stringify(ipv4),
469-
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy),
470-
},
475+
define: defineConfig,
471476
enableAsyncEntry:
472477
bundlerType === 'rspack'
473478
? (modernjsConfig.source?.enableAsyncEntry ?? true)

0 commit comments

Comments
 (0)