Skip to content

Commit f573ad0

Browse files
WIP: chore: split runtime as core and entry (#3154)
Co-authored-by: ScriptedAlchemy <[email protected]> Co-authored-by: Zack Jackson <[email protected]>
1 parent de80bb5 commit f573ad0

File tree

146 files changed

+5036
-2545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+5036
-2545
lines changed

.changeset/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"@module-federation/retry-plugin",
2424
"@module-federation/data-prefetch",
2525
"@module-federation/rsbuild-plugin",
26-
"@module-federation/error-codes"
26+
"@module-federation/error-codes",
27+
"@module-federation/inject-external-runtime-core-plugin"
2728
]
2829
],
2930
"ignorePatterns": ["^alpha|^beta"],
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@module-federation/inject-external-runtime-core-plugin': patch
3+
'@module-federation/runtime-core': patch
4+
'@module-federation/enhanced': patch
5+
'@module-federation/runtime': patch
6+
---
7+
8+
feat: add externalRuntime and provideExternalRuntime fields to help optimize assets size

apps/manifest-demo/3009-webpack-provider/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ module.exports = composePlugins(
4646
requiredVersion: '^18.3.1',
4747
},
4848
},
49+
experiments: {
50+
externalRuntime: true,
51+
},
4952
}),
5053
);
5154

apps/manifest-demo/3010-rspack-provider/rspack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ module.exports = composePlugins(
101101
},
102102
},
103103
dataPrefetch: true,
104+
experiments: {
105+
externalRuntime: true,
106+
},
104107
}),
105108
);
106109
(config.devServer = {

apps/manifest-demo/3011-rspack-manifest-provider/rspack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ module.exports = composePlugins(
8484
requiredVersion: '^18.3.1',
8585
},
8686
},
87+
experiments: {
88+
externalRuntime: true,
89+
},
8790
}),
8891
);
8992
(config.devServer = {

apps/manifest-demo/3012-rspack-js-entry-provider/rspack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ module.exports = composePlugins(
8585
},
8686
},
8787
manifest: false,
88+
experiments: {
89+
externalRuntime: true,
90+
},
8891
}),
8992
);
9093
(config.devServer = {

apps/manifest-demo/webpack-host/src/bootstrap.tsx

Lines changed: 0 additions & 50 deletions
This file was deleted.

apps/manifest-demo/webpack-host/webpack.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ module.exports = composePlugins(withNx(), withReact(), (config, context) => {
2323
'modern-js-provider': 'app1@http://127.0.0.1:4001/mf-manifest.json',
2424
},
2525
filename: 'remoteEntry.js',
26-
exposes: {
27-
'./Button': './src/Button.tsx',
28-
},
2926
shared: {
3027
lodash: {},
3128
antd: {},
@@ -47,8 +44,12 @@ module.exports = composePlugins(withNx(), withReact(), (config, context) => {
4744
},
4845
},
4946
dataPrefetch: true,
50-
experiments: { federationRuntime: 'hoisted' },
47+
// experiments: { federationRuntime: 'hoisted' },
5148
runtimePlugins: [path.join(__dirname, './runtimePlugin.ts')],
49+
experiments: {
50+
provideExternalRuntime: true,
51+
federationRuntime: 'hoisted',
52+
},
5253
}),
5354
);
5455

apps/website-new/docs/en/configure/experiments.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,22 @@ There should be no "eager consumption" errors possible, as the initialization of
6363
Instead of federation runtime initilizing in the entrypoint code, it is initialized in a RuntimeModule, within the webpack runtime.
6464
This allows module federation to be avaliable ahead of time, thus enabling "Async Startup" capabilities etc.
6565

66+
## externalRuntime
67+
68+
- Type: `boolean`
69+
- Required: No
70+
- Default: `false`
71+
72+
After setting `true`, the external MF runtime will be used and the runtime provided by the consumer will be used. (Please make sure your consumer has `provideExternalRuntime: true` set, otherwise it will not run properly!)
73+
74+
## provideExternalRuntime
75+
76+
- Type: `boolean`
77+
- Required: No
78+
- Default: `false`
79+
80+
::: warning note
81+
Make sure to only configure it on the topmost consumer! If multiple consumers inject runtime at the same time, the ones executed later will not overwrite the existing runtime.
82+
:::
83+
84+
Setting `true` will inject the MF runtime at the consumer.

apps/website-new/docs/zh/configure/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@
6363
"type": "file",
6464
"name": "shareStrategy",
6565
"label": "shareStrategy"
66+
},
67+
{
68+
"type": "file",
69+
"name": "experiments",
70+
"label": "experiments"
6671
}
6772
]

0 commit comments

Comments
 (0)