@module-federation/modern-js 0.0.0-next-20240712032032 → 0.0.0-next-20240715065227
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 +137 -0
- package/dist/cjs/cli/constant.js +28 -0
- package/dist/cjs/cli/index.js +50 -189
- package/dist/cjs/cli/ssrPlugin.js +160 -0
- package/dist/cjs/cli/utils.js +35 -48
- package/dist/cjs/cli/utils.spec.js +20 -14
- package/dist/cjs/ssr-runtime/plugin.js +3 -3
- package/dist/esm/cli/configPlugin.js +132 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +61 -199
- package/dist/esm/cli/ssrPlugin.js +152 -0
- package/dist/esm/cli/utils.js +57 -82
- package/dist/esm/cli/utils.spec.js +23 -17
- package/dist/esm/ssr-runtime/plugin.js +2 -2
- package/dist/esm-node/cli/configPlugin.js +101 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +50 -179
- package/dist/esm-node/cli/ssrPlugin.js +125 -0
- package/dist/esm-node/cli/utils.js +33 -45
- package/dist/esm-node/cli/utils.spec.js +21 -15
- package/dist/esm-node/ssr-runtime/plugin.js +2 -2
- package/dist/types/cli/configPlugin.d.ts +14 -0
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/ssrPlugin.d.ts +5 -0
- package/dist/types/cli/utils.d.ts +2 -37
- package/dist/types/ssr-runtime/plugin.d.ts +1 -1
- package/dist/types/types/index.d.ts +8 -2
- package/package.json +20 -7
|
@@ -0,0 +1,137 @@
|
|
|
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 configPlugin_exports = {};
|
|
30
|
+
__export(configPlugin_exports, {
|
|
31
|
+
default: () => configPlugin_default,
|
|
32
|
+
modifyBundlerConfig: () => modifyBundlerConfig,
|
|
33
|
+
moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
|
|
34
|
+
setEnv: () => setEnv
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(configPlugin_exports);
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_utils = require("./utils");
|
|
39
|
+
function setEnv(enableSSR) {
|
|
40
|
+
if (enableSSR) {
|
|
41
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
42
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function modifyBundlerConfig(options) {
|
|
46
|
+
const { mfConfig, config, isServer, modernjsConfig, bundlerType } = options;
|
|
47
|
+
(0, import_utils.patchMFConfig)(mfConfig, isServer);
|
|
48
|
+
(0, import_utils.patchBundlerConfig)({
|
|
49
|
+
bundlerConfig: config,
|
|
50
|
+
isServer,
|
|
51
|
+
modernjsConfig,
|
|
52
|
+
mfConfig
|
|
53
|
+
});
|
|
54
|
+
if (bundlerType === "webpack") {
|
|
55
|
+
config.ignoreWarnings = config.ignoreWarnings || [];
|
|
56
|
+
config.ignoreWarnings.push((warning) => {
|
|
57
|
+
if (warning.message.includes("external script")) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
65
|
+
name: "@modern-js/plugin-module-federation-config",
|
|
66
|
+
post: [
|
|
67
|
+
"@modern-js/plugin-module-federation"
|
|
68
|
+
],
|
|
69
|
+
setup: async ({ useConfigContext, useAppContext }) => {
|
|
70
|
+
console.log("config plugin");
|
|
71
|
+
const modernjsConfig = useConfigContext();
|
|
72
|
+
const mfConfig = await (0, import_utils.getMFConfig)(userConfig.originPluginOptions);
|
|
73
|
+
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
74
|
+
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
75
|
+
userConfig.ssrConfig = ssrConfig;
|
|
76
|
+
userConfig.csrConfig = csrConfig;
|
|
77
|
+
return {
|
|
78
|
+
config: async () => {
|
|
79
|
+
var _modernjsConfig_dev;
|
|
80
|
+
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
81
|
+
const ipv4 = (0, import_utils.getIPV4)();
|
|
82
|
+
return {
|
|
83
|
+
tools: {
|
|
84
|
+
rspack(config, { isServer }) {
|
|
85
|
+
var _config_output;
|
|
86
|
+
modifyBundlerConfig({
|
|
87
|
+
bundlerType,
|
|
88
|
+
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
89
|
+
config,
|
|
90
|
+
isServer,
|
|
91
|
+
// MFBundlerPlugin,
|
|
92
|
+
modernjsConfig
|
|
93
|
+
});
|
|
94
|
+
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
95
|
+
},
|
|
96
|
+
webpack(config, { isServer }) {
|
|
97
|
+
var _config_output;
|
|
98
|
+
modifyBundlerConfig({
|
|
99
|
+
bundlerType,
|
|
100
|
+
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
101
|
+
config,
|
|
102
|
+
isServer,
|
|
103
|
+
modernjsConfig
|
|
104
|
+
});
|
|
105
|
+
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
106
|
+
},
|
|
107
|
+
devServer: {
|
|
108
|
+
headers: {
|
|
109
|
+
"Access-Control-Allow-Origin": "*",
|
|
110
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
111
|
+
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
source: {
|
|
116
|
+
alias: {
|
|
117
|
+
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
118
|
+
},
|
|
119
|
+
define: {
|
|
120
|
+
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
dev: {
|
|
124
|
+
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
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
var configPlugin_default = moduleFederationConfigPlugin;
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
modifyBundlerConfig,
|
|
135
|
+
moduleFederationConfigPlugin,
|
|
136
|
+
setEnv
|
|
137
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constant_exports = {};
|
|
20
|
+
__export(constant_exports, {
|
|
21
|
+
isDev: () => isDev
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constant_exports);
|
|
24
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
isDev
|
|
28
|
+
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var cli_exports = {};
|
|
30
20
|
__export(cli_exports, {
|
|
@@ -33,195 +23,66 @@ __export(cli_exports, {
|
|
|
33
23
|
moduleFederationPlugin: () => moduleFederationPlugin
|
|
34
24
|
});
|
|
35
25
|
module.exports = __toCommonJS(cli_exports);
|
|
36
|
-
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_utils = require("@modern-js/utils");
|
|
38
26
|
var import_enhanced = require("@module-federation/enhanced");
|
|
39
27
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var import_manifest = require("./manifest");
|
|
43
|
-
var import_constant = require("../constant");
|
|
28
|
+
var import_configPlugin = require("./configPlugin");
|
|
29
|
+
var import_ssrPlugin = require("./ssrPlugin");
|
|
44
30
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const envConfig = (0, import_utils2.getTargetEnvConfig)(mfConfig, isServer);
|
|
70
|
-
if (isServer) {
|
|
71
|
-
var _config_plugins, _config_plugins1;
|
|
72
|
-
nodePlugin = new MFBundlerPlugin(envConfig);
|
|
73
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
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
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
var _config_output, _config_plugins3;
|
|
81
|
-
outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
82
|
-
browserPlugin = new MFBundlerPlugin(envConfig);
|
|
83
|
-
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
|
|
84
|
-
}
|
|
85
|
-
(0, import_utils2.patchWebpackConfig)({
|
|
86
|
-
bundlerConfig: config,
|
|
87
|
-
isServer,
|
|
88
|
-
modernjsConfig,
|
|
89
|
-
mfConfig: envConfig
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
const ipv4 = (0, import_utils2.getIPV4)();
|
|
93
|
-
return {
|
|
94
|
-
tools: {
|
|
95
|
-
rspack(config) {
|
|
96
|
-
if (enableSSR) {
|
|
97
|
-
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} not support ssr for rspack bundler yet!`);
|
|
98
|
-
}
|
|
99
|
-
modifyBundlerConfig(config, false);
|
|
100
|
-
},
|
|
101
|
-
webpack(config, { isServer }) {
|
|
102
|
-
var _modernjsConfig_source;
|
|
103
|
-
modifyBundlerConfig(config, isServer);
|
|
104
|
-
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
105
|
-
if (!enableAsyncEntry && mfConfig.async !== false) {
|
|
106
|
-
var _config_plugins;
|
|
107
|
-
const asyncBoundaryPluginOptions = typeof mfConfig.async === "object" ? mfConfig.async : {
|
|
108
|
-
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
109
|
-
excludeChunk: (chunk) => chunk.name === mfConfig.name
|
|
110
|
-
};
|
|
111
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
112
|
-
}
|
|
113
|
-
config.ignoreWarnings = config.ignoreWarnings || [];
|
|
114
|
-
config.ignoreWarnings.push((warning) => {
|
|
115
|
-
if (warning.message.includes("external script")) {
|
|
116
|
-
return true;
|
|
31
|
+
const moduleFederationPlugin = (userConfig = {}) => {
|
|
32
|
+
const internalModernPluginOptions = {
|
|
33
|
+
csrConfig: void 0,
|
|
34
|
+
ssrConfig: void 0,
|
|
35
|
+
browserPlugin: void 0,
|
|
36
|
+
nodePlugin: void 0,
|
|
37
|
+
distOutputDir: "",
|
|
38
|
+
originPluginOptions: userConfig
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
name: "@modern-js/plugin-module-federation",
|
|
42
|
+
setup: async ({ useConfigContext }) => {
|
|
43
|
+
console.log("main plugin");
|
|
44
|
+
const modernjsConfig = useConfigContext();
|
|
45
|
+
return {
|
|
46
|
+
config: async () => {
|
|
47
|
+
return {
|
|
48
|
+
tools: {
|
|
49
|
+
rspack(config, { isServer }) {
|
|
50
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
51
|
+
if (!isServer) {
|
|
52
|
+
var _config_plugins;
|
|
53
|
+
internalModernPluginOptions.browserPlugin = new import_rspack.ModuleFederationPlugin(browserPluginOptions);
|
|
54
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
117
55
|
}
|
|
118
|
-
return false;
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
devServer: {
|
|
122
|
-
headers: {
|
|
123
|
-
"Access-Control-Allow-Origin": "*",
|
|
124
|
-
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
125
|
-
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
|
126
56
|
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} else {
|
|
144
|
-
next();
|
|
145
|
-
}
|
|
146
|
-
} catch (err) {
|
|
147
|
-
if (process.env.FEDERATION_DEBUG) {
|
|
148
|
-
console.error(err);
|
|
149
|
-
}
|
|
150
|
-
next();
|
|
151
|
-
}
|
|
57
|
+
webpack(config, { isServer }) {
|
|
58
|
+
var _modernjsConfig_source;
|
|
59
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
60
|
+
if (!isServer) {
|
|
61
|
+
var _config_plugins;
|
|
62
|
+
internalModernPluginOptions.browserPlugin = new import_enhanced.ModuleFederationPlugin(browserPluginOptions);
|
|
63
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
64
|
+
}
|
|
65
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
66
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
67
|
+
var _config_plugins1;
|
|
68
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
69
|
+
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
70
|
+
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
71
|
+
};
|
|
72
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
152
73
|
}
|
|
153
|
-
]
|
|
154
|
-
},
|
|
155
|
-
bundlerChain(chain, { isServer }) {
|
|
156
|
-
if (isDev && !isServer) {
|
|
157
|
-
chain.externals({
|
|
158
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
159
|
-
});
|
|
160
74
|
}
|
|
161
75
|
}
|
|
162
|
-
},
|
|
163
|
-
source: {
|
|
164
|
-
alias: {
|
|
165
|
-
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
166
|
-
},
|
|
167
|
-
define: {
|
|
168
|
-
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
dev: {
|
|
172
|
-
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
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
},
|
|
176
|
-
modifyEntryImports({ entrypoint, imports }) {
|
|
177
|
-
if (!enableSSR || !isDev) {
|
|
178
|
-
return {
|
|
179
|
-
entrypoint,
|
|
180
|
-
imports
|
|
181
76
|
};
|
|
182
77
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
entrypoint,
|
|
193
|
-
imports
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
197
|
-
if (!enableSSR || !isDev) {
|
|
198
|
-
return {
|
|
199
|
-
entrypoint,
|
|
200
|
-
plugins
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
plugins.unshift({
|
|
204
|
-
name: SSR_PLUGIN_IDENTIFIER,
|
|
205
|
-
options: JSON.stringify({})
|
|
206
|
-
});
|
|
207
|
-
return {
|
|
208
|
-
entrypoint,
|
|
209
|
-
plugins
|
|
210
|
-
};
|
|
211
|
-
},
|
|
212
|
-
afterBuild: () => {
|
|
213
|
-
if (enableSSR) {
|
|
214
|
-
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, outputDir);
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
afterDev: () => {
|
|
218
|
-
if (enableSSR) {
|
|
219
|
-
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, outputDir);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
});
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
usePlugins: [
|
|
81
|
+
(0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
|
|
82
|
+
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
};
|
|
225
86
|
var cli_default = moduleFederationPlugin;
|
|
226
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
227
88
|
0 && (module.exports = {
|
|
@@ -0,0 +1,160 @@
|
|
|
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 ssrPlugin_exports = {};
|
|
30
|
+
__export(ssrPlugin_exports, {
|
|
31
|
+
default: () => ssrPlugin_default,
|
|
32
|
+
moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
|
|
33
|
+
setEnv: () => setEnv
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(ssrPlugin_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_enhanced = require("@module-federation/enhanced");
|
|
39
|
+
var import_node = require("@module-federation/node");
|
|
40
|
+
var import_manifest = require("./manifest");
|
|
41
|
+
var import_constant = require("../constant");
|
|
42
|
+
var import_constant2 = require("./constant");
|
|
43
|
+
function setEnv() {
|
|
44
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
45
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
46
|
+
}
|
|
47
|
+
const moduleFederationSSRPlugin = (userConfig) => ({
|
|
48
|
+
name: "@modern-js/plugin-module-federation-ssr",
|
|
49
|
+
pre: [
|
|
50
|
+
"@modern-js/plugin-module-federation-config",
|
|
51
|
+
"@modern-js/plugin-module-federation"
|
|
52
|
+
],
|
|
53
|
+
setup: async ({ useConfigContext }) => {
|
|
54
|
+
var _modernjsConfig_server;
|
|
55
|
+
console.log("ssr plugin");
|
|
56
|
+
const modernjsConfig = useConfigContext();
|
|
57
|
+
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
58
|
+
if (!enableSSR) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
setEnv();
|
|
62
|
+
return {
|
|
63
|
+
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
64
|
+
if (!import_constant2.isDev) {
|
|
65
|
+
return {
|
|
66
|
+
entrypoint,
|
|
67
|
+
plugins
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
plugins.push({
|
|
71
|
+
name: "mfSSR",
|
|
72
|
+
path: "@module-federation/modern-js/ssr-runtime",
|
|
73
|
+
config: {}
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
entrypoint,
|
|
77
|
+
plugins
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
config: async () => {
|
|
81
|
+
return {
|
|
82
|
+
tools: {
|
|
83
|
+
rspack(config, { isServer }) {
|
|
84
|
+
if (isServer) {
|
|
85
|
+
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} Not support rspack ssr mode yet !`);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
webpack(config, { isServer }) {
|
|
89
|
+
if (isServer) {
|
|
90
|
+
var _config_plugins, _config_plugins1;
|
|
91
|
+
if (!userConfig.nodePlugin) {
|
|
92
|
+
userConfig.nodePlugin = new import_enhanced.ModuleFederationPlugin(userConfig.ssrConfig);
|
|
93
|
+
}
|
|
94
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
95
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.StreamingTargetPlugin(userConfig.nodePlugin));
|
|
96
|
+
if (import_constant2.isDev) {
|
|
97
|
+
var _config_plugins2;
|
|
98
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new import_node.EntryChunkTrackerPlugin());
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
var _config_output;
|
|
102
|
+
userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
devServer: {
|
|
106
|
+
before: [
|
|
107
|
+
(req, res, next) => {
|
|
108
|
+
if (!enableSSR) {
|
|
109
|
+
next();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
var _req_url, _req_url1, _req_url2;
|
|
114
|
+
const SERVER_PREFIX = `/${import_constant.MODERN_JS_SERVER_DIR}`;
|
|
115
|
+
if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
|
|
116
|
+
const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
|
|
117
|
+
import_utils.fs.statSync(filepath);
|
|
118
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
119
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
120
|
+
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
|
|
121
|
+
import_utils.fs.createReadStream(filepath).pipe(res);
|
|
122
|
+
} else {
|
|
123
|
+
next();
|
|
124
|
+
}
|
|
125
|
+
} catch (err) {
|
|
126
|
+
if (process.env.FEDERATION_DEBUG) {
|
|
127
|
+
console.error(err);
|
|
128
|
+
}
|
|
129
|
+
next();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
bundlerChain(chain, { isServer }) {
|
|
135
|
+
if (import_constant2.isDev && !isServer) {
|
|
136
|
+
chain.externals({
|
|
137
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
afterBuild: () => {
|
|
145
|
+
const { nodePlugin, browserPlugin, distOutputDir } = userConfig;
|
|
146
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
147
|
+
},
|
|
148
|
+
afterDev: () => {
|
|
149
|
+
const { nodePlugin, browserPlugin, distOutputDir } = userConfig;
|
|
150
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
156
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
+
0 && (module.exports = {
|
|
158
|
+
moduleFederationSSRPlugin,
|
|
159
|
+
setEnv
|
|
160
|
+
});
|