@module-federation/modern-js 0.14.2 → 0.15.0
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/LICENSE +21 -0
- package/dist/cjs/cli/configPlugin.js +381 -0
- package/dist/cjs/cli/configPlugin.spec.js +114 -0
- package/dist/cjs/cli/index.js +95 -0
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +82 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +43 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +189 -0
- package/dist/cjs/cli/ssrPlugin.js +236 -0
- package/dist/cjs/cli/utils.js +90 -0
- package/dist/cjs/constant.js +78 -0
- package/dist/cjs/interfaces/bundler.js +16 -0
- package/dist/cjs/interfaces/global.js +16 -0
- package/dist/cjs/logger.js +27 -0
- package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
- package/dist/cjs/runtime/createRemoteComponent.js +327 -0
- package/dist/cjs/runtime/index.js +50 -0
- package/dist/cjs/runtime/wrapNoSSR.js +35 -0
- package/dist/cjs/server/fileCache.js +84 -0
- package/dist/cjs/server/fileCache.spec.js +28 -0
- package/dist/cjs/server/index.js +58 -0
- package/dist/cjs/server/staticMiddleware.js +77 -0
- package/dist/cjs/server/staticMiddleware.spec.js +185 -0
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +43 -0
- package/dist/cjs/ssr-runtime/devPlugin.js +71 -0
- package/dist/cjs/ssr-runtime/downgrade.js +114 -0
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
- package/dist/cjs/types/index.js +16 -0
- package/dist/cjs/utils/dataFetch.js +211 -0
- package/dist/cjs/utils/index.js +54 -0
- package/dist/esm/cli/configPlugin.js +388 -0
- package/dist/esm/cli/configPlugin.spec.js +110 -0
- package/dist/esm/cli/index.js +90 -0
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +74 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.js +237 -0
- package/dist/esm/cli/ssrPlugin.js +219 -0
- package/dist/esm/cli/utils.js +53 -0
- package/dist/esm/constant.js +42 -0
- package/dist/esm/interfaces/bundler.js +0 -0
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/logger.js +7 -0
- package/dist/esm/runtime/AwaitDataFetch.js +131 -0
- package/dist/esm/runtime/createRemoteComponent.js +417 -0
- package/dist/esm/runtime/index.js +22 -0
- package/dist/esm/runtime/wrapNoSSR.js +12 -0
- package/dist/esm/server/fileCache.js +98 -0
- package/dist/esm/server/fileCache.spec.js +50 -0
- package/dist/esm/server/index.js +36 -0
- package/dist/esm/server/staticMiddleware.js +81 -0
- package/dist/esm/server/staticMiddleware.spec.js +328 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.js +26 -0
- package/dist/esm/ssr-runtime/devPlugin.js +73 -0
- package/dist/esm/ssr-runtime/downgrade.js +150 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm/utils/dataFetch.js +237 -0
- package/dist/esm/utils/index.js +28 -0
- package/dist/esm-node/cli/configPlugin.js +340 -0
- package/dist/esm-node/cli/configPlugin.spec.js +91 -0
- package/dist/esm-node/cli/index.js +70 -0
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +62 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +159 -0
- package/dist/esm-node/cli/ssrPlugin.js +200 -0
- package/dist/esm-node/cli/utils.js +53 -0
- package/dist/esm-node/constant.js +42 -0
- package/dist/esm-node/interfaces/bundler.js +0 -0
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/logger.js +7 -0
- package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
- package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
- package/dist/esm-node/runtime/index.js +22 -0
- package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
- package/dist/esm-node/server/fileCache.js +49 -0
- package/dist/esm-node/server/fileCache.spec.js +27 -0
- package/dist/esm-node/server/index.js +34 -0
- package/dist/esm-node/server/staticMiddleware.js +43 -0
- package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +19 -0
- package/dist/esm-node/ssr-runtime/devPlugin.js +37 -0
- package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
- package/dist/esm-node/types/index.js +0 -0
- package/dist/esm-node/utils/dataFetch.js +166 -0
- package/dist/esm-node/utils/index.js +27 -0
- package/dist/types/cli/configPlugin.d.ts +21 -0
- package/dist/types/cli/configPlugin.spec.d.ts +1 -0
- package/dist/types/cli/index.d.ts +6 -0
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
- package/dist/types/cli/ssrPlugin.d.ts +6 -0
- package/dist/types/cli/utils.d.ts +6 -0
- package/dist/types/constant.d.ts +25 -0
- package/dist/types/interfaces/bundler.d.ts +18 -0
- package/dist/types/interfaces/global.d.ts +27 -0
- package/dist/types/logger.d.ts +2 -0
- package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
- package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
- package/dist/types/runtime/index.d.ts +10 -0
- package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
- package/dist/types/server/fileCache.d.ts +14 -0
- package/dist/types/server/fileCache.spec.d.ts +1 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/staticMiddleware.d.ts +6 -0
- package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
- package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
- package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
- package/dist/types/types/index.d.ts +24 -0
- package/dist/types/utils/dataFetch.d.ts +26 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/package.json +37 -12
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { getIPV4, isWebTarget, skipByTarget } from "./utils";
|
|
3
|
+
import { encodeName } from "@module-federation/sdk";
|
|
4
|
+
import { bundle } from "@modern-js/node-bundle-require";
|
|
5
|
+
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
|
|
6
|
+
import { autoDeleteSplitChunkCacheGroups, addDataFetchExposes } from "@module-federation/rsbuild-plugin/utils";
|
|
7
|
+
import logger from "../logger";
|
|
8
|
+
import { isDev } from "./utils";
|
|
9
|
+
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
10
|
+
function setEnv(enableSSR) {
|
|
11
|
+
if (enableSSR) {
|
|
12
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
13
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const getMFConfig = async (userConfig) => {
|
|
17
|
+
const { config, configPath } = userConfig;
|
|
18
|
+
if (config) {
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
22
|
+
const preBundlePath = await bundle(mfConfigPath);
|
|
23
|
+
const mfConfig = (await import(preBundlePath)).default;
|
|
24
|
+
return mfConfig;
|
|
25
|
+
};
|
|
26
|
+
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
27
|
+
if (!runtimePlugins.includes(runtimePlugin)) {
|
|
28
|
+
runtimePlugins.push(runtimePlugin);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
32
|
+
if (remoteIpStrategy && remoteIpStrategy === "inherit") {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!mfConfig.remotes) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const ipv4 = getIPV4();
|
|
39
|
+
const handleRemoteObject = (remoteObject) => {
|
|
40
|
+
Object.keys(remoteObject).forEach((remoteKey) => {
|
|
41
|
+
const remote = remoteObject[remoteKey];
|
|
42
|
+
if (Array.isArray(remote)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
46
|
+
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
47
|
+
}
|
|
48
|
+
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
49
|
+
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
if (Array.isArray(mfConfig.remotes)) {
|
|
54
|
+
mfConfig.remotes.forEach((remoteObject) => {
|
|
55
|
+
if (typeof remoteObject === "string") {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
handleRemoteObject(remoteObject);
|
|
59
|
+
});
|
|
60
|
+
} else if (typeof mfConfig.remotes !== "string") {
|
|
61
|
+
handleRemoteObject(mfConfig.remotes);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const patchDTSConfig = (mfConfig, isServer) => {
|
|
65
|
+
if (isServer) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const ModernJSRuntime = "@module-federation/modern-js/runtime";
|
|
69
|
+
if (mfConfig.dts !== false) {
|
|
70
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
71
|
+
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
72
|
+
mfConfig.dts = {
|
|
73
|
+
consumeTypes: {
|
|
74
|
+
runtimePkgs: [
|
|
75
|
+
ModernJSRuntime
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
} else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
80
|
+
var _mfConfig_dts2;
|
|
81
|
+
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
82
|
+
mfConfig.dts.consumeTypes = {
|
|
83
|
+
runtimePkgs: [
|
|
84
|
+
ModernJSRuntime
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
89
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
90
|
+
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR) => {
|
|
97
|
+
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
98
|
+
addDataFetchExposes(mfConfig.exposes, isServer);
|
|
99
|
+
if (mfConfig.remoteType === void 0) {
|
|
100
|
+
mfConfig.remoteType = "script";
|
|
101
|
+
}
|
|
102
|
+
if (!mfConfig.name) {
|
|
103
|
+
throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
104
|
+
}
|
|
105
|
+
const runtimePlugins = [
|
|
106
|
+
...mfConfig.runtimePlugins || []
|
|
107
|
+
];
|
|
108
|
+
patchDTSConfig(mfConfig, isServer);
|
|
109
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
110
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/auto-fetch-data"), runtimePlugins);
|
|
111
|
+
if (enableSSR && isDev()) {
|
|
112
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
113
|
+
}
|
|
114
|
+
if (isServer) {
|
|
115
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
116
|
+
if (isDev()) {
|
|
117
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
118
|
+
}
|
|
119
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
|
|
120
|
+
if (!mfConfig.library) {
|
|
121
|
+
mfConfig.library = {
|
|
122
|
+
type: "commonjs-module",
|
|
123
|
+
name: mfConfig.name
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
if (!mfConfig.library.type) {
|
|
127
|
+
mfConfig.library.type = "commonjs-module";
|
|
128
|
+
}
|
|
129
|
+
if (!mfConfig.library.name) {
|
|
130
|
+
mfConfig.library.name = mfConfig.name;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
135
|
+
if (!isServer) {
|
|
136
|
+
var _mfConfig_library;
|
|
137
|
+
if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
|
|
138
|
+
mfConfig.library.type = "global";
|
|
139
|
+
}
|
|
140
|
+
return mfConfig;
|
|
141
|
+
}
|
|
142
|
+
mfConfig.dts = false;
|
|
143
|
+
mfConfig.dev = false;
|
|
144
|
+
return mfConfig;
|
|
145
|
+
};
|
|
146
|
+
function patchIgnoreWarning(chain) {
|
|
147
|
+
const ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
148
|
+
const ignoredMsgs = [
|
|
149
|
+
"external script",
|
|
150
|
+
"process.env.WS_NO_BUFFER_UTIL",
|
|
151
|
+
`Can't resolve 'utf-8-validate`
|
|
152
|
+
];
|
|
153
|
+
ignoreWarnings.push((warning) => {
|
|
154
|
+
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
});
|
|
159
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
160
|
+
}
|
|
161
|
+
function addMyTypes2Ignored(chain, mfConfig) {
|
|
162
|
+
const watchOptions = chain.get("watchOptions");
|
|
163
|
+
if (!watchOptions || !watchOptions.ignored) {
|
|
164
|
+
chain.watchOptions({
|
|
165
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const ignored = watchOptions.ignored;
|
|
170
|
+
const DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
|
|
171
|
+
if (Array.isArray(ignored)) {
|
|
172
|
+
if (mfConfig.dts !== false && typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
173
|
+
chain.watchOptions({
|
|
174
|
+
...watchOptions,
|
|
175
|
+
ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
chain.watchOptions({
|
|
179
|
+
...watchOptions,
|
|
180
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (typeof ignored !== "string") {
|
|
186
|
+
chain.watchOptions({
|
|
187
|
+
...watchOptions,
|
|
188
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
chain.watchOptions({
|
|
193
|
+
...watchOptions,
|
|
194
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function patchBundlerConfig(options) {
|
|
198
|
+
var _modernjsConfig_deploy;
|
|
199
|
+
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
200
|
+
chain.optimization.delete("runtimeChunk");
|
|
201
|
+
patchIgnoreWarning(chain);
|
|
202
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
203
|
+
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
204
|
+
}
|
|
205
|
+
if (!chain.output.get("uniqueName")) {
|
|
206
|
+
chain.output.uniqueName(mfConfig.name);
|
|
207
|
+
}
|
|
208
|
+
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
209
|
+
if (!isServer) {
|
|
210
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
211
|
+
}
|
|
212
|
+
if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
|
|
213
|
+
splitChunkConfig.chunks = "async";
|
|
214
|
+
logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
215
|
+
}
|
|
216
|
+
if (isDev() && chain.output.get("publicPath") === "auto") {
|
|
217
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
218
|
+
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
219
|
+
const publicPath = `http://localhost:${port}/`;
|
|
220
|
+
chain.output.publicPath(publicPath);
|
|
221
|
+
}
|
|
222
|
+
if (isServer && enableSSR) {
|
|
223
|
+
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
224
|
+
const chunkFileName = chain.output.get("chunkFilename");
|
|
225
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
226
|
+
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
|
|
227
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (isDev() && enableSSR && !isServer) {
|
|
231
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
232
|
+
}
|
|
233
|
+
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
234
|
+
chain.optimization.usedExports(false);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
238
|
+
name: "@modern-js/plugin-module-federation-config",
|
|
239
|
+
pre: [
|
|
240
|
+
"@modern-js/plugin-initialize"
|
|
241
|
+
],
|
|
242
|
+
post: [
|
|
243
|
+
"@modern-js/plugin-module-federation"
|
|
244
|
+
],
|
|
245
|
+
setup: async (api) => {
|
|
246
|
+
var _userConfig_userConfig, _modernjsConfig_server;
|
|
247
|
+
const modernjsConfig = api.getConfig();
|
|
248
|
+
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
249
|
+
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
250
|
+
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
251
|
+
userConfig.ssrConfig = ssrConfig;
|
|
252
|
+
userConfig.csrConfig = csrConfig;
|
|
253
|
+
var _userConfig_userConfig_ssr;
|
|
254
|
+
const enableSSR = Boolean((_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr));
|
|
255
|
+
api.modifyBundlerChain((chain) => {
|
|
256
|
+
const target = chain.get("target");
|
|
257
|
+
if (skipByTarget(target)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const isWeb = isWebTarget(target);
|
|
261
|
+
addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
|
|
262
|
+
const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
|
|
263
|
+
patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4", enableSSR);
|
|
264
|
+
patchBundlerConfig({
|
|
265
|
+
chain,
|
|
266
|
+
isServer: !isWeb,
|
|
267
|
+
modernjsConfig,
|
|
268
|
+
mfConfig,
|
|
269
|
+
enableSSR
|
|
270
|
+
});
|
|
271
|
+
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
272
|
+
});
|
|
273
|
+
api.config(() => {
|
|
274
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
275
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
276
|
+
const ipv4 = getIPV4();
|
|
277
|
+
if (userConfig.remoteIpStrategy === void 0) {
|
|
278
|
+
if (!enableSSR) {
|
|
279
|
+
userConfig.remoteIpStrategy = "inherit";
|
|
280
|
+
} else {
|
|
281
|
+
userConfig.remoteIpStrategy = "ipv4";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const devServerConfig = (_modernjsConfig_tools = modernjsConfig.tools) === null || _modernjsConfig_tools === void 0 ? void 0 : _modernjsConfig_tools.devServer;
|
|
285
|
+
const corsWarnMsgs = [
|
|
286
|
+
"View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details."
|
|
287
|
+
];
|
|
288
|
+
if (typeof devServerConfig !== "object" || !("headers" in devServerConfig)) {
|
|
289
|
+
corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
|
|
290
|
+
}
|
|
291
|
+
const exposes = (_userConfig_csrConfig = userConfig.csrConfig) === null || _userConfig_csrConfig === void 0 ? void 0 : _userConfig_csrConfig.exposes;
|
|
292
|
+
const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(exposes !== null && exposes !== void 0 ? exposes : {}).length;
|
|
293
|
+
if (corsWarnMsgs.length > 1 && hasExposes) {
|
|
294
|
+
logger.warn(corsWarnMsgs.join("\n"));
|
|
295
|
+
}
|
|
296
|
+
const corsHeaders = hasExposes ? {
|
|
297
|
+
"Access-Control-Allow-Origin": "*",
|
|
298
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
299
|
+
"Access-Control-Allow-Headers": "*"
|
|
300
|
+
} : void 0;
|
|
301
|
+
const defineConfig = {
|
|
302
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
303
|
+
};
|
|
304
|
+
if (enableSSR && isDev()) {
|
|
305
|
+
defineConfig["FEDERATION_IPV4"] = JSON.stringify(ipv4);
|
|
306
|
+
}
|
|
307
|
+
var _modernjsConfig_source_enableAsyncEntry;
|
|
308
|
+
return {
|
|
309
|
+
tools: {
|
|
310
|
+
devServer: {
|
|
311
|
+
headers: corsHeaders
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
source: {
|
|
315
|
+
alias: {
|
|
316
|
+
// TODO: deprecated
|
|
317
|
+
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
318
|
+
},
|
|
319
|
+
define: defineConfig,
|
|
320
|
+
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
321
|
+
},
|
|
322
|
+
dev: {
|
|
323
|
+
assetPrefix: (modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
var configPlugin_default = moduleFederationConfigPlugin;
|
|
330
|
+
export {
|
|
331
|
+
addMyTypes2Ignored,
|
|
332
|
+
configPlugin_default as default,
|
|
333
|
+
getMFConfig,
|
|
334
|
+
isWebTarget,
|
|
335
|
+
moduleFederationConfigPlugin,
|
|
336
|
+
patchBundlerConfig,
|
|
337
|
+
patchMFConfig,
|
|
338
|
+
setEnv,
|
|
339
|
+
skipByTarget
|
|
340
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { it, expect, describe } from "vitest";
|
|
2
|
+
import { patchMFConfig } from "./configPlugin";
|
|
3
|
+
import { getIPV4 } from "./utils";
|
|
4
|
+
const mfConfig = {
|
|
5
|
+
name: "host",
|
|
6
|
+
filename: "remoteEntry.js",
|
|
7
|
+
remotes: {
|
|
8
|
+
remote: "http://localhost:3000/remoteEntry.js"
|
|
9
|
+
},
|
|
10
|
+
shared: {
|
|
11
|
+
react: {
|
|
12
|
+
singleton: true,
|
|
13
|
+
eager: true
|
|
14
|
+
},
|
|
15
|
+
"react-dom": {
|
|
16
|
+
singleton: true,
|
|
17
|
+
eager: true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
describe("patchMFConfig", async () => {
|
|
22
|
+
it("patchMFConfig: server", async () => {
|
|
23
|
+
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
24
|
+
patchMFConfig(patchedConfig, true);
|
|
25
|
+
const ipv4 = getIPV4();
|
|
26
|
+
expect(patchedConfig).toStrictEqual({
|
|
27
|
+
dev: false,
|
|
28
|
+
dts: false,
|
|
29
|
+
filename: "remoteEntry.js",
|
|
30
|
+
library: {
|
|
31
|
+
name: "host",
|
|
32
|
+
type: "commonjs-module"
|
|
33
|
+
},
|
|
34
|
+
name: "host",
|
|
35
|
+
remotes: {
|
|
36
|
+
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
37
|
+
},
|
|
38
|
+
remoteType: "script",
|
|
39
|
+
runtimePlugins: [
|
|
40
|
+
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
41
|
+
require.resolve("@module-federation/modern-js/auto-fetch-data"),
|
|
42
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
43
|
+
require.resolve("@module-federation/modern-js/inject-node-fetch")
|
|
44
|
+
],
|
|
45
|
+
shared: {
|
|
46
|
+
react: {
|
|
47
|
+
eager: true,
|
|
48
|
+
singleton: true
|
|
49
|
+
},
|
|
50
|
+
"react-dom": {
|
|
51
|
+
eager: true,
|
|
52
|
+
singleton: true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it("patchMFConfig: client", async () => {
|
|
58
|
+
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
59
|
+
patchMFConfig(patchedConfig, false);
|
|
60
|
+
const ipv4 = getIPV4();
|
|
61
|
+
expect(patchedConfig).toStrictEqual({
|
|
62
|
+
filename: "remoteEntry.js",
|
|
63
|
+
name: "host",
|
|
64
|
+
remotes: {
|
|
65
|
+
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
66
|
+
},
|
|
67
|
+
remoteType: "script",
|
|
68
|
+
runtimePlugins: [
|
|
69
|
+
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
70
|
+
require.resolve("@module-federation/modern-js/auto-fetch-data")
|
|
71
|
+
],
|
|
72
|
+
shared: {
|
|
73
|
+
react: {
|
|
74
|
+
eager: true,
|
|
75
|
+
singleton: true
|
|
76
|
+
},
|
|
77
|
+
"react-dom": {
|
|
78
|
+
eager: true,
|
|
79
|
+
singleton: true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
dts: {
|
|
83
|
+
consumeTypes: {
|
|
84
|
+
runtimePkgs: [
|
|
85
|
+
"@module-federation/modern-js/runtime"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
2
|
+
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
3
|
+
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
4
|
+
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
5
|
+
import { isWebTarget } from "./utils";
|
|
6
|
+
const moduleFederationPlugin = (userConfig = {}) => {
|
|
7
|
+
var _userConfig_fetchServerQuery;
|
|
8
|
+
const internalModernPluginOptions = {
|
|
9
|
+
csrConfig: void 0,
|
|
10
|
+
ssrConfig: void 0,
|
|
11
|
+
browserPlugin: void 0,
|
|
12
|
+
nodePlugin: void 0,
|
|
13
|
+
distOutputDir: "",
|
|
14
|
+
originPluginOptions: userConfig,
|
|
15
|
+
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
16
|
+
userConfig: userConfig || {},
|
|
17
|
+
fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
name: "@modern-js/plugin-module-federation",
|
|
21
|
+
setup: async (api) => {
|
|
22
|
+
const modernjsConfig = api.getConfig();
|
|
23
|
+
api.modifyBundlerChain((chain) => {
|
|
24
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
25
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
26
|
+
const MFPlugin = bundlerType === "webpack" ? WebpackModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
27
|
+
if (isWebTarget(chain.get("target"))) {
|
|
28
|
+
chain.plugin("plugin-module-federation").use(MFPlugin, [
|
|
29
|
+
browserPluginOptions
|
|
30
|
+
]).init((Plugin, args) => {
|
|
31
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
32
|
+
return internalModernPluginOptions.browserPlugin;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (bundlerType === "webpack") {
|
|
36
|
+
var _modernjsConfig_source;
|
|
37
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
38
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
39
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
40
|
+
eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
|
|
41
|
+
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
42
|
+
};
|
|
43
|
+
chain.plugin("async-boundary-plugin").use(AsyncBoundaryPlugin, [
|
|
44
|
+
asyncBoundaryPluginOptions
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
api._internalServerPlugins(({ plugins }) => {
|
|
50
|
+
plugins.push({
|
|
51
|
+
name: "@module-federation/modern-js/server"
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
plugins
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
usePlugins: [
|
|
59
|
+
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
60
|
+
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
var cli_default = moduleFederationPlugin;
|
|
65
|
+
import { createModuleFederationConfig } from "@module-federation/enhanced";
|
|
66
|
+
export {
|
|
67
|
+
createModuleFederationConfig,
|
|
68
|
+
cli_default as default,
|
|
69
|
+
moduleFederationPlugin
|
|
70
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getDataFetchInfo, initDataFetchMap, getDataFetchItem, getDataFetchMap, isCSROnly } from "../../utils";
|
|
2
|
+
import logger from "../../logger";
|
|
3
|
+
import { getDataFetchMapKey, isDataLoaderExpose, loadDataFetchModule } from "../../utils/dataFetch";
|
|
4
|
+
import { MF_DATA_FETCH_TYPE, MF_DATA_FETCH_STATUS } from "../../constant";
|
|
5
|
+
import { DATA_FETCH_CLIENT_SUFFIX } from "@module-federation/rsbuild-plugin/constant";
|
|
6
|
+
const autoFetchData = () => ({
|
|
7
|
+
name: "auto-fetch-data-plugin",
|
|
8
|
+
beforeInit(args) {
|
|
9
|
+
initDataFetchMap();
|
|
10
|
+
return args;
|
|
11
|
+
},
|
|
12
|
+
afterLoadSnapshot(args) {
|
|
13
|
+
const { id, moduleInfo, remoteSnapshot, host } = args;
|
|
14
|
+
if (typeof id === "string" && isDataLoaderExpose(id)) {
|
|
15
|
+
return args;
|
|
16
|
+
}
|
|
17
|
+
if (!remoteSnapshot || !id || !("modules" in remoteSnapshot)) {
|
|
18
|
+
return args;
|
|
19
|
+
}
|
|
20
|
+
const { name, alias } = moduleInfo;
|
|
21
|
+
const dataFetchInfo = getDataFetchInfo({
|
|
22
|
+
name,
|
|
23
|
+
alias,
|
|
24
|
+
id,
|
|
25
|
+
remoteSnapshot
|
|
26
|
+
});
|
|
27
|
+
if (!dataFetchInfo) {
|
|
28
|
+
return args;
|
|
29
|
+
}
|
|
30
|
+
const { dataFetchId, dataFetchName } = dataFetchInfo;
|
|
31
|
+
const dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
|
|
32
|
+
name: host.name,
|
|
33
|
+
version: host.options.version
|
|
34
|
+
});
|
|
35
|
+
logger.debug("======= auto fetch plugin dataFetchMapKey: ", dataFetchMapKey);
|
|
36
|
+
if (!dataFetchMapKey) {
|
|
37
|
+
return args;
|
|
38
|
+
}
|
|
39
|
+
const dataFetchItem = getDataFetchItem(dataFetchMapKey);
|
|
40
|
+
if (dataFetchItem) {
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
const dataFetchMap = getDataFetchMap();
|
|
44
|
+
const downgradeType = remoteSnapshot.modules.find((module) => module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`) ? MF_DATA_FETCH_TYPE.FETCH_CLIENT : MF_DATA_FETCH_TYPE.FETCH_SERVER;
|
|
45
|
+
let finalDataFetchId = dataFetchId;
|
|
46
|
+
if (typeof window !== "undefined") {
|
|
47
|
+
finalDataFetchId = downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT ? `${dataFetchId}${DATA_FETCH_CLIENT_SUFFIX}` : dataFetchId;
|
|
48
|
+
}
|
|
49
|
+
const getDataFetchGetter = () => loadDataFetchModule(host, finalDataFetchId);
|
|
50
|
+
const dataFetchFnItem = [
|
|
51
|
+
getDataFetchGetter,
|
|
52
|
+
downgradeType
|
|
53
|
+
];
|
|
54
|
+
if (typeof window === "undefined" || isCSROnly()) {
|
|
55
|
+
dataFetchFnItem.push(getDataFetchGetter());
|
|
56
|
+
}
|
|
57
|
+
dataFetchMap[dataFetchMapKey] = [
|
|
58
|
+
dataFetchFnItem,
|
|
59
|
+
void 0,
|
|
60
|
+
MF_DATA_FETCH_STATUS.AWAIT
|
|
61
|
+
];
|
|
62
|
+
return args;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
var auto_fetch_data_default = autoFetchData;
|
|
66
|
+
export {
|
|
67
|
+
auto_fetch_data_default as default
|
|
68
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import nodeFetch from "node-fetch";
|
|
2
|
+
const injectNodeFetchPlugin = () => ({
|
|
3
|
+
name: "inject-node-fetch-plugin",
|
|
4
|
+
beforeInit(args) {
|
|
5
|
+
if (!globalThis.fetch) {
|
|
6
|
+
globalThis.fetch = nodeFetch;
|
|
7
|
+
}
|
|
8
|
+
return args;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
12
|
+
export {
|
|
13
|
+
inject_node_fetch_default as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LOCALHOST } from "../../constant";
|
|
2
|
+
const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
3
|
+
const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
4
|
+
function replaceObjectLocalhost(key, obj) {
|
|
5
|
+
if (remoteIpStrategy !== "ipv4") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (!(key in obj)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const remote = obj[key];
|
|
12
|
+
if (remote && typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
13
|
+
obj[key] = replaceLocalhost(remote);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function replaceLocalhost(url) {
|
|
17
|
+
return url.replace(LOCALHOST, ipv4);
|
|
18
|
+
}
|
|
19
|
+
const resolveEntryIpv4Plugin = () => ({
|
|
20
|
+
name: "resolve-entry-ipv4",
|
|
21
|
+
beforeRegisterRemote(args) {
|
|
22
|
+
const { remote } = args;
|
|
23
|
+
replaceObjectLocalhost("entry", remote);
|
|
24
|
+
return args;
|
|
25
|
+
},
|
|
26
|
+
async afterResolve(args) {
|
|
27
|
+
const { remoteInfo } = args;
|
|
28
|
+
replaceObjectLocalhost("entry", remoteInfo);
|
|
29
|
+
return args;
|
|
30
|
+
},
|
|
31
|
+
beforeLoadRemoteSnapshot(args) {
|
|
32
|
+
const { moduleInfo } = args;
|
|
33
|
+
if ("entry" in moduleInfo) {
|
|
34
|
+
replaceObjectLocalhost("entry", moduleInfo);
|
|
35
|
+
return args;
|
|
36
|
+
}
|
|
37
|
+
if ("version" in moduleInfo) {
|
|
38
|
+
replaceObjectLocalhost("version", moduleInfo);
|
|
39
|
+
}
|
|
40
|
+
return args;
|
|
41
|
+
},
|
|
42
|
+
loadRemoteSnapshot(args) {
|
|
43
|
+
const { remoteSnapshot } = args;
|
|
44
|
+
if ("publicPath" in remoteSnapshot) {
|
|
45
|
+
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
46
|
+
}
|
|
47
|
+
if ("getPublicPath" in remoteSnapshot) {
|
|
48
|
+
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
49
|
+
}
|
|
50
|
+
if (remoteSnapshot.remotesInfo) {
|
|
51
|
+
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
52
|
+
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
53
|
+
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return args;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
60
|
+
export {
|
|
61
|
+
resolve_entry_ipv4_default as default
|
|
62
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const sharedStrategy = () => ({
|
|
2
|
+
name: "shared-strategy-plugin",
|
|
3
|
+
beforeInit(args) {
|
|
4
|
+
const { userOptions } = args;
|
|
5
|
+
const shared = userOptions.shared;
|
|
6
|
+
if (shared) {
|
|
7
|
+
Object.keys(shared).forEach((sharedKey) => {
|
|
8
|
+
const sharedConfigs = shared[sharedKey];
|
|
9
|
+
const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
10
|
+
sharedConfigs
|
|
11
|
+
];
|
|
12
|
+
arraySharedConfigs.forEach((s) => {
|
|
13
|
+
s.strategy = "loaded-first";
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return args;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var shared_strategy_default = sharedStrategy;
|
|
21
|
+
export {
|
|
22
|
+
shared_strategy_default as default
|
|
23
|
+
};
|