@module-federation/modern-js 0.0.0-chore-bump-node-22-20260710161714
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/cli/configPlugin.js +346 -0
- package/dist/cjs/cli/index.js +115 -0
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +54 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +53 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +59 -0
- package/dist/cjs/cli/ssrPlugin.js +314 -0
- package/dist/cjs/cli/utils.js +93 -0
- package/dist/cjs/constant.js +40 -0
- package/dist/cjs/interfaces/bundler.js +18 -0
- package/dist/cjs/logger.js +39 -0
- package/dist/cjs/react/data-fetch.js +58 -0
- package/dist/cjs/react/index.js +58 -0
- package/dist/cjs/react/plugin.js +65 -0
- package/dist/cjs/react/v18.js +58 -0
- package/dist/cjs/react/v19.js +58 -0
- package/dist/cjs/runtime/index.js +58 -0
- package/dist/cjs/server/fileCache.js +82 -0
- package/dist/cjs/server/index.js +71 -0
- package/dist/cjs/server/staticMiddleware.js +97 -0
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +50 -0
- package/dist/cjs/ssr-runtime/devPlugin.js +67 -0
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +47 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/esm/cli/configPlugin.mjs +321 -0
- package/dist/esm/cli/index.mjs +91 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
- package/dist/esm/cli/ssrPlugin.mjs +297 -0
- package/dist/esm/cli/utils.mjs +40 -0
- package/dist/esm/constant.mjs +3 -0
- package/dist/esm/interfaces/bundler.mjs +0 -0
- package/dist/esm/logger.mjs +5 -0
- package/dist/esm/react/data-fetch.mjs +1 -0
- package/dist/esm/react/index.mjs +1 -0
- package/dist/esm/react/plugin.mjs +3 -0
- package/dist/esm/react/v18.mjs +1 -0
- package/dist/esm/react/v19.mjs +1 -0
- package/dist/esm/runtime/index.mjs +1 -0
- package/dist/esm/server/fileCache.mjs +125 -0
- package/dist/esm/server/index.mjs +36 -0
- package/dist/esm/server/staticMiddleware.mjs +122 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.mjs +23 -0
- package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +33 -0
- package/dist/esm/types/index.mjs +0 -0
- package/dist/esm-node/cli/configPlugin.mjs +276 -0
- package/dist/esm-node/cli/index.mjs +75 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
- package/dist/esm-node/cli/ssrPlugin.mjs +258 -0
- package/dist/esm-node/cli/utils.mjs +40 -0
- package/dist/esm-node/constant.mjs +3 -0
- package/dist/esm-node/interfaces/bundler.mjs +0 -0
- package/dist/esm-node/logger.mjs +5 -0
- package/dist/esm-node/react/data-fetch.mjs +1 -0
- package/dist/esm-node/react/index.mjs +1 -0
- package/dist/esm-node/react/plugin.mjs +3 -0
- package/dist/esm-node/react/v18.mjs +1 -0
- package/dist/esm-node/react/v19.mjs +1 -0
- package/dist/esm-node/runtime/index.mjs +1 -0
- package/dist/esm-node/server/fileCache.mjs +45 -0
- package/dist/esm-node/server/index.mjs +34 -0
- package/dist/esm-node/server/staticMiddleware.mjs +50 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +16 -0
- package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +13 -0
- package/dist/esm-node/types/index.mjs +0 -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/inject-node-fetch.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/ssrPlugin.spec.d.ts +1 -0
- package/dist/types/cli/utils.d.ts +6 -0
- package/dist/types/constant.d.ts +2 -0
- package/dist/types/interfaces/bundler.d.ts +18 -0
- package/dist/types/logger.d.ts +2 -0
- package/dist/types/react/data-fetch.d.ts +1 -0
- package/dist/types/react/index.d.ts +1 -0
- package/dist/types/react/plugin.d.ts +2 -0
- package/dist/types/react/v18.d.ts +1 -0
- package/dist/types/react/v19.d.ts +1 -0
- package/dist/types/runtime/index.d.ts +1 -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 +7 -0
- package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +2 -0
- package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +4 -0
- package/dist/types/types/index.d.ts +35 -0
- package/package.json +192 -0
- package/types.d.ts +6 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_tagged_template_literal";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import "react";
|
|
4
|
+
function SSRLiveReload_templateObject() {
|
|
5
|
+
var data = _([
|
|
6
|
+
"\n if(",
|
|
7
|
+
"){\n location.reload();\n }\n "
|
|
8
|
+
]);
|
|
9
|
+
SSRLiveReload_templateObject = function() {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function SSRLiveReload() {
|
|
15
|
+
if ('development' !== process.env.NODE_ENV) return null;
|
|
16
|
+
return /*#__PURE__*/ jsx("script", {
|
|
17
|
+
suppressHydrationWarning: true,
|
|
18
|
+
dangerouslySetInnerHTML: {
|
|
19
|
+
__html: String.raw(SSRLiveReload_templateObject(), globalThis.shouldUpdate)
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export { SSRLiveReload };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
3
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { SSRLiveReload } from "./SSRLiveReload.mjs";
|
|
6
|
+
import { flushDataFetch } from "@module-federation/bridge-react/data-fetch";
|
|
7
|
+
var devPlugin_mfSSRDevPlugin = function() {
|
|
8
|
+
return {
|
|
9
|
+
name: '@module-federation/modern-js',
|
|
10
|
+
setup: function(api) {
|
|
11
|
+
api.onBeforeRender(function() {
|
|
12
|
+
return _(function() {
|
|
13
|
+
var nodeUtils, shouldUpdate;
|
|
14
|
+
return _ts_generator__(this, function(_state) {
|
|
15
|
+
switch(_state.label){
|
|
16
|
+
case 0:
|
|
17
|
+
if ("u" > typeof window) return [
|
|
18
|
+
2
|
|
19
|
+
];
|
|
20
|
+
globalThis.shouldUpdate = false;
|
|
21
|
+
return [
|
|
22
|
+
4,
|
|
23
|
+
import("@module-federation/node/utils")
|
|
24
|
+
];
|
|
25
|
+
case 1:
|
|
26
|
+
nodeUtils = _state.sent();
|
|
27
|
+
return [
|
|
28
|
+
4,
|
|
29
|
+
nodeUtils.revalidate()
|
|
30
|
+
];
|
|
31
|
+
case 2:
|
|
32
|
+
shouldUpdate = _state.sent();
|
|
33
|
+
console.log('shouldUpdate: ', shouldUpdate);
|
|
34
|
+
if (!shouldUpdate) return [
|
|
35
|
+
3,
|
|
36
|
+
4
|
|
37
|
+
];
|
|
38
|
+
console.log('should RELOAD', shouldUpdate);
|
|
39
|
+
return [
|
|
40
|
+
4,
|
|
41
|
+
nodeUtils.flushChunks()
|
|
42
|
+
];
|
|
43
|
+
case 3:
|
|
44
|
+
_state.sent();
|
|
45
|
+
flushDataFetch();
|
|
46
|
+
globalThis.shouldUpdate = true;
|
|
47
|
+
_state.label = 4;
|
|
48
|
+
case 4:
|
|
49
|
+
return [
|
|
50
|
+
2
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
})();
|
|
55
|
+
});
|
|
56
|
+
api.wrapRoot(function(App) {
|
|
57
|
+
var AppWrapper = function(props) {
|
|
58
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
59
|
+
children: [
|
|
60
|
+
/*#__PURE__*/ jsx(SSRLiveReload, {}),
|
|
61
|
+
/*#__PURE__*/ jsx(App, _object_spread__({}, props))
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return AppWrapper;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export { devPlugin_mfSSRDevPlugin as mfSSRDevPlugin };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { callDataFetch, setSSREnv } from "@module-federation/bridge-react/data-fetch";
|
|
4
|
+
var injectDataFetchFunctionPlugin_injectDataFetchFunctionPlugin = function(param) {
|
|
5
|
+
var fetchServerQuery = param.fetchServerQuery;
|
|
6
|
+
return {
|
|
7
|
+
name: '@module-federation/inject-data-fetch-function-plugin',
|
|
8
|
+
setup: function(api) {
|
|
9
|
+
api.onBeforeRender(function() {
|
|
10
|
+
return _(function() {
|
|
11
|
+
return _ts_generator__(this, function(_state) {
|
|
12
|
+
switch(_state.label){
|
|
13
|
+
case 0:
|
|
14
|
+
setSSREnv({
|
|
15
|
+
fetchServerQuery: fetchServerQuery
|
|
16
|
+
});
|
|
17
|
+
return [
|
|
18
|
+
4,
|
|
19
|
+
callDataFetch()
|
|
20
|
+
];
|
|
21
|
+
case 1:
|
|
22
|
+
_state.sent();
|
|
23
|
+
return [
|
|
24
|
+
2
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
})();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export { injectDataFetchFunctionPlugin_injectDataFetchFunctionPlugin as injectDataFetchFunctionPlugin };
|
|
File without changes
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import * as __rspack_external_jiti from "jiti";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
5
|
+
import { encodeName } from "@module-federation/sdk";
|
|
6
|
+
import { PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
7
|
+
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
8
|
+
import logger from "../logger.mjs";
|
|
9
|
+
var __webpack_modules__ = {
|
|
10
|
+
jiti (module) {
|
|
11
|
+
module.exports = __rspack_external_jiti;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __webpack_module_cache__ = {};
|
|
15
|
+
function __webpack_require__(moduleId) {
|
|
16
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
17
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
18
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
19
|
+
exports: {}
|
|
20
|
+
};
|
|
21
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
22
|
+
return module.exports;
|
|
23
|
+
}
|
|
24
|
+
const defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
25
|
+
const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
|
|
26
|
+
const packageEntry = require.resolve(packageName);
|
|
27
|
+
let packageRoot = path.dirname(packageEntry);
|
|
28
|
+
while(!fs.existsSync(path.join(packageRoot, 'package.json'))){
|
|
29
|
+
const parentDir = path.dirname(packageRoot);
|
|
30
|
+
if (parentDir === packageRoot) throw new Error(`Unable to resolve package root for ${packageName} from ${packageEntry}`);
|
|
31
|
+
packageRoot = parentDir;
|
|
32
|
+
}
|
|
33
|
+
return require.resolve(path.join(packageRoot, 'true' === process.env['IS_ESM_BUILD'] ? esmRelativePath : cjsRelativePath));
|
|
34
|
+
};
|
|
35
|
+
const resolveSharedStrategyPlugin = ()=>resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
|
|
36
|
+
const resolveInjectNodeFetchPlugin = ()=>resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
|
|
37
|
+
const resolveNodeRuntimePlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
|
|
38
|
+
const resolveNodeRecordRemoteHashPlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
|
|
39
|
+
function setEnv(enableSSR) {
|
|
40
|
+
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
41
|
+
}
|
|
42
|
+
const getMFConfig = async (userConfig)=>{
|
|
43
|
+
const { config, configPath } = userConfig;
|
|
44
|
+
if (config) return config;
|
|
45
|
+
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
46
|
+
const { createJiti } = __webpack_require__("jiti");
|
|
47
|
+
const jit = createJiti(__filename, {
|
|
48
|
+
interopDefault: true
|
|
49
|
+
});
|
|
50
|
+
const configModule = await jit(mfConfigPath);
|
|
51
|
+
const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
|
|
52
|
+
return resolvedConfig;
|
|
53
|
+
};
|
|
54
|
+
const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
|
|
55
|
+
const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
|
|
56
|
+
const hasPlugin = runtimePlugins.some((existingPlugin)=>{
|
|
57
|
+
if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
|
|
58
|
+
return existingPlugin[0] === pluginName;
|
|
59
|
+
});
|
|
60
|
+
if (!hasPlugin) runtimePlugins.push(runtimePlugin);
|
|
61
|
+
};
|
|
62
|
+
const patchDTSConfig = (mfConfig, isServer)=>{
|
|
63
|
+
if (isServer) return;
|
|
64
|
+
const ModernJSRuntime = '@module-federation/modern-js/runtime';
|
|
65
|
+
if (false !== mfConfig.dts) {
|
|
66
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
67
|
+
if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
|
|
68
|
+
consumeTypes: {
|
|
69
|
+
runtimePkgs: [
|
|
70
|
+
ModernJSRuntime
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
75
|
+
var _mfConfig_dts2;
|
|
76
|
+
if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
|
|
77
|
+
runtimePkgs: [
|
|
78
|
+
ModernJSRuntime
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
else {
|
|
82
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
83
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const patchMFConfig = (mfConfig, isServer)=>{
|
|
89
|
+
addDataFetchExposes(mfConfig.exposes, isServer);
|
|
90
|
+
if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
|
|
91
|
+
if (!mfConfig.name) throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
92
|
+
const runtimePlugins = [
|
|
93
|
+
...mfConfig.runtimePlugins || []
|
|
94
|
+
];
|
|
95
|
+
patchDTSConfig(mfConfig, isServer);
|
|
96
|
+
injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
|
|
97
|
+
if (isServer) {
|
|
98
|
+
injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
|
|
99
|
+
if (isDev()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
|
|
100
|
+
injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
|
|
101
|
+
if (mfConfig.library) {
|
|
102
|
+
if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
|
|
103
|
+
if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
|
|
104
|
+
} else mfConfig.library = {
|
|
105
|
+
type: 'commonjs-module',
|
|
106
|
+
name: mfConfig.name
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
110
|
+
if (!isServer) {
|
|
111
|
+
var _mfConfig_library;
|
|
112
|
+
if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
|
|
113
|
+
return mfConfig;
|
|
114
|
+
}
|
|
115
|
+
mfConfig.dts = false;
|
|
116
|
+
mfConfig.dev = false;
|
|
117
|
+
return mfConfig;
|
|
118
|
+
};
|
|
119
|
+
function patchIgnoreWarning(chain) {
|
|
120
|
+
const ignoreWarnings = chain.get('ignoreWarnings') || [];
|
|
121
|
+
const ignoredMsgs = [
|
|
122
|
+
"external script",
|
|
123
|
+
'process.env.WS_NO_BUFFER_UTIL',
|
|
124
|
+
"Can't resolve 'utf-8-validate"
|
|
125
|
+
];
|
|
126
|
+
ignoreWarnings.push((warning)=>{
|
|
127
|
+
if (ignoredMsgs.some((msg)=>warning.message.includes(msg))) return true;
|
|
128
|
+
return false;
|
|
129
|
+
});
|
|
130
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
131
|
+
}
|
|
132
|
+
function addMyTypes2Ignored(chain, mfConfig) {
|
|
133
|
+
const watchOptions = chain.get('watchOptions');
|
|
134
|
+
if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
|
|
135
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
136
|
+
});
|
|
137
|
+
const ignored = watchOptions.ignored;
|
|
138
|
+
const DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
|
|
139
|
+
if (Array.isArray(ignored)) {
|
|
140
|
+
if (false !== mfConfig.dts && 'object' == typeof mfConfig.dts && 'object' == typeof mfConfig.dts.consumeTypes && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions({
|
|
141
|
+
...watchOptions,
|
|
142
|
+
ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
|
|
143
|
+
});
|
|
144
|
+
else chain.watchOptions({
|
|
145
|
+
...watchOptions,
|
|
146
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if ('string' != typeof ignored) return void chain.watchOptions({
|
|
151
|
+
...watchOptions,
|
|
152
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
153
|
+
});
|
|
154
|
+
chain.watchOptions({
|
|
155
|
+
...watchOptions,
|
|
156
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function patchBundlerConfig(options) {
|
|
160
|
+
var _modernjsConfig_deploy;
|
|
161
|
+
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
162
|
+
chain.optimization.delete('runtimeChunk');
|
|
163
|
+
patchIgnoreWarning(chain);
|
|
164
|
+
if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
165
|
+
if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
|
|
166
|
+
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
167
|
+
if (!isServer) autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
168
|
+
if (!isServer && enableSSR && splitChunkConfig && 'object' == typeof splitChunkConfig && splitChunkConfig.cacheGroups) {
|
|
169
|
+
splitChunkConfig.chunks = 'async';
|
|
170
|
+
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
171
|
+
}
|
|
172
|
+
if (isDev() && 'auto' === chain.output.get('publicPath')) {
|
|
173
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
174
|
+
const port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
175
|
+
const publicPath = `http://localhost:${port}/`;
|
|
176
|
+
chain.output.publicPath(publicPath);
|
|
177
|
+
}
|
|
178
|
+
if (isServer && enableSSR) {
|
|
179
|
+
const uniqueName = mfConfig.name || chain.output.get('uniqueName');
|
|
180
|
+
const chunkFileName = chain.output.get('chunkFilename');
|
|
181
|
+
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
182
|
+
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
|
|
183
|
+
chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
|
|
187
|
+
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
|
|
188
|
+
}
|
|
189
|
+
const moduleFederationConfigPlugin = (userConfig)=>({
|
|
190
|
+
name: '@modern-js/plugin-module-federation-config',
|
|
191
|
+
pre: [
|
|
192
|
+
'@modern-js/plugin-initialize'
|
|
193
|
+
],
|
|
194
|
+
post: [
|
|
195
|
+
'@modern-js/plugin-module-federation'
|
|
196
|
+
],
|
|
197
|
+
setup: async (api)=>{
|
|
198
|
+
var _ref;
|
|
199
|
+
var _userConfig_userConfig, _modernjsConfig_server;
|
|
200
|
+
const modernjsConfig = api.getConfig();
|
|
201
|
+
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
202
|
+
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
203
|
+
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
204
|
+
userConfig.ssrConfig = ssrConfig;
|
|
205
|
+
userConfig.csrConfig = csrConfig;
|
|
206
|
+
const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
|
|
207
|
+
api.modifyBundlerChain((chain)=>{
|
|
208
|
+
var _modernjsConfig_source, _targetMFConfig_experiments;
|
|
209
|
+
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
210
|
+
const target = chain.get('target');
|
|
211
|
+
if (skipByTarget(target)) return;
|
|
212
|
+
const isWeb = isWebTarget(target);
|
|
213
|
+
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
214
|
+
const targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
215
|
+
patchMFConfig(targetMFConfig, !isWeb);
|
|
216
|
+
if ('rspack' === bundlerType && (null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
|
|
217
|
+
var _targetMFConfig;
|
|
218
|
+
(_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
|
|
219
|
+
targetMFConfig.experiments.asyncStartup = true;
|
|
220
|
+
}
|
|
221
|
+
patchBundlerConfig({
|
|
222
|
+
chain,
|
|
223
|
+
isServer: !isWeb,
|
|
224
|
+
modernjsConfig,
|
|
225
|
+
mfConfig,
|
|
226
|
+
enableSSR
|
|
227
|
+
});
|
|
228
|
+
if (isWeb) userConfig.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist');
|
|
229
|
+
else if (enableSSR) {
|
|
230
|
+
var _userConfig, _userConfig_userConfig;
|
|
231
|
+
(_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
|
|
232
|
+
(_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
|
|
233
|
+
if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
|
|
234
|
+
userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist/bundles');
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
api.config(()=>{
|
|
238
|
+
var _ref;
|
|
239
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
240
|
+
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
241
|
+
const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
242
|
+
const corsWarnMsgs = [
|
|
243
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
244
|
+
];
|
|
245
|
+
if ('object' != typeof devServerConfig || !('headers' in devServerConfig)) 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.');
|
|
246
|
+
const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
247
|
+
const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
248
|
+
if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
|
|
249
|
+
const corsHeaders = hasExposes ? {
|
|
250
|
+
'Access-Control-Allow-Origin': '*',
|
|
251
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
252
|
+
'Access-Control-Allow-Headers': '*'
|
|
253
|
+
} : void 0;
|
|
254
|
+
return {
|
|
255
|
+
tools: {
|
|
256
|
+
devServer: {
|
|
257
|
+
headers: corsHeaders
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
resolve: {
|
|
261
|
+
alias: {
|
|
262
|
+
'@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
source: {
|
|
266
|
+
enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
267
|
+
},
|
|
268
|
+
dev: {
|
|
269
|
+
assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
const configPlugin = moduleFederationConfigPlugin;
|
|
276
|
+
export { addMyTypes2Ignored, configPlugin as default, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setEnv, skipByTarget };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AsyncBoundaryPlugin, ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
|
|
2
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
3
|
+
import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
|
|
4
|
+
import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
|
|
5
|
+
import { isWebTarget } from "./utils.mjs";
|
|
6
|
+
const moduleFederationPlugin = (userConfig = {})=>{
|
|
7
|
+
var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
|
|
8
|
+
const internalModernPluginOptions = {
|
|
9
|
+
csrConfig: void 0,
|
|
10
|
+
ssrConfig: void 0,
|
|
11
|
+
browserPlugin: void 0,
|
|
12
|
+
nodePlugin: void 0,
|
|
13
|
+
assetResources: {},
|
|
14
|
+
distOutputDir: '',
|
|
15
|
+
originPluginOptions: {
|
|
16
|
+
...userConfig
|
|
17
|
+
},
|
|
18
|
+
userConfig: userConfig || {},
|
|
19
|
+
assetFileNames: {},
|
|
20
|
+
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
|
|
21
|
+
secondarySharedTreeShaking: null != (_userConfig_secondarySharedTreeShaking = userConfig.secondarySharedTreeShaking) ? _userConfig_secondarySharedTreeShaking : false
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
name: '@modern-js/plugin-module-federation',
|
|
25
|
+
setup: async (api)=>{
|
|
26
|
+
const modernjsConfig = api.getConfig();
|
|
27
|
+
api.modifyBundlerChain((chain)=>{
|
|
28
|
+
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
29
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
30
|
+
const { secondarySharedTreeShaking } = internalModernPluginOptions;
|
|
31
|
+
const MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
32
|
+
const TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
|
|
33
|
+
if (isWebTarget(chain.get('target'))) if (secondarySharedTreeShaking) chain.plugin('plugin-module-federation').use(TreeShakingSharedPlugin, [
|
|
34
|
+
{
|
|
35
|
+
mfConfig: browserPluginOptions,
|
|
36
|
+
secondary: true
|
|
37
|
+
}
|
|
38
|
+
]);
|
|
39
|
+
else chain.plugin('plugin-module-federation').use(MFPlugin, [
|
|
40
|
+
browserPluginOptions
|
|
41
|
+
]).init((Plugin, args)=>{
|
|
42
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
43
|
+
return internalModernPluginOptions.browserPlugin;
|
|
44
|
+
});
|
|
45
|
+
if ('webpack' === bundlerType && !secondarySharedTreeShaking) {
|
|
46
|
+
var _modernjsConfig_source;
|
|
47
|
+
const enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
48
|
+
if (!enableAsyncEntry && false !== browserPluginOptions.async) {
|
|
49
|
+
const asyncBoundaryPluginOptions = 'object' == typeof browserPluginOptions.async ? browserPluginOptions.async : {
|
|
50
|
+
eager: (module)=>module && /\.federation/.test((null == module ? void 0 : module.request) || ''),
|
|
51
|
+
excludeChunk: (chunk)=>chunk.name === browserPluginOptions.name
|
|
52
|
+
};
|
|
53
|
+
chain.plugin('async-boundary-plugin').use(AsyncBoundaryPlugin, [
|
|
54
|
+
asyncBoundaryPluginOptions
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
api._internalServerPlugins(({ plugins })=>{
|
|
60
|
+
plugins.push({
|
|
61
|
+
name: '@module-federation/modern-js/server'
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
plugins
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
usePlugins: [
|
|
69
|
+
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
70
|
+
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const cli = moduleFederationPlugin;
|
|
75
|
+
export { createModuleFederationConfig, cli as default, moduleFederationPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import node_fetch from "node-fetch";
|
|
2
|
+
const injectNodeFetchPlugin = ()=>({
|
|
3
|
+
name: 'inject-node-fetch-plugin',
|
|
4
|
+
beforeInit (args) {
|
|
5
|
+
if (!globalThis.fetch) globalThis.fetch = node_fetch;
|
|
6
|
+
return args;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
const inject_node_fetch = injectNodeFetchPlugin;
|
|
10
|
+
export { inject_node_fetch as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const sharedStrategy = ()=>({
|
|
2
|
+
name: 'shared-strategy-plugin',
|
|
3
|
+
beforeInit (args) {
|
|
4
|
+
const { userOptions } = args;
|
|
5
|
+
const shared = userOptions.shared;
|
|
6
|
+
if (shared) Object.keys(shared).forEach((sharedKey)=>{
|
|
7
|
+
const sharedConfigs = shared[sharedKey];
|
|
8
|
+
const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
9
|
+
sharedConfigs
|
|
10
|
+
];
|
|
11
|
+
arraySharedConfigs.forEach((s)=>{
|
|
12
|
+
s.strategy = 'loaded-first';
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return args;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const shared_strategy = sharedStrategy;
|
|
19
|
+
export { shared_strategy as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import data_fetch_server_middleware from "@module-federation/bridge-react/data-fetch-server-middleware";
|
|
2
|
+
const dataFetchServePlugin = ()=>({
|
|
3
|
+
name: 'mf-data-fetch-server-plugin',
|
|
4
|
+
setup: (api)=>{
|
|
5
|
+
api.onPrepare(()=>{
|
|
6
|
+
const { middlewares } = api.getServerContext();
|
|
7
|
+
middlewares.push({
|
|
8
|
+
name: 'module-federation-serve-manifest',
|
|
9
|
+
handler: data_fetch_server_middleware
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const data_fetch_server_plugin = dataFetchServePlugin;
|
|
15
|
+
export { data_fetch_server_plugin as default };
|