@module-federation/modern-js 0.0.0-next-20240812114132 → 0.0.0-next-20240814073142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/ast/constant.js +46 -0
- package/dist/cjs/cli/ast/generateRoutes.js +140 -0
- package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
- package/dist/cjs/cli/ast/index.js +31 -0
- package/dist/cjs/cli/configPlugin.js +1 -0
- package/dist/cjs/cli/constant.js +3 -0
- package/dist/cjs/cli/dataLoaderPlugin.js +205 -0
- package/dist/cjs/cli/index.js +6 -1
- package/dist/cjs/cli/server/dataLoaderPlugin.js +87 -0
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/constant.js +34 -0
- package/dist/cjs/runtime/dataLoader.js +87 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/utils.js +43 -0
- package/dist/cjs/runtime/withMFRouteId.js +31 -0
- package/dist/cjs/ssr-runtime/plugin.js +5 -7
- package/dist/esm/cli/ast/constant.js +16 -0
- package/dist/esm/cli/ast/generateRoutes.js +107 -0
- package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
- package/dist/esm/cli/ast/index.js +6 -0
- package/dist/esm/cli/configPlugin.js +1 -0
- package/dist/esm/cli/constant.js +2 -0
- package/dist/esm/cli/dataLoaderPlugin.js +191 -0
- package/dist/esm/cli/index.js +6 -1
- package/dist/esm/cli/server/dataLoaderPlugin.js +132 -0
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/constant.js +8 -0
- package/dist/esm/runtime/dataLoader.js +125 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/utils.js +16 -0
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +5 -10
- package/dist/esm-node/cli/ast/constant.js +16 -0
- package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
- package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
- package/dist/esm-node/cli/ast/index.js +6 -0
- package/dist/esm-node/cli/configPlugin.js +1 -0
- package/dist/esm-node/cli/constant.js +2 -0
- package/dist/esm-node/cli/dataLoaderPlugin.js +169 -0
- package/dist/esm-node/cli/index.js +6 -1
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +67 -0
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/constant.js +8 -0
- package/dist/esm-node/runtime/dataLoader.js +63 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/utils.js +19 -0
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +5 -7
- package/dist/types/cli/ast/constant.d.ts +7 -0
- package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
- package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
- package/dist/types/cli/ast/index.d.ts +2 -0
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/dataLoaderPlugin.d.ts +6 -0
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +4 -0
- package/dist/types/interfaces/route.d.ts +13 -0
- package/dist/types/runtime/constant.d.ts +3 -0
- package/dist/types/runtime/dataLoader.d.ts +7 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +1 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/types/index.d.ts +15 -0
- package/package.json +36 -10
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
import { transformName2Prefix } from "../runtime/utils";
|
|
4
|
+
import { PLUGIN_IDENTIFIER } from "../constant";
|
|
5
|
+
import { MF_FULL_ROUTES, MF_SLIM_ROUTES, MF_ROUTES_META } from "../runtime/constant";
|
|
6
|
+
import { generateRoutes, generateSlimRoutes } from "./ast";
|
|
7
|
+
import { MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME } from "./constant";
|
|
8
|
+
function generateExtraExposeFiles(options) {
|
|
9
|
+
const { routesFilePath, mfConfig, isServer, baseName } = options;
|
|
10
|
+
const outputDir = path.resolve(process.cwd(), "node_modules/.federation");
|
|
11
|
+
fs.ensureDirSync(outputDir);
|
|
12
|
+
const addSuffix = (fileName) => {
|
|
13
|
+
if (!isServer) {
|
|
14
|
+
return `${fileName}.jsx`;
|
|
15
|
+
}
|
|
16
|
+
return `${fileName}.server.jsx`;
|
|
17
|
+
};
|
|
18
|
+
const routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
|
|
19
|
+
const outputSlimRoutesPath = path.resolve(outputDir, addSuffix(MF_SLIM_ROUTES));
|
|
20
|
+
const outputFullRoutesPath = path.resolve(outputDir, addSuffix(MF_FULL_ROUTES));
|
|
21
|
+
const outputRoutesMetaPath = path.resolve(outputDir, `${MF_ROUTES_META}.js`);
|
|
22
|
+
generateSlimRoutes({
|
|
23
|
+
sourceCode: routesFileContent,
|
|
24
|
+
filePath: outputSlimRoutesPath,
|
|
25
|
+
prefix: transformName2Prefix(mfConfig.name),
|
|
26
|
+
baseName
|
|
27
|
+
});
|
|
28
|
+
generateRoutes({
|
|
29
|
+
sourceCode: routesFileContent,
|
|
30
|
+
filePath: outputFullRoutesPath,
|
|
31
|
+
prefix: transformName2Prefix(mfConfig.name),
|
|
32
|
+
baseName
|
|
33
|
+
});
|
|
34
|
+
fs.writeFileSync(outputRoutesMetaPath, `export const baseName = '${baseName}';`);
|
|
35
|
+
return {
|
|
36
|
+
outputSlimRoutesPath,
|
|
37
|
+
outputFullRoutesPath,
|
|
38
|
+
outputRoutesMetaPath
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function addExpose(options) {
|
|
42
|
+
const { mfConfig } = options;
|
|
43
|
+
const { outputSlimRoutesPath, outputFullRoutesPath, outputRoutesMetaPath } = generateExtraExposeFiles(options);
|
|
44
|
+
const fullRoutesKey = `./${MF_FULL_ROUTES}`;
|
|
45
|
+
const slimRoutesKey = `./${MF_SLIM_ROUTES}`;
|
|
46
|
+
const routeMetaKey = `./${MF_ROUTES_META}`;
|
|
47
|
+
if (!mfConfig.exposes) {
|
|
48
|
+
mfConfig.exposes = {
|
|
49
|
+
[fullRoutesKey]: outputFullRoutesPath,
|
|
50
|
+
[slimRoutesKey]: outputSlimRoutesPath,
|
|
51
|
+
[routeMetaKey]: outputRoutesMetaPath
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
if (!Array.isArray(mfConfig.exposes)) {
|
|
55
|
+
if (!mfConfig.exposes[fullRoutesKey]) {
|
|
56
|
+
mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
|
|
57
|
+
}
|
|
58
|
+
if (!mfConfig.exposes[slimRoutesKey]) {
|
|
59
|
+
mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
|
|
60
|
+
}
|
|
61
|
+
if (!mfConfig.exposes[routeMetaKey]) {
|
|
62
|
+
mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function addShared(options) {
|
|
68
|
+
const { pkgName, mfConfig } = options;
|
|
69
|
+
const alias = `@${pkgName}/runtime/router`;
|
|
70
|
+
if (!mfConfig.shared) {
|
|
71
|
+
mfConfig.shared = {
|
|
72
|
+
[alias]: {
|
|
73
|
+
singleton: true
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
} else {
|
|
77
|
+
if (!Array.isArray(mfConfig.shared)) {
|
|
78
|
+
mfConfig.shared[alias] = {
|
|
79
|
+
singleton: true
|
|
80
|
+
};
|
|
81
|
+
} else {
|
|
82
|
+
mfConfig.shared.push(alias);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function _pathMfConfig(options) {
|
|
87
|
+
addShared(options);
|
|
88
|
+
addExpose(options);
|
|
89
|
+
}
|
|
90
|
+
const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) => ({
|
|
91
|
+
name: "@modern-js/plugin-module-federation-data-loader",
|
|
92
|
+
pre: [
|
|
93
|
+
"@modern-js/plugin-module-federation-config"
|
|
94
|
+
],
|
|
95
|
+
post: [
|
|
96
|
+
"@modern-js/plugin-router",
|
|
97
|
+
"@modern-js/plugin-module-federation"
|
|
98
|
+
],
|
|
99
|
+
setup: async ({ useConfigContext, useAppContext }) => {
|
|
100
|
+
var _modernjsConfig_server, _internalOptions_csrConfig;
|
|
101
|
+
if (!enable) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const { baseName, partialSSRRemotes = [], fetchSSRByRouteIds, patchMFConfig, pkgName = "modern-js", serverPlugin = "@module-federation/modern-js/data-loader-server" } = userConfig;
|
|
105
|
+
if (!baseName) {
|
|
106
|
+
throw new Error(`${PLUGIN_IDENTIFIER} 'baseName' is required if you enable 'dataLoader'!`);
|
|
107
|
+
}
|
|
108
|
+
const modernjsConfig = useConfigContext();
|
|
109
|
+
const appContext = useAppContext();
|
|
110
|
+
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
111
|
+
const name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
|
|
112
|
+
const routesFilePath = path.resolve(appContext.internalDirectory, `./main/${MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME}`);
|
|
113
|
+
return {
|
|
114
|
+
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
115
|
+
plugins.push({
|
|
116
|
+
name: "ssrDataLoader",
|
|
117
|
+
path: "@module-federation/modern-js/data-loader",
|
|
118
|
+
config: {}
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
entrypoint,
|
|
122
|
+
plugins
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
_internalServerPlugins({ plugins }) {
|
|
126
|
+
plugins.push({
|
|
127
|
+
name: serverPlugin,
|
|
128
|
+
options: internalOptions
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
plugins
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
config: async () => {
|
|
135
|
+
console.log("dataloader plugin config");
|
|
136
|
+
const patchMFConfigFn = patchMFConfig || _pathMfConfig;
|
|
137
|
+
return {
|
|
138
|
+
// server: {
|
|
139
|
+
// ssrByRouteIds: ssrByRouteIds,
|
|
140
|
+
// },
|
|
141
|
+
tools: {
|
|
142
|
+
rspack(_config, { isServer }) {
|
|
143
|
+
patchMFConfigFn({
|
|
144
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
145
|
+
baseName,
|
|
146
|
+
pkgName,
|
|
147
|
+
isServer,
|
|
148
|
+
routesFilePath
|
|
149
|
+
});
|
|
150
|
+
console.log("dataloader plugin rspack");
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
source: {
|
|
154
|
+
define: {
|
|
155
|
+
MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
|
|
164
|
+
export {
|
|
165
|
+
dataLoaderPlugin_default as default,
|
|
166
|
+
generateRoutes,
|
|
167
|
+
generateSlimRoutes,
|
|
168
|
+
moduleFederationDataLoaderPlugin
|
|
169
|
+
};
|
|
@@ -2,6 +2,7 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
|
|
|
2
2
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
3
3
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
4
4
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
5
|
+
import { moduleFederationDataLoaderPlugin } from "./dataLoaderPlugin";
|
|
5
6
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
6
7
|
const internalModernPluginOptions = {
|
|
7
8
|
csrConfig: void 0,
|
|
@@ -53,7 +54,11 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
53
54
|
},
|
|
54
55
|
usePlugins: [
|
|
55
56
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
56
|
-
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
57
|
+
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
58
|
+
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
|
|
59
|
+
baseName: "",
|
|
60
|
+
...userConfig.dataLoader
|
|
61
|
+
})
|
|
57
62
|
]
|
|
58
63
|
};
|
|
59
64
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getInstance, init } from "@module-federation/enhanced/runtime";
|
|
2
|
+
import { MF_SLIM_ROUTES } from "../../runtime/constant";
|
|
3
|
+
var dataLoaderPlugin_default = (options) => ({
|
|
4
|
+
name: "MFDataLoaderServerPlugin",
|
|
5
|
+
pre: [
|
|
6
|
+
"@modern-js/plugin-inject-resource"
|
|
7
|
+
],
|
|
8
|
+
setup(api) {
|
|
9
|
+
const mfConfig = options.csrConfig;
|
|
10
|
+
const remotes = mfConfig.remotes;
|
|
11
|
+
if (!remotes || !Object.keys(remotes).length) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
const runtimeRemotes = Object.entries(remotes).map((item) => {
|
|
15
|
+
const [_alias, nameAndEntry] = item;
|
|
16
|
+
const [name, entry] = nameAndEntry.split("@");
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
entry
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
let isHandled = false;
|
|
23
|
+
return {
|
|
24
|
+
prepare() {
|
|
25
|
+
const { middlewares } = api.useAppContext();
|
|
26
|
+
middlewares.push({
|
|
27
|
+
name: "MFDataLoaderServerPlugin",
|
|
28
|
+
handler: async (c, next) => {
|
|
29
|
+
console.log("isHandled : ", isHandled);
|
|
30
|
+
const serverManifest = c.get("serverManifest");
|
|
31
|
+
const { loaderBundles } = serverManifest;
|
|
32
|
+
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
33
|
+
if (isHandled) {
|
|
34
|
+
await next();
|
|
35
|
+
} else {
|
|
36
|
+
const instance = getInstance() || init({
|
|
37
|
+
name: mfConfig.name,
|
|
38
|
+
remotes: runtimeRemotes
|
|
39
|
+
});
|
|
40
|
+
const slimRoutes = await Promise.all(runtimeRemotes.map(async (remote) => {
|
|
41
|
+
const { routes, baseName } = await instance.loadRemote(`${remote.name}/${MF_SLIM_ROUTES}`);
|
|
42
|
+
return {
|
|
43
|
+
routes,
|
|
44
|
+
baseName
|
|
45
|
+
};
|
|
46
|
+
}));
|
|
47
|
+
slimRoutes.forEach((slimRoute) => {
|
|
48
|
+
const { routes, baseName } = slimRoute;
|
|
49
|
+
routes[0].path = `/${baseName}`;
|
|
50
|
+
loaderBundles.main.routes.push(...routes);
|
|
51
|
+
});
|
|
52
|
+
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
53
|
+
isHandled = true;
|
|
54
|
+
await next();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
before: [
|
|
58
|
+
"render"
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
export {
|
|
66
|
+
dataLoaderPlugin_default as default
|
|
67
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getInstance, loadRemote } from "@module-federation/enhanced/runtime";
|
|
3
|
+
import { MF_FULL_ROUTES } from "./constant";
|
|
4
|
+
globalThis.mfRemoteRoutes = globalThis.mfRemoteRoutes || [];
|
|
5
|
+
var _globalThis_mfHasLoadedRemoteRoutes;
|
|
6
|
+
globalThis.mfHasLoadedRemoteRoutes = (_globalThis_mfHasLoadedRemoteRoutes = globalThis.mfHasLoadedRemoteRoutes) !== null && _globalThis_mfHasLoadedRemoteRoutes !== void 0 ? _globalThis_mfHasLoadedRemoteRoutes : false;
|
|
7
|
+
async function loadRoutes() {
|
|
8
|
+
var _getInstance;
|
|
9
|
+
if (globalThis.mfHasLoadedRemoteRoutes) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const remotes = (_getInstance = getInstance()) === null || _getInstance === void 0 ? void 0 : _getInstance.options.remotes;
|
|
13
|
+
if (!remotes) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const remoteModuleIds = remotes.map((remote) => {
|
|
17
|
+
return `${remote.name}/${MF_FULL_ROUTES}`;
|
|
18
|
+
});
|
|
19
|
+
const traverse = (cRoutes, prefix) => {
|
|
20
|
+
cRoutes.forEach((i) => {
|
|
21
|
+
i.id = prefix + i.id;
|
|
22
|
+
const Comp = i.component;
|
|
23
|
+
i.element = /* @__PURE__ */ _jsx(Comp, {});
|
|
24
|
+
if (i.children) {
|
|
25
|
+
traverse(i.children, prefix);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
await Promise.all(remoteModuleIds.map(async (remoteModuleId) => {
|
|
30
|
+
const remoteName = remoteModuleId.split(`/${MF_FULL_ROUTES}`)[0];
|
|
31
|
+
const { routes, baseName } = await loadRemote(remoteModuleId);
|
|
32
|
+
routes[0].path = `/${baseName}`;
|
|
33
|
+
routes[0].isRoot = false;
|
|
34
|
+
globalThis.mfRemoteRoutes.push(...routes);
|
|
35
|
+
}));
|
|
36
|
+
globalThis.mfHasLoadedRemoteRoutes = true;
|
|
37
|
+
return globalThis.mfRemoteRoutes;
|
|
38
|
+
}
|
|
39
|
+
const ssrDataLoaderPlugin = () => {
|
|
40
|
+
return {
|
|
41
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
42
|
+
post: [
|
|
43
|
+
"@modern-js/plugin-router"
|
|
44
|
+
],
|
|
45
|
+
setup: () => {
|
|
46
|
+
return {
|
|
47
|
+
async beforeRender({ context }) {
|
|
48
|
+
console.log("init");
|
|
49
|
+
await loadRoutes();
|
|
50
|
+
},
|
|
51
|
+
modifyRoutes: (routes) => {
|
|
52
|
+
console.log("modifyRoutes");
|
|
53
|
+
routes.push(...globalThis.mfRemoteRoutes);
|
|
54
|
+
console.log("routes: ", routes);
|
|
55
|
+
return routes;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
ssrDataLoaderPlugin
|
|
63
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function transformName2Prefix(name) {
|
|
2
|
+
const NameTransformSymbol = {
|
|
3
|
+
AT: "@",
|
|
4
|
+
HYPHEN: "-",
|
|
5
|
+
SLASH: "/",
|
|
6
|
+
UNDERLINE: "_"
|
|
7
|
+
};
|
|
8
|
+
const NameTransformMap = {
|
|
9
|
+
[NameTransformSymbol.AT]: "SCOPE",
|
|
10
|
+
[NameTransformSymbol.HYPHEN]: "HYPHEN",
|
|
11
|
+
[NameTransformSymbol.SLASH]: "SLASH",
|
|
12
|
+
[NameTransformSymbol.UNDERLINE]: "UNDERLINE"
|
|
13
|
+
};
|
|
14
|
+
const SPLIT_SYMBOL = "@";
|
|
15
|
+
return `${name.replace(new RegExp(`${NameTransformSymbol.AT}`, "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, "g"), NameTransformMap[NameTransformSymbol.SLASH]).replace(new RegExp(`${NameTransformSymbol.UNDERLINE}`, "g"), NameTransformMap[NameTransformSymbol.UNDERLINE])}${SPLIT_SYMBOL}`;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
transformName2Prefix
|
|
19
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
3
3
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
4
|
+
console.log("mfSSRPlugin trigger");
|
|
4
5
|
const mfSSRPlugin = () => ({
|
|
5
6
|
name: "@module-federation/modern-js",
|
|
6
7
|
setup: () => {
|
|
7
8
|
return {
|
|
8
|
-
async
|
|
9
|
+
async beforeRender() {
|
|
10
|
+
console.log(111, "beforeRender");
|
|
9
11
|
if (typeof window !== "undefined") {
|
|
10
|
-
return
|
|
11
|
-
context
|
|
12
|
-
});
|
|
12
|
+
return;
|
|
13
13
|
}
|
|
14
14
|
globalThis.shouldUpdate = false;
|
|
15
15
|
const nodeUtils = await import("@module-federation/node/utils");
|
|
@@ -19,9 +19,7 @@ const mfSSRPlugin = () => ({
|
|
|
19
19
|
await nodeUtils.flushChunks();
|
|
20
20
|
globalThis.shouldUpdate = true;
|
|
21
21
|
}
|
|
22
|
-
return
|
|
23
|
-
context
|
|
24
|
-
});
|
|
22
|
+
return;
|
|
25
23
|
},
|
|
26
24
|
wrapRoot(App) {
|
|
27
25
|
const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const IS_ROOT = "isRoot";
|
|
2
|
+
export declare const ID = "id";
|
|
3
|
+
export declare const COMPONENT = "component";
|
|
4
|
+
export declare const LAZY_COMPONENT = "lazyImport";
|
|
5
|
+
export declare const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
6
|
+
export declare const PRIVATE_COMPONENT = "_component";
|
|
7
|
+
export declare const ELEMENT = "element";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
|
2
|
+
import type { DataLoaderOptions, InternalModernPluginOptions } from '../types';
|
|
3
|
+
import { generateRoutes, generateSlimRoutes } from './ast';
|
|
4
|
+
export declare const moduleFederationDataLoaderPlugin: (enable: boolean, internalOptions: InternalModernPluginOptions, userConfig: DataLoaderOptions) => CliPlugin<AppTools>;
|
|
5
|
+
export default moduleFederationDataLoaderPlugin;
|
|
6
|
+
export { generateRoutes, generateSlimRoutes };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Route = {
|
|
2
|
+
id: string;
|
|
3
|
+
type: string;
|
|
4
|
+
loader?: boolean;
|
|
5
|
+
index?: boolean;
|
|
6
|
+
isRoot?: boolean;
|
|
7
|
+
children?: Route[];
|
|
8
|
+
};
|
|
9
|
+
export type MFModernRouteJson = {
|
|
10
|
+
baseName: string;
|
|
11
|
+
routes: Record<string, Route[]>;
|
|
12
|
+
prefix: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Plugin } from '@modern-js/runtime';
|
|
2
|
+
import { type RouteObject } from '@modern-js/runtime/router';
|
|
3
|
+
declare global {
|
|
4
|
+
var mfRemoteRoutes: RouteObject[];
|
|
5
|
+
var mfHasLoadedRemoteRoutes: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const ssrDataLoaderPlugin: () => Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transformName2Prefix(name: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withMFRouteId(id: string): string;
|
|
@@ -5,6 +5,7 @@ export interface PluginOptions {
|
|
|
5
5
|
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
6
6
|
configPath?: string;
|
|
7
7
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
8
|
+
dataLoader?: false | Pick<DataLoaderOptions, 'baseName' | 'partialSSRRemotes'>;
|
|
8
9
|
}
|
|
9
10
|
export interface InternalModernPluginOptions {
|
|
10
11
|
csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
@@ -16,3 +17,17 @@ export interface InternalModernPluginOptions {
|
|
|
16
17
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
17
18
|
}
|
|
18
19
|
export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
|
|
20
|
+
export type DataLoaderOptions = {
|
|
21
|
+
baseName: string;
|
|
22
|
+
partialSSRRemotes?: string[];
|
|
23
|
+
pkgName?: string;
|
|
24
|
+
serverPlugin?: string;
|
|
25
|
+
fetchSSRByRouteIds?: (partialSSRRemotes: string[], mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Promise<string[] | undefined>;
|
|
26
|
+
patchMFConfig?: (options: {
|
|
27
|
+
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
28
|
+
baseName: string;
|
|
29
|
+
pkgName: string;
|
|
30
|
+
isServer: boolean;
|
|
31
|
+
routesFilePath: string;
|
|
32
|
+
}) => void;
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240814073142",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -23,6 +23,19 @@
|
|
|
23
23
|
"types": "./dist/types/ssr-runtime/index.d.ts",
|
|
24
24
|
"default": "./dist/esm/ssr-runtime/index.js"
|
|
25
25
|
},
|
|
26
|
+
"./data-loader": {
|
|
27
|
+
"types": "./dist/types/runtime/dataLoader.d.ts",
|
|
28
|
+
"default": "./dist/esm/runtime/dataLoader.js"
|
|
29
|
+
},
|
|
30
|
+
"./data-loader-server": {
|
|
31
|
+
"types": "./dist/types/cli/server/dataLoaderPlugin.d.ts",
|
|
32
|
+
"default": "./dist/cjs/cli/server/dataLoaderPlugin.js"
|
|
33
|
+
},
|
|
34
|
+
"./data-loader-plugin": {
|
|
35
|
+
"import": "./dist/esm/cli/dataLoaderPlugin.js",
|
|
36
|
+
"require": "./dist/cjs/cli/dataLoaderPlugin.js",
|
|
37
|
+
"types": "./dist/types/cli/dataLoaderPlugin.d.ts"
|
|
38
|
+
},
|
|
26
39
|
"./config-plugin": {
|
|
27
40
|
"import": "./dist/esm/cli/configPlugin.js",
|
|
28
41
|
"require": "./dist/cjs/cli/configPlugin.js",
|
|
@@ -47,6 +60,12 @@
|
|
|
47
60
|
],
|
|
48
61
|
"ssr-plugin": [
|
|
49
62
|
"./dist/types/cli/ssrPlugin.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"data-loader-plugin": [
|
|
65
|
+
"./dist/types/cli/dataLoaderPlugin.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"data-loader": [
|
|
68
|
+
"./dist/types/runtime/dataLoader.d.ts"
|
|
50
69
|
]
|
|
51
70
|
}
|
|
52
71
|
},
|
|
@@ -61,18 +80,25 @@
|
|
|
61
80
|
"node-fetch": "~3.3.0",
|
|
62
81
|
"react-error-boundary": "4.0.13",
|
|
63
82
|
"hoist-non-react-statics": "3.3.2",
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
83
|
+
"@babel/generator": "7.25.0",
|
|
84
|
+
"@babel/parser": "7.25.3",
|
|
85
|
+
"@babel/traverse": "7.25.3",
|
|
86
|
+
"@babel/types": "7.25.2",
|
|
87
|
+
"@module-federation/sdk": "0.0.0-next-20240814073142",
|
|
88
|
+
"@module-federation/enhanced": "0.0.0-next-20240814073142",
|
|
89
|
+
"@module-federation/node": "0.0.0-next-20240814073142"
|
|
67
90
|
},
|
|
68
91
|
"devDependencies": {
|
|
92
|
+
"@types/babel__traverse": "7.20.6",
|
|
93
|
+
"@types/babel__generator": "7.6.8",
|
|
69
94
|
"@types/hoist-non-react-statics": "3.3.2",
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@modern-js/
|
|
72
|
-
"@modern-js/
|
|
73
|
-
"@modern-js/
|
|
74
|
-
"@modern-js/
|
|
75
|
-
"@
|
|
95
|
+
"@modern-js/server-core": "0.0.0-next-20240814063139",
|
|
96
|
+
"@modern-js/app-tools": "0.0.0-next-20240814063139",
|
|
97
|
+
"@modern-js/core": "0.0.0-next-20240814063139",
|
|
98
|
+
"@modern-js/runtime": "0.0.0-next-20240814063139",
|
|
99
|
+
"@modern-js/module-tools": "0.0.0-next-20240814063139",
|
|
100
|
+
"@modern-js/tsconfig": "0.0.0-next-20240814063139",
|
|
101
|
+
"@module-federation/manifest": "0.0.0-next-20240814073142"
|
|
76
102
|
},
|
|
77
103
|
"peerDependencies": {
|
|
78
104
|
"react": ">=17",
|