@module-federation/modern-js-v3 2.6.0 → 2.8.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/cjs/cli/configPlugin.js +34 -13
- package/dist/cjs/cli/index.js +11 -7
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +14 -21
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +12 -8
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +9 -5
- package/dist/cjs/cli/ssrPlugin.js +11 -7
- package/dist/cjs/cli/utils.js +9 -5
- package/dist/cjs/constant.js +13 -9
- package/dist/cjs/logger.js +9 -5
- package/dist/cjs/react/data-fetch.js +9 -5
- package/dist/cjs/react/index.js +9 -5
- package/dist/cjs/react/plugin.js +12 -8
- package/dist/cjs/react/v18.js +9 -5
- package/dist/cjs/react/v19.js +9 -5
- package/dist/cjs/runtime/index.js +9 -5
- package/dist/cjs/server/fileCache.js +13 -9
- package/dist/cjs/server/index.js +9 -5
- package/dist/cjs/server/staticMiddleware.js +11 -7
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +9 -5
- package/dist/cjs/ssr-runtime/devPlugin.js +9 -5
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +9 -5
- package/dist/esm/cli/configPlugin.mjs +25 -18
- package/dist/esm/cli/index.mjs +3 -2
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +2 -3
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +1 -1
- package/dist/esm/cli/server/data-fetch-server-plugin.mjs +1 -1
- package/dist/esm/cli/ssrPlugin.mjs +2 -1
- package/dist/esm/cli/utils.mjs +1 -1
- package/dist/esm/interfaces/bundler.mjs +1 -0
- package/dist/esm/logger.mjs +1 -1
- package/dist/esm/react/plugin.mjs +1 -2
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/server/fileCache.mjs +5 -4
- package/dist/esm/server/index.mjs +2 -1
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm-node/cli/configPlugin.mjs +24 -18
- package/dist/esm-node/cli/index.mjs +3 -2
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +2 -3
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +1 -1
- package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +1 -1
- package/dist/esm-node/cli/ssrPlugin.mjs +2 -1
- package/dist/esm-node/interfaces/bundler.mjs +1 -0
- package/dist/esm-node/logger.mjs +1 -1
- package/dist/esm-node/react/plugin.mjs +1 -2
- package/dist/esm-node/rslib-runtime.mjs +18 -0
- package/dist/esm-node/server/fileCache.mjs +4 -4
- package/dist/esm-node/server/index.mjs +2 -1
- package/dist/esm-node/types/index.mjs +1 -0
- package/dist/types/cli/configPlugin.d.ts +1 -0
- package/dist/types/server/fileCache.d.ts +1 -0
- package/dist/types/types/index.d.ts +6 -0
- package/package.json +21 -21
- package/dist/types/cli/configPlugin.spec.d.ts +0 -1
- package/dist/types/cli/ssrPlugin.spec.d.ts +0 -1
- package/dist/types/server/fileCache.spec.d.ts +0 -1
- package/dist/types/server/staticMiddleware.spec.d.ts +0 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as __rspack_external_jiti from "jiti";
|
|
2
1
|
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
3
2
|
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
4
3
|
import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props";
|
|
@@ -12,21 +11,13 @@ import { encodeName } from "@module-federation/sdk";
|
|
|
12
11
|
import { PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
13
12
|
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
14
13
|
import logger from "../logger.mjs";
|
|
15
|
-
|
|
14
|
+
import { __webpack_require__ } from "../rslib-runtime.mjs";
|
|
15
|
+
import * as __rspack_external_jiti from "jiti";
|
|
16
|
+
__webpack_require__.add({
|
|
16
17
|
jiti: function(module) {
|
|
17
18
|
module.exports = __rspack_external_jiti;
|
|
18
19
|
}
|
|
19
|
-
};
|
|
20
|
-
var __webpack_module_cache__ = {};
|
|
21
|
-
function __webpack_require__(moduleId) {
|
|
22
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
23
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
24
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
25
|
-
exports: {}
|
|
26
|
-
};
|
|
27
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
28
|
-
return module.exports;
|
|
29
|
-
}
|
|
20
|
+
});
|
|
30
21
|
var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
31
22
|
var configPlugin_resolvePackageFile = function(packageName, esmRelativePath, cjsRelativePath) {
|
|
32
23
|
var packageEntry = require.resolve(packageName);
|
|
@@ -147,6 +138,14 @@ var configPlugin_patchMFConfig = function(mfConfig, isServer) {
|
|
|
147
138
|
mfConfig.dev = false;
|
|
148
139
|
return mfConfig;
|
|
149
140
|
};
|
|
141
|
+
var configPlugin_setDefaultOptimizationTarget = function(mfConfig, enableSSR, isServer) {
|
|
142
|
+
var autoOptimization = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : true;
|
|
143
|
+
var _mfConfig, _mfConfig_experiments, _mfConfig_experiments_optimization;
|
|
144
|
+
if (!autoOptimization) return;
|
|
145
|
+
(_mfConfig = mfConfig).experiments || (_mfConfig.experiments = {});
|
|
146
|
+
(_mfConfig_experiments = mfConfig.experiments).optimization || (_mfConfig_experiments.optimization = {});
|
|
147
|
+
null != (_mfConfig_experiments_optimization = mfConfig.experiments.optimization).target || (_mfConfig_experiments_optimization.target = enableSSR && isServer ? 'node' : 'web');
|
|
148
|
+
};
|
|
150
149
|
function patchIgnoreWarning(chain) {
|
|
151
150
|
var ignoreWarnings = chain.get('ignoreWarnings') || [];
|
|
152
151
|
var ignoredMsgs = [
|
|
@@ -213,7 +212,10 @@ function patchBundlerConfig(options) {
|
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
|
|
216
|
-
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length)
|
|
215
|
+
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
216
|
+
logger.info('optimization.usedExports is set to "global" to avoid tree shaking issues in micro frontend mode.');
|
|
217
|
+
chain.optimization.usedExports('global');
|
|
218
|
+
}
|
|
217
219
|
}
|
|
218
220
|
var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
|
|
219
221
|
return {
|
|
@@ -249,6 +251,7 @@ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
|
|
|
249
251
|
var isWeb = isWebTarget(target);
|
|
250
252
|
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
251
253
|
var targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
254
|
+
configPlugin_setDefaultOptimizationTarget(targetMFConfig, enableSSR, !isWeb, userConfig.originPluginOptions.autoOptimization);
|
|
252
255
|
configPlugin_patchMFConfig(targetMFConfig, !isWeb);
|
|
253
256
|
if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
|
|
254
257
|
var _targetMFConfig;
|
|
@@ -273,15 +276,17 @@ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
|
|
|
273
276
|
});
|
|
274
277
|
api.config(function() {
|
|
275
278
|
var _ref;
|
|
276
|
-
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source,
|
|
279
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_dev, _modernjsConfig_source, _modernjsConfig_dev1, _modernjsConfig_dev2;
|
|
277
280
|
var devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
278
281
|
var corsWarnMsgs = [
|
|
279
282
|
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
280
283
|
];
|
|
281
284
|
if ((void 0 === devServerConfig ? "undefined" : _type_of__(devServerConfig)) !== 'object' || !('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.');
|
|
282
285
|
var exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
283
|
-
var hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
286
|
+
var hasExposes = exposes && Array.isArray(exposes) ? exposes.length > 0 : Object.keys(null != exposes ? exposes : {}).length > 0;
|
|
287
|
+
var lazyCompilationDisabledByPlugin = hasExposes && (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.lazyCompilation) !== false;
|
|
284
288
|
if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
|
|
289
|
+
if (lazyCompilationDisabledByPlugin) logger.warn('Detected exposes in the Module Federation config. The Modern.js v3 Module Federation plugin will set dev.lazyCompilation to false for producer apps.');
|
|
285
290
|
var corsHeaders = hasExposes ? {
|
|
286
291
|
'Access-Control-Allow-Origin': '*',
|
|
287
292
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
@@ -302,7 +307,8 @@ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
|
|
|
302
307
|
enableAsyncEntry: null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true
|
|
303
308
|
},
|
|
304
309
|
dev: {
|
|
305
|
-
assetPrefix: (null == modernjsConfig ? void 0 : null == (
|
|
310
|
+
assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev1 = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev1.assetPrefix) ? modernjsConfig.dev.assetPrefix : 'auto',
|
|
311
|
+
lazyCompilation: hasExposes ? false : null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev2 = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev2.lazyCompilation
|
|
306
312
|
}
|
|
307
313
|
};
|
|
308
314
|
});
|
|
@@ -316,4 +322,5 @@ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
|
|
|
316
322
|
};
|
|
317
323
|
};
|
|
318
324
|
var configPlugin = configPlugin_moduleFederationConfigPlugin;
|
|
319
|
-
export
|
|
325
|
+
export default configPlugin;
|
|
326
|
+
export { addMyTypes2Ignored, configPlugin_getMFConfig as getMFConfig, configPlugin_moduleFederationConfigPlugin as moduleFederationConfigPlugin, configPlugin_patchMFConfig as patchMFConfig, configPlugin_setDefaultOptimizationTarget as setDefaultOptimizationTarget, isWebTarget, patchBundlerConfig, setEnv, skipByTarget };
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { ModuleFederationPlugin, TreeShakingSharedPlugin } from "@module-federat
|
|
|
5
5
|
import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
|
|
6
6
|
import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
|
|
7
7
|
import { isWebTarget } from "./utils.mjs";
|
|
8
|
-
import { createModuleFederationConfig } from "@module-federation/enhanced";
|
|
9
8
|
var cli_moduleFederationPlugin = function() {
|
|
10
9
|
var userConfig = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
11
10
|
var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
|
|
@@ -65,4 +64,6 @@ var cli_moduleFederationPlugin = function() {
|
|
|
65
64
|
};
|
|
66
65
|
};
|
|
67
66
|
var cli = cli_moduleFederationPlugin;
|
|
68
|
-
export { createModuleFederationConfig
|
|
67
|
+
export { createModuleFederationConfig } from "@module-federation/enhanced";
|
|
68
|
+
export default cli;
|
|
69
|
+
export { cli_moduleFederationPlugin as moduleFederationPlugin };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import node_fetch from "node-fetch";
|
|
2
1
|
var inject_node_fetch_injectNodeFetchPlugin = function() {
|
|
3
2
|
return {
|
|
4
3
|
name: 'inject-node-fetch-plugin',
|
|
5
4
|
beforeInit: function(args) {
|
|
6
|
-
if (!globalThis.fetch)
|
|
5
|
+
if (!globalThis.fetch) throw new Error('@module-federation/modern-js-v3 requires Node.js 18 or later.');
|
|
7
6
|
return args;
|
|
8
7
|
}
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
10
|
var inject_node_fetch = inject_node_fetch_injectNodeFetchPlugin;
|
|
12
|
-
export
|
|
11
|
+
export default inject_node_fetch;
|
|
@@ -286,4 +286,5 @@ var ssrPlugin_moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
286
286
|
};
|
|
287
287
|
};
|
|
288
288
|
var ssrPlugin = ssrPlugin_moduleFederationSSRPlugin;
|
|
289
|
-
export
|
|
289
|
+
export default ssrPlugin;
|
|
290
|
+
export { CHAIN_MF_PLUGIN_ID, setEnv, ssrPlugin_moduleFederationSSRPlugin as moduleFederationSSRPlugin };
|
package/dist/esm/cli/utils.mjs
CHANGED
|
@@ -37,4 +37,4 @@ var utils_skipByTarget = function(target) {
|
|
|
37
37
|
function isDev() {
|
|
38
38
|
return 'development' === process.env.NODE_ENV;
|
|
39
39
|
}
|
|
40
|
-
export { utils_getIPV4 as getIPV4,
|
|
40
|
+
export { isDev, utils_getIPV4 as getIPV4, utils_isWebTarget as isWebTarget, utils_skipByTarget as skipByTarget };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/esm/logger.mjs
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __webpack_modules__ = {};
|
|
2
|
+
var __webpack_module_cache__ = {};
|
|
3
|
+
function __webpack_require__(moduleId) {
|
|
4
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
5
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
6
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
7
|
+
exports: {}
|
|
8
|
+
};
|
|
9
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
10
|
+
return module.exports;
|
|
11
|
+
}
|
|
12
|
+
__webpack_require__.m = __webpack_modules__;
|
|
13
|
+
!function() {
|
|
14
|
+
__webpack_require__.add = function(modules) {
|
|
15
|
+
Object.assign(__webpack_require__.m, modules);
|
|
16
|
+
};
|
|
17
|
+
}();
|
|
18
|
+
export { __webpack_require__ };
|
|
@@ -2,7 +2,7 @@ import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _class_call_check__ } from "@swc/helpers/_/_class_call_check";
|
|
3
3
|
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import { access, lstat, readFile } from "fs/promises";
|
|
5
|
-
import {
|
|
5
|
+
import { SizeLimitedCache } from "@module-federation/bridge-react/size-limited-cache";
|
|
6
6
|
var fileCache_pathExists = function(filepath) {
|
|
7
7
|
return _(function() {
|
|
8
8
|
return _ts_generator__(this, function(_state) {
|
|
@@ -41,9 +41,10 @@ var fileCache_pathExists = function(filepath) {
|
|
|
41
41
|
var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
42
42
|
"use strict";
|
|
43
43
|
function FileCache() {
|
|
44
|
+
var maxSize = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 209715200;
|
|
44
45
|
_class_call_check__(this, FileCache);
|
|
45
|
-
this.cache = new
|
|
46
|
-
maxSize:
|
|
46
|
+
this.cache = new SizeLimitedCache({
|
|
47
|
+
maxSize: maxSize
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
var _proto = FileCache.prototype;
|
|
@@ -122,4 +123,4 @@ var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
|
122
123
|
return FileCache;
|
|
123
124
|
}();
|
|
124
125
|
var fileCache = new fileCache_FileCache();
|
|
125
|
-
export { fileCache_FileCache as FileCache
|
|
126
|
+
export { fileCache, fileCache_FileCache as FileCache };
|
package/dist/esm/types/index.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as __rspack_external_jiti from "jiti";
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
@@ -6,21 +5,13 @@ import { encodeName } from "@module-federation/sdk";
|
|
|
6
5
|
import { PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
7
6
|
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
8
7
|
import logger from "../logger.mjs";
|
|
9
|
-
|
|
8
|
+
import { __webpack_require__ } from "../rslib-runtime.mjs";
|
|
9
|
+
import * as __rspack_external_jiti from "jiti";
|
|
10
|
+
__webpack_require__.add({
|
|
10
11
|
jiti (module) {
|
|
11
12
|
module.exports = __rspack_external_jiti;
|
|
12
13
|
}
|
|
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
|
-
}
|
|
14
|
+
});
|
|
24
15
|
const defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
25
16
|
const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
|
|
26
17
|
const packageEntry = require.resolve(packageName);
|
|
@@ -116,6 +107,13 @@ const patchMFConfig = (mfConfig, isServer)=>{
|
|
|
116
107
|
mfConfig.dev = false;
|
|
117
108
|
return mfConfig;
|
|
118
109
|
};
|
|
110
|
+
const setDefaultOptimizationTarget = (mfConfig, enableSSR, isServer, autoOptimization = true)=>{
|
|
111
|
+
var _mfConfig, _mfConfig_experiments, _mfConfig_experiments_optimization;
|
|
112
|
+
if (!autoOptimization) return;
|
|
113
|
+
(_mfConfig = mfConfig).experiments || (_mfConfig.experiments = {});
|
|
114
|
+
(_mfConfig_experiments = mfConfig.experiments).optimization || (_mfConfig_experiments.optimization = {});
|
|
115
|
+
null != (_mfConfig_experiments_optimization = mfConfig.experiments.optimization).target || (_mfConfig_experiments_optimization.target = enableSSR && isServer ? 'node' : 'web');
|
|
116
|
+
};
|
|
119
117
|
function patchIgnoreWarning(chain) {
|
|
120
118
|
const ignoreWarnings = chain.get('ignoreWarnings') || [];
|
|
121
119
|
const ignoredMsgs = [
|
|
@@ -184,7 +182,10 @@ function patchBundlerConfig(options) {
|
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
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)
|
|
185
|
+
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
186
|
+
logger.info('optimization.usedExports is set to "global" to avoid tree shaking issues in micro frontend mode.');
|
|
187
|
+
chain.optimization.usedExports('global');
|
|
188
|
+
}
|
|
188
189
|
}
|
|
189
190
|
const moduleFederationConfigPlugin = (userConfig)=>({
|
|
190
191
|
name: '@modern-js/plugin-module-federation-config',
|
|
@@ -211,6 +212,7 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
211
212
|
const isWeb = isWebTarget(target);
|
|
212
213
|
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
213
214
|
const targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
215
|
+
setDefaultOptimizationTarget(targetMFConfig, enableSSR, !isWeb, userConfig.originPluginOptions.autoOptimization);
|
|
214
216
|
patchMFConfig(targetMFConfig, !isWeb);
|
|
215
217
|
if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
|
|
216
218
|
var _targetMFConfig;
|
|
@@ -235,15 +237,17 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
235
237
|
});
|
|
236
238
|
api.config(()=>{
|
|
237
239
|
var _ref;
|
|
238
|
-
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source,
|
|
240
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_dev, _modernjsConfig_source, _modernjsConfig_dev1, _modernjsConfig_dev2;
|
|
239
241
|
const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
240
242
|
const corsWarnMsgs = [
|
|
241
243
|
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
242
244
|
];
|
|
243
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.');
|
|
244
246
|
const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
245
|
-
const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
247
|
+
const hasExposes = exposes && Array.isArray(exposes) ? exposes.length > 0 : Object.keys(null != exposes ? exposes : {}).length > 0;
|
|
248
|
+
const lazyCompilationDisabledByPlugin = hasExposes && (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.lazyCompilation) !== false;
|
|
246
249
|
if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
|
|
250
|
+
if (lazyCompilationDisabledByPlugin) logger.warn('Detected exposes in the Module Federation config. The Modern.js v3 Module Federation plugin will set dev.lazyCompilation to false for producer apps.');
|
|
247
251
|
const corsHeaders = hasExposes ? {
|
|
248
252
|
'Access-Control-Allow-Origin': '*',
|
|
249
253
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
@@ -264,11 +268,13 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
264
268
|
enableAsyncEntry: null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true
|
|
265
269
|
},
|
|
266
270
|
dev: {
|
|
267
|
-
assetPrefix: (null == modernjsConfig ? void 0 : null == (
|
|
271
|
+
assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev1 = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev1.assetPrefix) ? modernjsConfig.dev.assetPrefix : 'auto',
|
|
272
|
+
lazyCompilation: hasExposes ? false : null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev2 = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev2.lazyCompilation
|
|
268
273
|
}
|
|
269
274
|
};
|
|
270
275
|
});
|
|
271
276
|
}
|
|
272
277
|
});
|
|
273
278
|
const configPlugin = moduleFederationConfigPlugin;
|
|
274
|
-
export
|
|
279
|
+
export default configPlugin;
|
|
280
|
+
export { addMyTypes2Ignored, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setDefaultOptimizationTarget, setEnv, skipByTarget };
|
|
@@ -2,7 +2,6 @@ import { ModuleFederationPlugin, TreeShakingSharedPlugin } from "@module-federat
|
|
|
2
2
|
import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
|
|
3
3
|
import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
|
|
4
4
|
import { isWebTarget } from "./utils.mjs";
|
|
5
|
-
import { createModuleFederationConfig } from "@module-federation/enhanced";
|
|
6
5
|
const moduleFederationPlugin = (userConfig = {})=>{
|
|
7
6
|
var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
|
|
8
7
|
const internalModernPluginOptions = {
|
|
@@ -55,4 +54,6 @@ const moduleFederationPlugin = (userConfig = {})=>{
|
|
|
55
54
|
};
|
|
56
55
|
};
|
|
57
56
|
const cli = moduleFederationPlugin;
|
|
58
|
-
export { createModuleFederationConfig
|
|
57
|
+
export { createModuleFederationConfig } from "@module-federation/enhanced";
|
|
58
|
+
export default cli;
|
|
59
|
+
export { moduleFederationPlugin };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import node_fetch from "node-fetch";
|
|
2
1
|
const injectNodeFetchPlugin = ()=>({
|
|
3
2
|
name: 'inject-node-fetch-plugin',
|
|
4
3
|
beforeInit (args) {
|
|
5
|
-
if (!globalThis.fetch)
|
|
4
|
+
if (!globalThis.fetch) throw new Error('@module-federation/modern-js-v3 requires Node.js 18 or later.');
|
|
6
5
|
return args;
|
|
7
6
|
}
|
|
8
7
|
});
|
|
9
8
|
const inject_node_fetch = injectNodeFetchPlugin;
|
|
10
|
-
export
|
|
9
|
+
export default inject_node_fetch;
|
|
@@ -245,4 +245,5 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
const ssrPlugin = moduleFederationSSRPlugin;
|
|
248
|
-
export
|
|
248
|
+
export default ssrPlugin;
|
|
249
|
+
export { CHAIN_MF_PLUGIN_ID, moduleFederationSSRPlugin, setEnv };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/esm-node/logger.mjs
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __webpack_modules__ = {};
|
|
2
|
+
var __webpack_module_cache__ = {};
|
|
3
|
+
function __webpack_require__(moduleId) {
|
|
4
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
5
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
6
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
7
|
+
exports: {}
|
|
8
|
+
};
|
|
9
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
10
|
+
return module.exports;
|
|
11
|
+
}
|
|
12
|
+
__webpack_require__.m = __webpack_modules__;
|
|
13
|
+
(()=>{
|
|
14
|
+
__webpack_require__.add = function(modules) {
|
|
15
|
+
Object.assign(__webpack_require__.m, modules);
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
export { __webpack_require__ };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, lstat, readFile } from "fs/promises";
|
|
2
|
-
import {
|
|
2
|
+
import { SizeLimitedCache } from "@module-federation/bridge-react/size-limited-cache";
|
|
3
3
|
const pathExists = async (filepath)=>{
|
|
4
4
|
try {
|
|
5
5
|
await access(filepath);
|
|
@@ -35,9 +35,9 @@ class FileCache {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
constructor(){
|
|
39
|
-
this.cache = new
|
|
40
|
-
maxSize
|
|
38
|
+
constructor(maxSize = 209715200){
|
|
39
|
+
this.cache = new SizeLimitedCache({
|
|
40
|
+
maxSize
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -8,6 +8,7 @@ export type ConfigType = Rspack.Configuration;
|
|
|
8
8
|
export declare function setEnv(enableSSR: boolean): void;
|
|
9
9
|
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
10
10
|
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
11
|
+
export declare const setDefaultOptimizationTarget: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, enableSSR: boolean, isServer: boolean, autoOptimization?: boolean) => void;
|
|
11
12
|
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
12
13
|
export declare function patchBundlerConfig(options: {
|
|
13
14
|
chain: BundlerChainConfig;
|
|
@@ -3,6 +3,12 @@ import type { StatsAssetResource } from '@module-federation/rsbuild-plugin/utils
|
|
|
3
3
|
export interface PluginOptions {
|
|
4
4
|
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
5
5
|
configPath?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Automatically set the federation optimization target from the Modern.js
|
|
8
|
+
* SSR and bundler target configuration.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
autoOptimization?: boolean;
|
|
6
12
|
ssr?: {
|
|
7
13
|
distOutputDir?: string;
|
|
8
14
|
} | boolean;
|