@module-federation/modern-js 0.0.0-next-20240521123600 → 0.0.0-next-20240521125425
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/index.js +10 -6
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
- package/dist/cjs/cli/utils.js +15 -7
- package/dist/esm/cli/index.js +12 -8
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
- package/dist/esm/cli/utils.js +15 -7
- package/dist/esm-node/cli/index.js +11 -7
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
- package/dist/esm-node/cli/utils.js +15 -7
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
- package/package.json +6 -5
package/dist/cjs/cli/index.js
CHANGED
|
@@ -52,15 +52,15 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
52
52
|
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
53
53
|
const mfConfig = await (0, import_utils2.getMFConfig)(userConfig);
|
|
54
54
|
let outputDir = "";
|
|
55
|
-
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
56
|
-
const WebpackPluginConstructor = userConfig.webpackPluginImplementation || import_enhanced.ModuleFederationPlugin;
|
|
57
|
-
const RspackPluginConstructor = userConfig.webpackPluginImplementation || import_rspack.ModuleFederationPlugin;
|
|
58
|
-
const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
59
55
|
let browserPlugin;
|
|
60
56
|
let nodePlugin;
|
|
61
57
|
return {
|
|
62
58
|
config: () => {
|
|
63
59
|
var _modernjsConfig_dev;
|
|
60
|
+
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
61
|
+
const WebpackPluginConstructor = userConfig.webpackPluginImplementation || import_enhanced.ModuleFederationPlugin;
|
|
62
|
+
const RspackPluginConstructor = userConfig.rspackPluginImplementation || import_rspack.ModuleFederationPlugin;
|
|
63
|
+
const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
64
64
|
if (enableSSR) {
|
|
65
65
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
66
66
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -72,11 +72,15 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
72
72
|
nodePlugin = new MFBundlerPlugin(envConfig);
|
|
73
73
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
74
74
|
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.StreamingTargetPlugin(envConfig));
|
|
75
|
+
if (isDev) {
|
|
76
|
+
var _config_plugins2;
|
|
77
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new import_node.EntryChunkTrackerPlugin());
|
|
78
|
+
}
|
|
75
79
|
} else {
|
|
76
|
-
var _config_output,
|
|
80
|
+
var _config_output, _config_plugins3;
|
|
77
81
|
outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
78
82
|
browserPlugin = new MFBundlerPlugin(envConfig);
|
|
79
|
-
(
|
|
83
|
+
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
|
|
80
84
|
}
|
|
81
85
|
(0, import_utils2.patchWebpackConfig)({
|
|
82
86
|
bundlerConfig: config,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var inject_node_fetch_exports = {};
|
|
30
|
+
__export(inject_node_fetch_exports, {
|
|
31
|
+
default: () => inject_node_fetch_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(inject_node_fetch_exports);
|
|
34
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
35
|
+
const injectNodeFetchPlugin = () => ({
|
|
36
|
+
name: "inject-node-fetch-plugin",
|
|
37
|
+
beforeInit(args) {
|
|
38
|
+
if (!globalThis.fetch) {
|
|
39
|
+
globalThis.fetch = import_node_fetch.default;
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(utils_exports, {
|
|
|
34
34
|
patchWebpackConfig: () => patchWebpackConfig
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(utils_exports);
|
|
37
|
+
var import_sdk = require("@module-federation/sdk");
|
|
37
38
|
var import_path = __toESM(require("path"));
|
|
38
39
|
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
39
40
|
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
@@ -51,14 +52,21 @@ const patchMFConfig = (mfConfig, isServer) => {
|
|
|
51
52
|
const runtimePlugins = [
|
|
52
53
|
...mfConfig.runtimePlugins || []
|
|
53
54
|
];
|
|
54
|
-
const
|
|
55
|
-
if (!runtimePlugins.includes(
|
|
56
|
-
runtimePlugins.push(
|
|
55
|
+
const sharedStrategyRuntimePluginPath = import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
|
|
56
|
+
if (!runtimePlugins.includes(sharedStrategyRuntimePluginPath)) {
|
|
57
|
+
runtimePlugins.push(sharedStrategyRuntimePluginPath);
|
|
57
58
|
}
|
|
58
59
|
if (isServer) {
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
|
|
60
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
61
|
+
if (isDev) {
|
|
62
|
+
const nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
|
|
63
|
+
if (!runtimePlugins.includes(nodeHmrPluginPath)) {
|
|
64
|
+
runtimePlugins.push(nodeHmrPluginPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const injectNodeFetchRuntimePluginPath = import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
|
|
68
|
+
if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
|
|
69
|
+
runtimePlugins.push(injectNodeFetchRuntimePluginPath);
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
if (typeof mfConfig.async === "undefined") {
|
|
@@ -112,7 +120,7 @@ function patchWebpackConfig(options) {
|
|
|
112
120
|
const uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
|
|
113
121
|
const chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
|
|
114
122
|
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
115
|
-
const suffix =
|
|
123
|
+
const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
|
|
116
124
|
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
117
125
|
}
|
|
118
126
|
}
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "path";
|
|
|
4
4
|
import { fs } from "@modern-js/utils";
|
|
5
5
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
6
6
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
|
-
import { StreamingTargetPlugin } from "@module-federation/node";
|
|
7
|
+
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
8
8
|
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
|
|
9
9
|
import { updateStatsAndManifest } from "./manifest";
|
|
10
10
|
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
@@ -16,7 +16,7 @@ var moduleFederationPlugin = function() {
|
|
|
16
16
|
name: "@modern-js/plugin-module-federation",
|
|
17
17
|
setup: function() {
|
|
18
18
|
var _ref = _async_to_generator(function(param) {
|
|
19
|
-
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR, mfConfig, outputDir,
|
|
19
|
+
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR, mfConfig, outputDir, browserPlugin, nodePlugin;
|
|
20
20
|
return _ts_generator(this, function(_state) {
|
|
21
21
|
switch (_state.label) {
|
|
22
22
|
case 0:
|
|
@@ -30,15 +30,15 @@ var moduleFederationPlugin = function() {
|
|
|
30
30
|
case 1:
|
|
31
31
|
mfConfig = _state.sent();
|
|
32
32
|
outputDir = "";
|
|
33
|
-
bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
34
|
-
WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
|
|
35
|
-
RspackPluginConstructor = userConfig.webpackPluginImplementation || RspackModuleFederationPlugin;
|
|
36
|
-
MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
37
33
|
return [
|
|
38
34
|
2,
|
|
39
35
|
{
|
|
40
36
|
config: function() {
|
|
41
37
|
var _modernjsConfig_dev;
|
|
38
|
+
var bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
39
|
+
var WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
|
|
40
|
+
var RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
|
|
41
|
+
var MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
42
42
|
if (enableSSR) {
|
|
43
43
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
44
44
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -50,11 +50,15 @@ var moduleFederationPlugin = function() {
|
|
|
50
50
|
nodePlugin = new MFBundlerPlugin(envConfig);
|
|
51
51
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
52
52
|
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
|
|
53
|
+
if (isDev) {
|
|
54
|
+
var _config_plugins2;
|
|
55
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
|
|
56
|
+
}
|
|
53
57
|
} else {
|
|
54
|
-
var _config_output,
|
|
58
|
+
var _config_output, _config_plugins3;
|
|
55
59
|
outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
56
60
|
browserPlugin = new MFBundlerPlugin(envConfig);
|
|
57
|
-
(
|
|
61
|
+
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
|
|
58
62
|
}
|
|
59
63
|
patchWebpackConfig({
|
|
60
64
|
bundlerConfig: config,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import nodeFetch from "node-fetch";
|
|
2
|
+
var injectNodeFetchPlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: "inject-node-fetch-plugin",
|
|
5
|
+
beforeInit: function beforeInit(args) {
|
|
6
|
+
if (!globalThis.fetch) {
|
|
7
|
+
globalThis.fetch = nodeFetch;
|
|
8
|
+
}
|
|
9
|
+
return args;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
14
|
+
export {
|
|
15
|
+
inject_node_fetch_default as default
|
|
16
|
+
};
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
|
+
import { encodeName } from "@module-federation/sdk";
|
|
6
7
|
import path from "path";
|
|
7
8
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
8
9
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
@@ -45,14 +46,21 @@ var getMFConfig = function() {
|
|
|
45
46
|
}();
|
|
46
47
|
var patchMFConfig = function(mfConfig, isServer) {
|
|
47
48
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
48
|
-
var
|
|
49
|
-
if (!runtimePlugins.includes(
|
|
50
|
-
runtimePlugins.push(
|
|
49
|
+
var sharedStrategyRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
|
|
50
|
+
if (!runtimePlugins.includes(sharedStrategyRuntimePluginPath)) {
|
|
51
|
+
runtimePlugins.push(sharedStrategyRuntimePluginPath);
|
|
51
52
|
}
|
|
52
53
|
if (isServer) {
|
|
53
|
-
var
|
|
54
|
-
if (
|
|
55
|
-
|
|
54
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
55
|
+
if (isDev) {
|
|
56
|
+
var nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
|
|
57
|
+
if (!runtimePlugins.includes(nodeHmrPluginPath)) {
|
|
58
|
+
runtimePlugins.push(nodeHmrPluginPath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var injectNodeFetchRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
|
|
62
|
+
if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
|
|
63
|
+
runtimePlugins.push(injectNodeFetchRuntimePluginPath);
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
66
|
if (typeof mfConfig.async === "undefined") {
|
|
@@ -102,7 +110,7 @@ function patchWebpackConfig(options) {
|
|
|
102
110
|
var uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
|
|
103
111
|
var chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
|
|
104
112
|
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
105
|
-
var suffix = "-[chunkhash].js";
|
|
113
|
+
var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
|
|
106
114
|
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
107
115
|
}
|
|
108
116
|
}
|
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
3
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
4
4
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
|
-
import { StreamingTargetPlugin } from "@module-federation/node";
|
|
5
|
+
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
6
6
|
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
|
|
7
7
|
import { updateStatsAndManifest } from "./manifest";
|
|
8
8
|
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
@@ -16,15 +16,15 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
16
16
|
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
17
17
|
const mfConfig = await getMFConfig(userConfig);
|
|
18
18
|
let outputDir = "";
|
|
19
|
-
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
20
|
-
const WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
|
|
21
|
-
const RspackPluginConstructor = userConfig.webpackPluginImplementation || RspackModuleFederationPlugin;
|
|
22
|
-
const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
23
19
|
let browserPlugin;
|
|
24
20
|
let nodePlugin;
|
|
25
21
|
return {
|
|
26
22
|
config: () => {
|
|
27
23
|
var _modernjsConfig_dev;
|
|
24
|
+
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
25
|
+
const WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
|
|
26
|
+
const RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
|
|
27
|
+
const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
28
28
|
if (enableSSR) {
|
|
29
29
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
30
30
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -36,11 +36,15 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
36
36
|
nodePlugin = new MFBundlerPlugin(envConfig);
|
|
37
37
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
38
38
|
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
|
|
39
|
+
if (isDev) {
|
|
40
|
+
var _config_plugins2;
|
|
41
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
|
|
42
|
+
}
|
|
39
43
|
} else {
|
|
40
|
-
var _config_output,
|
|
44
|
+
var _config_output, _config_plugins3;
|
|
41
45
|
outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
42
46
|
browserPlugin = new MFBundlerPlugin(envConfig);
|
|
43
|
-
(
|
|
47
|
+
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
|
|
44
48
|
}
|
|
45
49
|
patchWebpackConfig({
|
|
46
50
|
bundlerConfig: config,
|
|
@@ -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
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { encodeName } from "@module-federation/sdk";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
3
4
|
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
@@ -15,14 +16,21 @@ const patchMFConfig = (mfConfig, isServer) => {
|
|
|
15
16
|
const runtimePlugins = [
|
|
16
17
|
...mfConfig.runtimePlugins || []
|
|
17
18
|
];
|
|
18
|
-
const
|
|
19
|
-
if (!runtimePlugins.includes(
|
|
20
|
-
runtimePlugins.push(
|
|
19
|
+
const sharedStrategyRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
|
|
20
|
+
if (!runtimePlugins.includes(sharedStrategyRuntimePluginPath)) {
|
|
21
|
+
runtimePlugins.push(sharedStrategyRuntimePluginPath);
|
|
21
22
|
}
|
|
22
23
|
if (isServer) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
25
|
+
if (isDev) {
|
|
26
|
+
const nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
|
|
27
|
+
if (!runtimePlugins.includes(nodeHmrPluginPath)) {
|
|
28
|
+
runtimePlugins.push(nodeHmrPluginPath);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const injectNodeFetchRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
|
|
32
|
+
if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
|
|
33
|
+
runtimePlugins.push(injectNodeFetchRuntimePluginPath);
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
if (typeof mfConfig.async === "undefined") {
|
|
@@ -76,7 +84,7 @@ function patchWebpackConfig(options) {
|
|
|
76
84
|
const uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
|
|
77
85
|
const chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
|
|
78
86
|
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
79
|
-
const suffix =
|
|
87
|
+
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
|
|
80
88
|
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
81
89
|
}
|
|
82
90
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240521125425",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"@swc/helpers": "0.5.3",
|
|
46
46
|
"@modern-js/utils": "^2.49.2",
|
|
47
47
|
"@modern-js/node-bundle-require": "^2.49.2",
|
|
48
|
-
"
|
|
49
|
-
"@module-federation/
|
|
50
|
-
"@module-federation/
|
|
48
|
+
"node-fetch": "~3.3.0",
|
|
49
|
+
"@module-federation/sdk": "0.0.0-next-20240521125425",
|
|
50
|
+
"@module-federation/enhanced": "0.0.0-next-20240521125425",
|
|
51
|
+
"@module-federation/node": "0.0.0-next-20240521125425"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@modern-js/app-tools": "^2.49.2",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"@modern-js/runtime": "^2.49.2",
|
|
56
57
|
"@modern-js/module-tools": "^2.35.0",
|
|
57
58
|
"@modern-js/tsconfig": "^2.35.0",
|
|
58
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
59
|
+
"@module-federation/manifest": "0.0.0-next-20240521125425"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"react": ">=17",
|