@module-federation/rsbuild-plugin 2.0.0 → 2.0.1
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/README.md +8 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +429 -0
- package/dist/cli/index.mjs +360 -0
- package/dist/constant.d.ts +1 -0
- package/dist/constant.js +48 -35
- package/dist/constant.mjs +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +86 -528
- package/dist/index.mjs +5 -470
- package/dist/logger.js +60 -0
- package/dist/logger.mjs +10 -0
- package/dist/utils/addDataFetchExposes.js +126 -0
- package/dist/utils/addDataFetchExposes.mjs +65 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.js +99 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.mjs +53 -0
- package/dist/utils/index.js +109 -0
- package/dist/utils/index.mjs +31 -0
- package/dist/utils/manifest.js +113 -0
- package/dist/utils/manifest.mjs +50 -0
- package/dist/utils/ssr.js +230 -0
- package/dist/utils/ssr.mjs +152 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +86 -291
- package/dist/utils.mjs +5 -222
- package/package.json +4 -4
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/compat_get_default_export
|
|
14
|
+
(() => {
|
|
15
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
16
|
+
__webpack_require__.n = (module) => {
|
|
17
|
+
var getter = module && module.__esModule ?
|
|
18
|
+
() => (module['default']) :
|
|
19
|
+
() => (module);
|
|
20
|
+
__webpack_require__.d(getter, { a: getter });
|
|
21
|
+
return getter;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
})();
|
|
25
|
+
// webpack/runtime/define_property_getters
|
|
26
|
+
(() => {
|
|
27
|
+
__webpack_require__.d = (exports, definition) => {
|
|
28
|
+
for(var key in definition) {
|
|
29
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
30
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
// webpack/runtime/has_own_property
|
|
36
|
+
(() => {
|
|
37
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
38
|
+
})();
|
|
39
|
+
// webpack/runtime/make_namespace_object
|
|
40
|
+
(() => {
|
|
41
|
+
// define __esModule on exports
|
|
42
|
+
__webpack_require__.r = (exports) => {
|
|
43
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
44
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
45
|
+
}
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
/************************************************************************/
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
// ESM COMPAT FLAG
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
|
|
54
|
+
// EXPORTS
|
|
55
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
56
|
+
patchNodeConfig: () => (/* binding */ patchNodeConfig),
|
|
57
|
+
createSSRREnvConfig: () => (/* binding */ createSSRREnvConfig),
|
|
58
|
+
setSSREnv: () => (/* binding */ setSSREnv),
|
|
59
|
+
patchNodeMFConfig: () => (/* binding */ patchNodeMFConfig),
|
|
60
|
+
SSR_ENV_NAME: () => (/* binding */ SSR_ENV_NAME),
|
|
61
|
+
patchToolsTspack: () => (/* binding */ patchToolsTspack),
|
|
62
|
+
patchSSRRspackConfig: () => (/* binding */ patchSSRRspackConfig),
|
|
63
|
+
SSR_DIR: () => (/* binding */ SSR_DIR),
|
|
64
|
+
ENV_NAME: () => (/* binding */ ENV_NAME),
|
|
65
|
+
createSSRMFConfig: () => (/* binding */ createSSRMFConfig)
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
;// CONCATENATED MODULE: external "path"
|
|
69
|
+
const external_path_namespaceObject = require("path");
|
|
70
|
+
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
|
|
71
|
+
;// CONCATENATED MODULE: external "node:module"
|
|
72
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
73
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
74
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
75
|
+
;// CONCATENATED MODULE: external "../constant.js"
|
|
76
|
+
const external_constant_js_namespaceObject = require("../constant.js");
|
|
77
|
+
;// CONCATENATED MODULE: ./src/utils/ssr.ts
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const ssr_require = (0,external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
83
|
+
const resolve = ssr_require.resolve;
|
|
84
|
+
const SSR_DIR = 'ssr';
|
|
85
|
+
const SSR_ENV_NAME = 'mf-ssr';
|
|
86
|
+
const ENV_NAME = 'mf';
|
|
87
|
+
function setSSREnv() {
|
|
88
|
+
process.env['MF_SSR_PRJ'] = 'true';
|
|
89
|
+
}
|
|
90
|
+
const isDev = ()=>{
|
|
91
|
+
return process.env['NODE_ENV'] === 'development';
|
|
92
|
+
};
|
|
93
|
+
function patchNodeConfig(config, mfConfig) {
|
|
94
|
+
var _config_output;
|
|
95
|
+
config.output ||= {};
|
|
96
|
+
config.target = 'async-node';
|
|
97
|
+
// @module-federation/node/universe-entry-chunk-tracker-plugin only export cjs
|
|
98
|
+
const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
99
|
+
config.plugins ||= [];
|
|
100
|
+
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
101
|
+
const uniqueName = mfConfig.name || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.uniqueName);
|
|
102
|
+
const chunkFileName = config.output.chunkFilename;
|
|
103
|
+
if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
104
|
+
const suffix = `${(0,sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
|
|
105
|
+
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
|
|
109
|
+
config.output ||= {};
|
|
110
|
+
if (modifyPublicPath) {
|
|
111
|
+
var _config_output;
|
|
112
|
+
if (typeof ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath) !== 'string') {
|
|
113
|
+
throw new Error('publicPath must be string!');
|
|
114
|
+
}
|
|
115
|
+
const publicPath = config.output.publicPath;
|
|
116
|
+
if (publicPath === 'auto') {
|
|
117
|
+
throw new Error('publicPath can not be "auto"!');
|
|
118
|
+
}
|
|
119
|
+
const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
|
|
120
|
+
config.output.publicPath = publicPathWithSSRDir;
|
|
121
|
+
}
|
|
122
|
+
if (callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSPRESS && resetEntry) {
|
|
123
|
+
// set virtue entry, only need mf entry
|
|
124
|
+
config.entry = 'data:application/node;base64,';
|
|
125
|
+
}
|
|
126
|
+
patchNodeConfig(config, mfConfig);
|
|
127
|
+
return config;
|
|
128
|
+
}
|
|
129
|
+
function patchToolsTspack(envConfig, fn) {
|
|
130
|
+
var _envConfig_tools;
|
|
131
|
+
const rspackArr = [];
|
|
132
|
+
if ((_envConfig_tools = envConfig.tools) === null || _envConfig_tools === void 0 ? void 0 : _envConfig_tools.rspack) {
|
|
133
|
+
var _envConfig_tools1, _envConfig_tools2;
|
|
134
|
+
if (Array.isArray((_envConfig_tools1 = envConfig.tools) === null || _envConfig_tools1 === void 0 ? void 0 : _envConfig_tools1.rspack)) {
|
|
135
|
+
var _envConfig_tools3;
|
|
136
|
+
rspackArr.push(...(_envConfig_tools3 = envConfig.tools) === null || _envConfig_tools3 === void 0 ? void 0 : _envConfig_tools3.rspack);
|
|
137
|
+
} else if (typeof ((_envConfig_tools2 = envConfig.tools) === null || _envConfig_tools2 === void 0 ? void 0 : _envConfig_tools2.rspack) === 'function') {
|
|
138
|
+
var _envConfig_tools4;
|
|
139
|
+
rspackArr.push((_envConfig_tools4 = envConfig.tools) === null || _envConfig_tools4 === void 0 ? void 0 : _envConfig_tools4.rspack);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
envConfig.tools ||= {};
|
|
143
|
+
envConfig.tools.rspack = [
|
|
144
|
+
...rspackArr,
|
|
145
|
+
fn
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
|
|
149
|
+
var _envConfig_tools, _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
|
|
150
|
+
const rspackArr = [];
|
|
151
|
+
if ((_envConfig_tools = envConfig.tools) === null || _envConfig_tools === void 0 ? void 0 : _envConfig_tools.rspack) {
|
|
152
|
+
var _envConfig_tools1, _envConfig_tools2;
|
|
153
|
+
if (Array.isArray((_envConfig_tools1 = envConfig.tools) === null || _envConfig_tools1 === void 0 ? void 0 : _envConfig_tools1.rspack)) {
|
|
154
|
+
var _envConfig_tools3;
|
|
155
|
+
rspackArr.push(...(_envConfig_tools3 = envConfig.tools) === null || _envConfig_tools3 === void 0 ? void 0 : _envConfig_tools3.rspack);
|
|
156
|
+
} else if (typeof ((_envConfig_tools2 = envConfig.tools) === null || _envConfig_tools2 === void 0 ? void 0 : _envConfig_tools2.rspack) === 'function') {
|
|
157
|
+
var _envConfig_tools4;
|
|
158
|
+
rspackArr.push((_envConfig_tools4 = envConfig.tools) === null || _envConfig_tools4 === void 0 ? void 0 : _envConfig_tools4.rspack);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const ssrEnvConfig = {
|
|
162
|
+
...envConfig
|
|
163
|
+
};
|
|
164
|
+
patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
|
|
165
|
+
if (environment.name !== SSR_ENV_NAME) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
|
|
169
|
+
});
|
|
170
|
+
ssrEnvConfig.output = {
|
|
171
|
+
...ssrEnvConfig.output,
|
|
172
|
+
// https://rsbuild.rs/config/output/target#other-targets
|
|
173
|
+
// Rsbuild not support all rspack targets, so modify to async-node in modifyRspackConfig
|
|
174
|
+
target: 'node',
|
|
175
|
+
distPath: {
|
|
176
|
+
...(_ssrEnvConfig_output = ssrEnvConfig.output) === null || _ssrEnvConfig_output === void 0 ? void 0 : _ssrEnvConfig_output.distPath,
|
|
177
|
+
root: external_path_default().join(((_ssrEnvConfig_output1 = ssrEnvConfig.output) === null || _ssrEnvConfig_output1 === void 0 ? void 0 : (_ssrEnvConfig_output_distPath = _ssrEnvConfig_output1.distPath) === null || _ssrEnvConfig_output_distPath === void 0 ? void 0 : _ssrEnvConfig_output_distPath.root) || ((_rsbuildConfig_output = rsbuildConfig.output) === null || _rsbuildConfig_output === void 0 ? void 0 : (_rsbuildConfig_output_distPath = _rsbuildConfig_output.distPath) === null || _rsbuildConfig_output_distPath === void 0 ? void 0 : _rsbuildConfig_output_distPath.root) || '', ssrDir)
|
|
178
|
+
},
|
|
179
|
+
emitAssets: true
|
|
180
|
+
};
|
|
181
|
+
return ssrEnvConfig;
|
|
182
|
+
}
|
|
183
|
+
function patchNodeMFConfig(mfConfig) {
|
|
184
|
+
var _mfConfig_library;
|
|
185
|
+
if (mfConfig.remotes) {
|
|
186
|
+
mfConfig.remoteType = 'script';
|
|
187
|
+
}
|
|
188
|
+
mfConfig.exposes = {
|
|
189
|
+
...mfConfig.exposes
|
|
190
|
+
};
|
|
191
|
+
mfConfig.library = {
|
|
192
|
+
...mfConfig.library,
|
|
193
|
+
name: mfConfig.name,
|
|
194
|
+
type: ((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
|
|
195
|
+
};
|
|
196
|
+
mfConfig.runtimePlugins = [
|
|
197
|
+
...mfConfig.runtimePlugins || []
|
|
198
|
+
];
|
|
199
|
+
mfConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
|
|
200
|
+
if (isDev()) {
|
|
201
|
+
mfConfig.runtimePlugins.push(// @ts-ignore
|
|
202
|
+
resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function createSSRMFConfig(mfConfig) {
|
|
206
|
+
const ssrMFConfig = {
|
|
207
|
+
...mfConfig
|
|
208
|
+
};
|
|
209
|
+
patchNodeMFConfig(ssrMFConfig);
|
|
210
|
+
ssrMFConfig.dts = false;
|
|
211
|
+
ssrMFConfig.dev = false;
|
|
212
|
+
return ssrMFConfig;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
exports.ENV_NAME = __webpack_exports__.ENV_NAME;
|
|
216
|
+
exports.SSR_DIR = __webpack_exports__.SSR_DIR;
|
|
217
|
+
exports.SSR_ENV_NAME = __webpack_exports__.SSR_ENV_NAME;
|
|
218
|
+
exports.createSSRMFConfig = __webpack_exports__.createSSRMFConfig;
|
|
219
|
+
exports.createSSRREnvConfig = __webpack_exports__.createSSRREnvConfig;
|
|
220
|
+
exports.patchNodeConfig = __webpack_exports__.patchNodeConfig;
|
|
221
|
+
exports.patchNodeMFConfig = __webpack_exports__.patchNodeMFConfig;
|
|
222
|
+
exports.patchSSRRspackConfig = __webpack_exports__.patchSSRRspackConfig;
|
|
223
|
+
exports.patchToolsTspack = __webpack_exports__.patchToolsTspack;
|
|
224
|
+
exports.setSSREnv = __webpack_exports__.setSSREnv;
|
|
225
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
226
|
+
if(["ENV_NAME","SSR_DIR","SSR_ENV_NAME","createSSRMFConfig","createSSRREnvConfig","patchNodeConfig","patchNodeMFConfig","patchSSRRspackConfig","patchToolsTspack","setSSREnv"].indexOf(__webpack_i__) === -1) {
|
|
227
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { encodeName } from "@module-federation/sdk";
|
|
4
|
+
import { CALL_NAME_MAP } from "../constant.mjs";
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "path"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: external "node:module"
|
|
9
|
+
|
|
10
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
11
|
+
|
|
12
|
+
;// CONCATENATED MODULE: external "../constant.mjs"
|
|
13
|
+
|
|
14
|
+
;// CONCATENATED MODULE: ./src/utils/ssr.ts
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const ssr_require = createRequire(import.meta.url);
|
|
20
|
+
const resolve = ssr_require.resolve;
|
|
21
|
+
const SSR_DIR = 'ssr';
|
|
22
|
+
const SSR_ENV_NAME = 'mf-ssr';
|
|
23
|
+
const ENV_NAME = 'mf';
|
|
24
|
+
function setSSREnv() {
|
|
25
|
+
process.env['MF_SSR_PRJ'] = 'true';
|
|
26
|
+
}
|
|
27
|
+
const isDev = ()=>{
|
|
28
|
+
return process.env['NODE_ENV'] === 'development';
|
|
29
|
+
};
|
|
30
|
+
function patchNodeConfig(config, mfConfig) {
|
|
31
|
+
var _config_output;
|
|
32
|
+
config.output ||= {};
|
|
33
|
+
config.target = 'async-node';
|
|
34
|
+
// @module-federation/node/universe-entry-chunk-tracker-plugin only export cjs
|
|
35
|
+
const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
36
|
+
config.plugins ||= [];
|
|
37
|
+
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
38
|
+
const uniqueName = mfConfig.name || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.uniqueName);
|
|
39
|
+
const chunkFileName = config.output.chunkFilename;
|
|
40
|
+
if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
41
|
+
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
|
|
42
|
+
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
|
|
46
|
+
config.output ||= {};
|
|
47
|
+
if (modifyPublicPath) {
|
|
48
|
+
var _config_output;
|
|
49
|
+
if (typeof ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath) !== 'string') {
|
|
50
|
+
throw new Error('publicPath must be string!');
|
|
51
|
+
}
|
|
52
|
+
const publicPath = config.output.publicPath;
|
|
53
|
+
if (publicPath === 'auto') {
|
|
54
|
+
throw new Error('publicPath can not be "auto"!');
|
|
55
|
+
}
|
|
56
|
+
const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
|
|
57
|
+
config.output.publicPath = publicPathWithSSRDir;
|
|
58
|
+
}
|
|
59
|
+
if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) {
|
|
60
|
+
// set virtue entry, only need mf entry
|
|
61
|
+
config.entry = 'data:application/node;base64,';
|
|
62
|
+
}
|
|
63
|
+
patchNodeConfig(config, mfConfig);
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
function patchToolsTspack(envConfig, fn) {
|
|
67
|
+
var _envConfig_tools;
|
|
68
|
+
const rspackArr = [];
|
|
69
|
+
if ((_envConfig_tools = envConfig.tools) === null || _envConfig_tools === void 0 ? void 0 : _envConfig_tools.rspack) {
|
|
70
|
+
var _envConfig_tools1, _envConfig_tools2;
|
|
71
|
+
if (Array.isArray((_envConfig_tools1 = envConfig.tools) === null || _envConfig_tools1 === void 0 ? void 0 : _envConfig_tools1.rspack)) {
|
|
72
|
+
var _envConfig_tools3;
|
|
73
|
+
rspackArr.push(...(_envConfig_tools3 = envConfig.tools) === null || _envConfig_tools3 === void 0 ? void 0 : _envConfig_tools3.rspack);
|
|
74
|
+
} else if (typeof ((_envConfig_tools2 = envConfig.tools) === null || _envConfig_tools2 === void 0 ? void 0 : _envConfig_tools2.rspack) === 'function') {
|
|
75
|
+
var _envConfig_tools4;
|
|
76
|
+
rspackArr.push((_envConfig_tools4 = envConfig.tools) === null || _envConfig_tools4 === void 0 ? void 0 : _envConfig_tools4.rspack);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
envConfig.tools ||= {};
|
|
80
|
+
envConfig.tools.rspack = [
|
|
81
|
+
...rspackArr,
|
|
82
|
+
fn
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
|
|
86
|
+
var _envConfig_tools, _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
|
|
87
|
+
const rspackArr = [];
|
|
88
|
+
if ((_envConfig_tools = envConfig.tools) === null || _envConfig_tools === void 0 ? void 0 : _envConfig_tools.rspack) {
|
|
89
|
+
var _envConfig_tools1, _envConfig_tools2;
|
|
90
|
+
if (Array.isArray((_envConfig_tools1 = envConfig.tools) === null || _envConfig_tools1 === void 0 ? void 0 : _envConfig_tools1.rspack)) {
|
|
91
|
+
var _envConfig_tools3;
|
|
92
|
+
rspackArr.push(...(_envConfig_tools3 = envConfig.tools) === null || _envConfig_tools3 === void 0 ? void 0 : _envConfig_tools3.rspack);
|
|
93
|
+
} else if (typeof ((_envConfig_tools2 = envConfig.tools) === null || _envConfig_tools2 === void 0 ? void 0 : _envConfig_tools2.rspack) === 'function') {
|
|
94
|
+
var _envConfig_tools4;
|
|
95
|
+
rspackArr.push((_envConfig_tools4 = envConfig.tools) === null || _envConfig_tools4 === void 0 ? void 0 : _envConfig_tools4.rspack);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const ssrEnvConfig = {
|
|
99
|
+
...envConfig
|
|
100
|
+
};
|
|
101
|
+
patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
|
|
102
|
+
if (environment.name !== SSR_ENV_NAME) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
|
|
106
|
+
});
|
|
107
|
+
ssrEnvConfig.output = {
|
|
108
|
+
...ssrEnvConfig.output,
|
|
109
|
+
// https://rsbuild.rs/config/output/target#other-targets
|
|
110
|
+
// Rsbuild not support all rspack targets, so modify to async-node in modifyRspackConfig
|
|
111
|
+
target: 'node',
|
|
112
|
+
distPath: {
|
|
113
|
+
...(_ssrEnvConfig_output = ssrEnvConfig.output) === null || _ssrEnvConfig_output === void 0 ? void 0 : _ssrEnvConfig_output.distPath,
|
|
114
|
+
root: path.join(((_ssrEnvConfig_output1 = ssrEnvConfig.output) === null || _ssrEnvConfig_output1 === void 0 ? void 0 : (_ssrEnvConfig_output_distPath = _ssrEnvConfig_output1.distPath) === null || _ssrEnvConfig_output_distPath === void 0 ? void 0 : _ssrEnvConfig_output_distPath.root) || ((_rsbuildConfig_output = rsbuildConfig.output) === null || _rsbuildConfig_output === void 0 ? void 0 : (_rsbuildConfig_output_distPath = _rsbuildConfig_output.distPath) === null || _rsbuildConfig_output_distPath === void 0 ? void 0 : _rsbuildConfig_output_distPath.root) || '', ssrDir)
|
|
115
|
+
},
|
|
116
|
+
emitAssets: true
|
|
117
|
+
};
|
|
118
|
+
return ssrEnvConfig;
|
|
119
|
+
}
|
|
120
|
+
function patchNodeMFConfig(mfConfig) {
|
|
121
|
+
var _mfConfig_library;
|
|
122
|
+
if (mfConfig.remotes) {
|
|
123
|
+
mfConfig.remoteType = 'script';
|
|
124
|
+
}
|
|
125
|
+
mfConfig.exposes = {
|
|
126
|
+
...mfConfig.exposes
|
|
127
|
+
};
|
|
128
|
+
mfConfig.library = {
|
|
129
|
+
...mfConfig.library,
|
|
130
|
+
name: mfConfig.name,
|
|
131
|
+
type: ((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
|
|
132
|
+
};
|
|
133
|
+
mfConfig.runtimePlugins = [
|
|
134
|
+
...mfConfig.runtimePlugins || []
|
|
135
|
+
];
|
|
136
|
+
mfConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
|
|
137
|
+
if (isDev()) {
|
|
138
|
+
mfConfig.runtimePlugins.push(// @ts-ignore
|
|
139
|
+
resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function createSSRMFConfig(mfConfig) {
|
|
143
|
+
const ssrMFConfig = {
|
|
144
|
+
...mfConfig
|
|
145
|
+
};
|
|
146
|
+
patchNodeMFConfig(ssrMFConfig);
|
|
147
|
+
ssrMFConfig.dts = false;
|
|
148
|
+
ssrMFConfig.dev = false;
|
|
149
|
+
return ssrMFConfig;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { ENV_NAME, SSR_DIR, SSR_ENV_NAME, createSSRMFConfig, createSSRREnvConfig, patchNodeConfig, patchNodeMFConfig, patchSSRRspackConfig, patchToolsTspack, setSSREnv };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils/index';
|