Skip to content

Commit 97875a6

Browse files
committed
chore: use rspack ssr
1 parent 42ced1f commit 97875a6

File tree

13 files changed

+1936
-1077
lines changed

13 files changed

+1936
-1077
lines changed

modernjs-ssr/dynamic-provider/modern.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { moduleFederationPlugin } from '@module-federation/modern-js';
33

44
// https://modernjs.dev/en/configure/app/usage
55
export default defineConfig({
6+
dev:{
7+
// FIXME: it should be removed , related issue: https://github.com/web-infra-dev/modern.js/issues/5999
8+
host: '0.0.0.0',
9+
},
610
runtime: {
711
router: true,
812
},
@@ -12,5 +16,8 @@ export default defineConfig({
1216
},
1317
port: 3008,
1418
},
15-
plugins: [appTools(), moduleFederationPlugin()],
19+
plugins: [
20+
appTools({bundler:'experimental-rspack'}),
21+
moduleFederationPlugin()
22+
],
1623
});

modernjs-ssr/dynamic-provider/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@
2727
"dist/"
2828
],
2929
"dependencies": {
30-
"@modern-js/runtime": "2.54.2",
30+
"@modern-js/runtime": "2.56.2",
3131
"react": "~18.3.0",
3232
"react-dom": "~18.3.0",
33-
"@module-federation/modern-js":"0.3.1"
33+
"@module-federation/modern-js":"0.0.0-next-20240725061440"
3434
},
3535
"devDependencies": {
36-
"@modern-js/app-tools": "2.54.2",
37-
"@modern-js/eslint-config": "2.54.2",
38-
"@modern-js/tsconfig": "2.54.2",
39-
"@modern-js-app/eslint-config": "2.54.2",
40-
"@modern-js/builder-rspack-provider": "2.46.1",
36+
"@modern-js/app-tools": "2.56.2",
37+
"@modern-js/eslint-config": "2.56.2",
38+
"@modern-js/tsconfig": "2.56.2",
39+
"@modern-js-app/eslint-config": "2.56.2",
4140
"lint-staged": "15.2.7",
4241
"prettier": "3.3.2",
4342
"husky": "9.0.11",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './compiled-types/Image';
2-
export { default } from './compiled-types/Image';
1+
export * from './compiled-types/src/components/Image';
2+
export { default } from './compiled-types/src/components/Image';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './compiled-types/Image';
2-
export { default } from './compiled-types/Image';
1+
export * from './compiled-types/src/components/Image';
2+
export { default } from './compiled-types/src/components/Image';

modernjs-ssr/host/modern.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { moduleFederationPlugin } from '@module-federation/modern-js';
33

44
// https://modernjs.dev/en/configure/app/usage
55
export default defineConfig({
6+
dev:{
7+
// FIXME: it should be removed , related issue: https://github.com/web-infra-dev/modern.js/issues/5999
8+
host: '0.0.0.0',
9+
},
610
runtime: {
711
router: true,
812
},
@@ -12,5 +16,9 @@ export default defineConfig({
1216
},
1317
port: 3007,
1418
},
15-
plugins: [appTools(), moduleFederationPlugin()],
19+
plugins: [
20+
// not support data loader in rspack mode yet
21+
appTools(),
22+
moduleFederationPlugin()
23+
],
1624
});

modernjs-ssr/host/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@
2727
"dist/"
2828
],
2929
"dependencies": {
30-
"@modern-js/runtime": "2.54.2",
30+
"@modern-js/runtime": "2.56.2",
3131
"react": "^18.2.0",
3232
"react-dom": "^18.2.0",
33-
"@module-federation/modern-js":"0.3.1"
33+
"@module-federation/modern-js":"0.0.0-next-20240725061440"
3434
},
3535
"devDependencies": {
36-
"@modern-js/app-tools": "2.54.2",
37-
"@modern-js/eslint-config": "2.54.2",
38-
"@modern-js/tsconfig": "2.54.2",
39-
"@modern-js-app/eslint-config": "2.54.2",
40-
"@modern-js/builder-rspack-provider": "2.46.1",
36+
"@modern-js/app-tools": "2.56.2",
37+
"@modern-js/eslint-config": "2.56.2",
38+
"@modern-js/tsconfig": "2.56.2",
39+
"@modern-js-app/eslint-config": "2.56.2",
4140
"lint-staged": "15.2.7",
4241
"prettier": "3.3.2",
4342
"husky": "9.0.11",

modernjs-ssr/host/rspackplugin.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
class ModifyServerLoaderPlugin {
2+
apply(compiler){
3+
compiler.hooks.thisCompilation.tap(
4+
'ModifyServerLoaderPlugin',
5+
(compilation) => {
6+
this._handleRenderStartup(compiler, compilation);
7+
},
8+
);
9+
}
10+
11+
_handleRenderStartup(compiler, compilation) {
12+
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
13+
compilation,
14+
).renderStartup.tap(
15+
'ModifyServerLoaderPlugin',
16+
(
17+
source,
18+
_renderContext,
19+
upperContext,
20+
) => {
21+
return new compiler.webpack.sources.ConcatSource(`
22+
console.log(11);
23+
${source.source().toString()}
24+
`);
25+
26+
// const isSingleRuntime = compiler.options?.optimization?.runtimeChunk;
27+
// if (upperContext?.chunk.id && isSingleRuntime) {
28+
// if (upperContext?.chunk.hasRuntime()) {
29+
// return source;
30+
// }
31+
// }
32+
33+
// if (
34+
// this._options.excludeChunk &&
35+
// this._options.excludeChunk(upperContext.chunk)
36+
// ) {
37+
// return source;
38+
// }
39+
40+
// const runtime = this._getChunkRuntime(upperContext);
41+
42+
// let remotes = '';
43+
// let shared = '';
44+
45+
// for (const runtimeItem of runtime) {
46+
// if (!runtimeItem) {
47+
// continue;
48+
// }
49+
50+
// const requirements =
51+
// compilation.chunkGraph.getTreeRuntimeRequirements(runtimeItem);
52+
53+
// const entryOptions = upperContext.chunk.getEntryOptions();
54+
// const chunkInitialsSet = new Set(
55+
// compilation.chunkGraph.getChunkEntryDependentChunksIterable(
56+
// upperContext.chunk,
57+
// ),
58+
// );
59+
60+
// chunkInitialsSet.add(upperContext.chunk);
61+
// const dependOn = entryOptions?.dependOn || [];
62+
// this.getChunkByName(compilation, dependOn, chunkInitialsSet);
63+
64+
// const initialChunks = [];
65+
66+
// let hasRemoteModules = false;
67+
// let consumeShares = false;
68+
69+
// for (const chunk of chunkInitialsSet) {
70+
// initialChunks.push(chunk.id);
71+
// if (!hasRemoteModules) {
72+
// hasRemoteModules = Boolean(
73+
// compilation.chunkGraph.getChunkModulesIterableBySourceType(
74+
// chunk,
75+
// 'remote',
76+
// ),
77+
// );
78+
// }
79+
// if (!consumeShares) {
80+
// consumeShares = Boolean(
81+
// compilation.chunkGraph.getChunkModulesIterableBySourceType(
82+
// chunk,
83+
// 'consume-shared',
84+
// ),
85+
// );
86+
// }
87+
// if (hasRemoteModules && consumeShares) {
88+
// break;
89+
// }
90+
// }
91+
92+
// remotes = this._getRemotes(
93+
// compiler.webpack.RuntimeGlobals,
94+
// requirements,
95+
// hasRemoteModules,
96+
// initialChunks,
97+
// remotes,
98+
// );
99+
100+
// shared = this._getShared(
101+
// compiler.webpack.RuntimeGlobals,
102+
// requirements,
103+
// consumeShares,
104+
// initialChunks,
105+
// shared,
106+
// );
107+
// }
108+
109+
// if (!remotes && !shared) {
110+
// return source;
111+
// }
112+
113+
// const initialEntryModules = this._getInitialEntryModules(
114+
// compilation,
115+
// upperContext,
116+
// );
117+
// const templateString = this._getTemplateString(
118+
// compiler,
119+
// initialEntryModules,
120+
// shared,
121+
// remotes,
122+
// source,
123+
// );
124+
125+
return new compiler.webpack.sources.ConcatSource(templateString);
126+
},
127+
);
128+
}
129+
}
130+
module.exports = ModifyServerLoaderPlugin

modernjs-ssr/host/src/routes/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRemoteSSRComponent, loadRemote, registerRemotes } from '@modern-js/runtime/mf';
22
import type { DataLoaderRes } from './page.data'
3-
import { useLoaderData } from '@modern-js/runtime/router';
3+
import { useRouteLoaderData } from '@modern-js/runtime/router';
44

55
import './index.css';
66

@@ -17,7 +17,7 @@ const RemoteSSRComponent = createRemoteSSRComponent({
1717
});
1818

1919
const Index = () => {
20-
const dataLoader = useLoaderData() as DataLoaderRes;
20+
const dataLoader = useRouteLoaderData('page') as DataLoaderRes;
2121
registerRemotes(dataLoader.providerList);
2222

2323
const DynamicRemoteSSRComponents = dataLoader.providerList.map(item => {

0 commit comments

Comments
 (0)