@modern-js/app-tools 2.9.0 → 2.10.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/CHANGELOG.md +56 -0
- package/dist/cjs/analyze/generateCode.js +3 -1
- package/dist/cjs/analyze/index.js +8 -0
- package/dist/cjs/analyze/templates.js +45 -13
- package/dist/cjs/builder/builder-rspack/index.js +22 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -3
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm/analyze/generateCode.js +3 -2
- package/dist/esm/analyze/index.js +8 -0
- package/dist/esm/analyze/templates.js +53 -15
- package/dist/esm/builder/builder-rspack/index.js +169 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +10 -3
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm-node/analyze/generateCode.js +3 -1
- package/dist/esm-node/analyze/index.js +8 -0
- package/dist/esm-node/analyze/templates.js +45 -13
- package/dist/esm-node/builder/builder-rspack/index.js +12 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +7 -4
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/builder/builder-rspack/index.d.ts +2 -1
- package/dist/types/types/config/output.d.ts +1 -0
- package/package.json +31 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0da32d0: chore: upgrade jest and puppeteer
|
|
8
|
+
chore: 升级 jest 和 puppeteer 到 latest
|
|
9
|
+
- 0d9962b: fix: add types field in package.json
|
|
10
|
+
fix: 添加 package.json 中的 types 字段
|
|
11
|
+
- fbefa7e: chore(deps): bump webpack from 5.75.0 to 5.76.2
|
|
12
|
+
|
|
13
|
+
chore(deps): 将 webpack 从 5.75.0 升级至 5.76.2
|
|
14
|
+
|
|
15
|
+
- 7b5dd99: feat(app-tools): support builder-plugin-node-polyfill & output.disableNodePolyfill false when use Rspack
|
|
16
|
+
|
|
17
|
+
feat(app-tools): 在启动 Rspack 时,支持 builder-plugin-node-polyfill 插件以及将 output.disableNodePolyfill 设置为 false
|
|
18
|
+
|
|
19
|
+
- 6db4864: feat: add output.splitRouteChunks
|
|
20
|
+
feat: 添加 output.splitRouteChunks 配置
|
|
21
|
+
- dcc5610: perf: improve routerPlugin performance
|
|
22
|
+
perf: 优化 routerPlugin 的性能
|
|
23
|
+
- 84c4372: fix: should get publicPath from webpack stats in router-plugin
|
|
24
|
+
fix: 应该从 webpack stats 获得 publicPath
|
|
25
|
+
- Updated dependencies [d8bbf28]
|
|
26
|
+
- Updated dependencies [a8db932]
|
|
27
|
+
- Updated dependencies [3e0bd50]
|
|
28
|
+
- Updated dependencies [92d247f]
|
|
29
|
+
- Updated dependencies [0da32d0]
|
|
30
|
+
- Updated dependencies [d3f0642]
|
|
31
|
+
- Updated dependencies [a16b9b0]
|
|
32
|
+
- Updated dependencies [0d9962b]
|
|
33
|
+
- Updated dependencies [fbefa7e]
|
|
34
|
+
- Updated dependencies [4d54233]
|
|
35
|
+
- Updated dependencies [6db4864]
|
|
36
|
+
- Updated dependencies [82326ee]
|
|
37
|
+
- Updated dependencies [d6b6e29]
|
|
38
|
+
- Updated dependencies [cfdbf80]
|
|
39
|
+
- Updated dependencies [ed55acb]
|
|
40
|
+
- @modern-js/prod-server@2.10.0
|
|
41
|
+
- @modern-js/builder-webpack-provider@2.10.0
|
|
42
|
+
- @modern-js/builder-rspack-provider@2.10.0
|
|
43
|
+
- @modern-js/builder-shared@2.10.0
|
|
44
|
+
- @modern-js/plugin-data-loader@2.10.0
|
|
45
|
+
- @modern-js/server@2.10.0
|
|
46
|
+
- @modern-js/types@2.10.0
|
|
47
|
+
- @modern-js/node-bundle-require@2.10.0
|
|
48
|
+
- @modern-js/new-action@2.10.0
|
|
49
|
+
- @modern-js/plugin-i18n@2.10.0
|
|
50
|
+
- @modern-js/plugin-lint@2.10.0
|
|
51
|
+
- @modern-js/upgrade@2.10.0
|
|
52
|
+
- @modern-js/plugin@2.10.0
|
|
53
|
+
- @modern-js/utils@2.10.0
|
|
54
|
+
- @modern-js/core@2.10.0
|
|
55
|
+
- @modern-js/builder-plugin-esbuild@2.10.0
|
|
56
|
+
- @modern-js/builder-plugin-node-polyfill@2.10.0
|
|
57
|
+
- @modern-js/builder@2.10.0
|
|
58
|
+
|
|
3
59
|
## 2.9.0
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
|
@@ -99,6 +99,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
99
99
|
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
|
100
100
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
101
101
|
async function generateEntryCode(entrypoint) {
|
|
102
|
+
var _a;
|
|
102
103
|
const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
|
103
104
|
if (isAutoMount) {
|
|
104
105
|
if (fileSystemRoutes) {
|
|
@@ -161,7 +162,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
161
162
|
ssrMode: useSSG ? "string" : mode,
|
|
162
163
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
163
164
|
entryName: entrypoint.entryName,
|
|
164
|
-
internalDirectory
|
|
165
|
+
internalDirectory,
|
|
166
|
+
splitRouteChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRouteChunks
|
|
165
167
|
})
|
|
166
168
|
});
|
|
167
169
|
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
|
@@ -247,6 +247,14 @@ var analyze_default = ({
|
|
|
247
247
|
imports
|
|
248
248
|
};
|
|
249
249
|
},
|
|
250
|
+
validateSchema() {
|
|
251
|
+
return {
|
|
252
|
+
target: "output.splitRouteChunks",
|
|
253
|
+
schema: {
|
|
254
|
+
type: "boolean"
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
},
|
|
250
258
|
async fileChange(e) {
|
|
251
259
|
const appContext = api.useAppContext();
|
|
252
260
|
const { appDirectory } = appContext;
|
|
@@ -176,13 +176,16 @@ const routesForServer = ({
|
|
|
176
176
|
${routesCode}
|
|
177
177
|
`;
|
|
178
178
|
};
|
|
179
|
+
const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^,]+)"`, "g");
|
|
179
180
|
const fileSystemRoutes = async ({
|
|
180
181
|
routes,
|
|
181
182
|
ssrMode,
|
|
182
183
|
nestedRoutesEntry,
|
|
183
184
|
entryName,
|
|
184
|
-
internalDirectory
|
|
185
|
+
internalDirectory,
|
|
186
|
+
splitRouteChunks = true
|
|
185
187
|
}) => {
|
|
188
|
+
const components = [];
|
|
186
189
|
const loadings = [];
|
|
187
190
|
const errors = [];
|
|
188
191
|
const loaders = [];
|
|
@@ -241,20 +244,30 @@ const fileSystemRoutes = async ({
|
|
|
241
244
|
};
|
|
242
245
|
}
|
|
243
246
|
if (route._component) {
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
if (splitRouteChunks) {
|
|
248
|
+
if (route.isRoot) {
|
|
249
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
250
|
+
component = `RootLayout`;
|
|
251
|
+
} else if (ssrMode === "string") {
|
|
252
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
253
|
+
component = `loadable(${lazyImport})`;
|
|
254
|
+
} else {
|
|
255
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
256
|
+
component = `lazy(${lazyImport})`;
|
|
257
|
+
}
|
|
250
258
|
} else {
|
|
251
|
-
|
|
252
|
-
component = `
|
|
259
|
+
components.push(route._component);
|
|
260
|
+
component = `component_${components.length - 1}`;
|
|
253
261
|
}
|
|
254
262
|
}
|
|
255
263
|
} else if (route._component) {
|
|
256
|
-
|
|
257
|
-
|
|
264
|
+
if (splitRouteChunks) {
|
|
265
|
+
lazyImport = `() => import('${route._component}')`;
|
|
266
|
+
component = `loadable(${lazyImport})`;
|
|
267
|
+
} else {
|
|
268
|
+
components.push(route._component);
|
|
269
|
+
component = `component_${components.length - 1}`;
|
|
270
|
+
}
|
|
258
271
|
}
|
|
259
272
|
const finalRoute = {
|
|
260
273
|
...route,
|
|
@@ -275,20 +288,38 @@ const fileSystemRoutes = async ({
|
|
|
275
288
|
for (const route of routes) {
|
|
276
289
|
if ("type" in route) {
|
|
277
290
|
const newRoute = traverseRouteTree(route);
|
|
278
|
-
|
|
291
|
+
const routeStr = JSON.stringify(newRoute, null, 2);
|
|
292
|
+
const keywords = [
|
|
293
|
+
"component",
|
|
294
|
+
"lazyImport",
|
|
295
|
+
"loader",
|
|
296
|
+
"loading",
|
|
297
|
+
"error"
|
|
298
|
+
];
|
|
299
|
+
const regs = keywords.map(createMatchReg);
|
|
300
|
+
const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
|
|
301
|
+
routeComponentsCode += `${newRouteStr},`;
|
|
279
302
|
} else {
|
|
280
303
|
const component = `loadable(() => import('${route._component}'))`;
|
|
281
304
|
const finalRoute = {
|
|
282
305
|
...route,
|
|
283
306
|
component
|
|
284
307
|
};
|
|
285
|
-
|
|
308
|
+
const keywords = ["component", "lazyImport"];
|
|
309
|
+
const routeStr = JSON.stringify(finalRoute, null, 2);
|
|
310
|
+
const regs = keywords.map(createMatchReg);
|
|
311
|
+
const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/\\"/g, '"');
|
|
312
|
+
routeComponentsCode += `${newRouteStr},`;
|
|
286
313
|
}
|
|
287
314
|
}
|
|
288
315
|
routeComponentsCode += `
|
|
289
316
|
];`;
|
|
290
317
|
const importLoadingCode = loadings.map((loading, index2) => {
|
|
291
318
|
return `import loading_${index2} from '${loading}';
|
|
319
|
+
`;
|
|
320
|
+
}).join("");
|
|
321
|
+
const importComponentsCode = components.map((component, index2) => {
|
|
322
|
+
return `import component_${index2} from '${component}';
|
|
292
323
|
`;
|
|
293
324
|
}).join("");
|
|
294
325
|
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
@@ -313,6 +344,7 @@ const fileSystemRoutes = async ({
|
|
|
313
344
|
await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
|
314
345
|
return `
|
|
315
346
|
${importLazyCode}
|
|
347
|
+
${importComponentsCode}
|
|
316
348
|
${rootLayoutCode}
|
|
317
349
|
${importLoadingCode}
|
|
318
350
|
${importErrorComponentsCode}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
var builder_rspack_exports = {};
|
|
19
29
|
__export(builder_rspack_exports, {
|
|
@@ -23,7 +33,18 @@ module.exports = __toCommonJS(builder_rspack_exports);
|
|
|
23
33
|
var import_builder_rspack_provider = require("@modern-js/builder-rspack-provider");
|
|
24
34
|
var import_generator = require("../generator");
|
|
25
35
|
function createRspackBuilderForModern(options) {
|
|
26
|
-
return (0, import_generator.generateBuilder)(options, import_builder_rspack_provider.builderRspackProvider
|
|
36
|
+
return (0, import_generator.generateBuilder)(options, import_builder_rspack_provider.builderRspackProvider, {
|
|
37
|
+
async modifyBuilderInstance(builder) {
|
|
38
|
+
applyBuilderPlugins(builder, options);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function applyBuilderPlugins(builder, options) {
|
|
43
|
+
const { normalizedConfig } = options;
|
|
44
|
+
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
45
|
+
const { builderPluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
|
|
46
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
47
|
+
}
|
|
27
48
|
}
|
|
28
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
50
|
0 && (module.exports = {
|
|
@@ -42,13 +42,16 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
42
42
|
api.modifyBundlerChain(
|
|
43
43
|
async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
|
44
44
|
const builderConfig = api.getNormalizedConfig();
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const { normalizedConfig: normalizedConfig2 } = options;
|
|
46
|
+
if ((0, import_utils.isSSR)(normalizedConfig2)) {
|
|
47
|
+
applyRouterPlugin(chain, options);
|
|
48
|
+
await applySSRLoaderEntry(chain, options, isServer);
|
|
49
|
+
}
|
|
47
50
|
if (["node", "service-worker"].includes(target)) {
|
|
48
51
|
applyFilterEntriesBySSRConfig({
|
|
49
52
|
isProd,
|
|
50
53
|
chain,
|
|
51
|
-
appNormalizedConfig:
|
|
54
|
+
appNormalizedConfig: normalizedConfig2
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
if ((0, import_adapterHtml.isHtmlEnabled)(builderConfig, target)) {
|
|
@@ -245,7 +245,7 @@ var generateCode = function() {
|
|
|
245
245
|
}
|
|
246
246
|
function _generateEntryCode() {
|
|
247
247
|
_generateEntryCode = _asyncToGenerator(function(entrypoint) {
|
|
248
|
-
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, serverLoaderCombined, serverLoaderFile, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
|
|
248
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config2_output, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, serverLoaderCombined, serverLoaderFile, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
|
|
249
249
|
return __generator(this, function(_state) {
|
|
250
250
|
switch(_state.label){
|
|
251
251
|
case 0:
|
|
@@ -322,7 +322,8 @@ var generateCode = function() {
|
|
|
322
322
|
ssrMode: useSSG ? "string" : mode,
|
|
323
323
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
324
324
|
entryName: entrypoint.entryName,
|
|
325
|
-
internalDirectory: internalDirectory
|
|
325
|
+
internalDirectory: internalDirectory,
|
|
326
|
+
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config2_output = config2.output) === null || _config2_output === void 0 ? void 0 : _config2_output.splitRouteChunks
|
|
326
327
|
})
|
|
327
328
|
];
|
|
328
329
|
case 4:
|
|
@@ -638,6 +638,14 @@ var analyze_default = function(param) {
|
|
|
638
638
|
});
|
|
639
639
|
})();
|
|
640
640
|
},
|
|
641
|
+
validateSchema: function validateSchema() {
|
|
642
|
+
return {
|
|
643
|
+
target: "output.splitRouteChunks",
|
|
644
|
+
schema: {
|
|
645
|
+
type: "boolean"
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
},
|
|
641
649
|
fileChange: function fileChange(e) {
|
|
642
650
|
return _asyncToGenerator(function() {
|
|
643
651
|
var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
|
|
@@ -296,13 +296,17 @@ var routesForServer = function(param) {
|
|
|
296
296
|
}
|
|
297
297
|
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
|
298
298
|
};
|
|
299
|
+
var createMatchReg = function(keyword) {
|
|
300
|
+
return new RegExp('("'.concat(keyword, '":\\s)"([^,]+)"'), "g");
|
|
301
|
+
};
|
|
299
302
|
var fileSystemRoutes = function() {
|
|
300
303
|
var _ref = _asyncToGenerator(function(param) {
|
|
301
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
|
304
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRouteChunks, splitRouteChunks, components, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, routeStr, keywords, regs, newRouteStr, component, finalRoute, keywords1, routeStr1, regs1, newRouteStr1, importLoadingCode, importComponentsCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
|
302
305
|
return __generator(this, function(_state) {
|
|
303
306
|
switch(_state.label){
|
|
304
307
|
case 0:
|
|
305
|
-
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
|
|
308
|
+
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory, _param_splitRouteChunks = param.splitRouteChunks, splitRouteChunks = _param_splitRouteChunks === void 0 ? true : _param_splitRouteChunks;
|
|
309
|
+
components = [];
|
|
306
310
|
loadings = [];
|
|
307
311
|
errors = [];
|
|
308
312
|
loaders = [];
|
|
@@ -351,20 +355,30 @@ var fileSystemRoutes = function() {
|
|
|
351
355
|
};
|
|
352
356
|
}
|
|
353
357
|
if (route._component) {
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
if (splitRouteChunks) {
|
|
359
|
+
if (route.isRoot) {
|
|
360
|
+
rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
|
|
361
|
+
component = "RootLayout";
|
|
362
|
+
} else if (ssrMode === "string") {
|
|
363
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
364
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
365
|
+
} else {
|
|
366
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
367
|
+
component = "lazy(".concat(lazyImport, ")");
|
|
368
|
+
}
|
|
360
369
|
} else {
|
|
361
|
-
|
|
362
|
-
component = "
|
|
370
|
+
components.push(route._component);
|
|
371
|
+
component = "component_".concat(components.length - 1);
|
|
363
372
|
}
|
|
364
373
|
}
|
|
365
374
|
} else if (route._component) {
|
|
366
|
-
|
|
367
|
-
|
|
375
|
+
if (splitRouteChunks) {
|
|
376
|
+
lazyImport = "() => import('".concat(route._component, "')");
|
|
377
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
378
|
+
} else {
|
|
379
|
+
components.push(route._component);
|
|
380
|
+
component = "component_".concat(components.length - 1);
|
|
381
|
+
}
|
|
368
382
|
}
|
|
369
383
|
var finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
370
384
|
lazyImport: lazyImport,
|
|
@@ -385,13 +399,34 @@ var fileSystemRoutes = function() {
|
|
|
385
399
|
route = _step.value;
|
|
386
400
|
if ("type" in route) {
|
|
387
401
|
newRoute = traverseRouteTree(route);
|
|
388
|
-
|
|
402
|
+
routeStr = JSON.stringify(newRoute, null, 2);
|
|
403
|
+
keywords = [
|
|
404
|
+
"component",
|
|
405
|
+
"lazyImport",
|
|
406
|
+
"loader",
|
|
407
|
+
"loading",
|
|
408
|
+
"error"
|
|
409
|
+
];
|
|
410
|
+
regs = keywords.map(createMatchReg);
|
|
411
|
+
newRouteStr = regs.reduce(function(acc, reg) {
|
|
412
|
+
return acc.replace(reg, "$1$2");
|
|
413
|
+
}, routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
|
|
414
|
+
routeComponentsCode += "".concat(newRouteStr, ",");
|
|
389
415
|
} else {
|
|
390
416
|
component = "loadable(() => import('".concat(route._component, "'))");
|
|
391
417
|
finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
392
418
|
component: component
|
|
393
419
|
});
|
|
394
|
-
|
|
420
|
+
keywords1 = [
|
|
421
|
+
"component",
|
|
422
|
+
"lazyImport"
|
|
423
|
+
];
|
|
424
|
+
routeStr1 = JSON.stringify(finalRoute, null, 2);
|
|
425
|
+
regs1 = keywords1.map(createMatchReg);
|
|
426
|
+
newRouteStr1 = regs1.reduce(function(acc, reg) {
|
|
427
|
+
return acc.replace(reg, "$1$2");
|
|
428
|
+
}, routeStr1).replace(/\\"/g, '"');
|
|
429
|
+
routeComponentsCode += "".concat(newRouteStr1, ",");
|
|
395
430
|
}
|
|
396
431
|
}
|
|
397
432
|
} catch (err) {
|
|
@@ -412,6 +447,9 @@ var fileSystemRoutes = function() {
|
|
|
412
447
|
importLoadingCode = loadings.map(function(loading, index2) {
|
|
413
448
|
return "import loading_".concat(index2, " from '").concat(loading, "';\n");
|
|
414
449
|
}).join("");
|
|
450
|
+
importComponentsCode = components.map(function(component, index2) {
|
|
451
|
+
return "import component_".concat(index2, " from '").concat(component, "';\n");
|
|
452
|
+
}).join("");
|
|
415
453
|
importErrorComponentsCode = errors.map(function(error, index2) {
|
|
416
454
|
return "import error_".concat(index2, " from '").concat(error, "';\n");
|
|
417
455
|
}).join("");
|
|
@@ -454,7 +492,7 @@ var fileSystemRoutes = function() {
|
|
|
454
492
|
_state.sent();
|
|
455
493
|
return [
|
|
456
494
|
2,
|
|
457
|
-
"\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
495
|
+
"\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
458
496
|
];
|
|
459
497
|
}
|
|
460
498
|
});
|
|
@@ -1,6 +1,174 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g;
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
1
125
|
import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
|
|
2
126
|
import { generateBuilder } from "../generator";
|
|
3
127
|
function createRspackBuilderForModern(options) {
|
|
4
|
-
return generateBuilder(options, builderRspackProvider
|
|
128
|
+
return generateBuilder(options, builderRspackProvider, {
|
|
129
|
+
modifyBuilderInstance: function modifyBuilderInstance(builder) {
|
|
130
|
+
return _asyncToGenerator(function() {
|
|
131
|
+
return __generator(this, function(_state) {
|
|
132
|
+
applyBuilderPlugins(builder, options);
|
|
133
|
+
return [
|
|
134
|
+
2
|
|
135
|
+
];
|
|
136
|
+
});
|
|
137
|
+
})();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function applyBuilderPlugins(builder, options) {
|
|
142
|
+
return _applyBuilderPlugins.apply(this, arguments);
|
|
143
|
+
}
|
|
144
|
+
function _applyBuilderPlugins() {
|
|
145
|
+
_applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
|
|
146
|
+
var normalizedConfig, builderPluginNodePolyfill;
|
|
147
|
+
return __generator(this, function(_state) {
|
|
148
|
+
switch(_state.label){
|
|
149
|
+
case 0:
|
|
150
|
+
normalizedConfig = options.normalizedConfig;
|
|
151
|
+
if (!!normalizedConfig.output.disableNodePolyfill) return [
|
|
152
|
+
3,
|
|
153
|
+
2
|
|
154
|
+
];
|
|
155
|
+
return [
|
|
156
|
+
4,
|
|
157
|
+
import("@modern-js/builder-plugin-node-polyfill")
|
|
158
|
+
];
|
|
159
|
+
case 1:
|
|
160
|
+
builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
|
|
161
|
+
builder.addPlugins([
|
|
162
|
+
builderPluginNodePolyfill()
|
|
163
|
+
]);
|
|
164
|
+
_state.label = 2;
|
|
165
|
+
case 2:
|
|
166
|
+
return [
|
|
167
|
+
2
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
return _applyBuilderPlugins.apply(this, arguments);
|
|
5
173
|
}
|
|
6
174
|
export { createRspackBuilderForModern };
|
|
@@ -123,7 +123,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
126
|
-
import { fs } from "@modern-js/utils";
|
|
126
|
+
import { isSSR, fs } from "@modern-js/utils";
|
|
127
127
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
|
128
128
|
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
|
129
129
|
import { isHtmlEnabled } from "./adapterHtml";
|
|
@@ -144,12 +144,17 @@ var builderPluginAdapterSSR = function(options) {
|
|
|
144
144
|
});
|
|
145
145
|
api.modifyBundlerChain(function() {
|
|
146
146
|
var _ref = _asyncToGenerator(function(chain, param) {
|
|
147
|
-
var target, CHAIN_ID, isProd, HtmlBundlerPlugin, isServer, builderConfig;
|
|
147
|
+
var target, CHAIN_ID, isProd, HtmlBundlerPlugin, isServer, builderConfig, normalizedConfig2;
|
|
148
148
|
return __generator(this, function(_state) {
|
|
149
149
|
switch(_state.label){
|
|
150
150
|
case 0:
|
|
151
151
|
target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
|
|
152
152
|
builderConfig = api.getNormalizedConfig();
|
|
153
|
+
normalizedConfig2 = options.normalizedConfig;
|
|
154
|
+
if (!isSSR(normalizedConfig2)) return [
|
|
155
|
+
3,
|
|
156
|
+
2
|
|
157
|
+
];
|
|
153
158
|
applyRouterPlugin(chain, options);
|
|
154
159
|
return [
|
|
155
160
|
4,
|
|
@@ -157,6 +162,8 @@ var builderPluginAdapterSSR = function(options) {
|
|
|
157
162
|
];
|
|
158
163
|
case 1:
|
|
159
164
|
_state.sent();
|
|
165
|
+
_state.label = 2;
|
|
166
|
+
case 2:
|
|
160
167
|
if ([
|
|
161
168
|
"node",
|
|
162
169
|
"service-worker"
|
|
@@ -164,7 +171,7 @@ var builderPluginAdapterSSR = function(options) {
|
|
|
164
171
|
applyFilterEntriesBySSRConfig({
|
|
165
172
|
isProd: isProd,
|
|
166
173
|
chain: chain,
|
|
167
|
-
appNormalizedConfig:
|
|
174
|
+
appNormalizedConfig: normalizedConfig2
|
|
168
175
|
});
|
|
169
176
|
}
|
|
170
177
|
if (isHtmlEnabled(builderConfig, target)) {
|
|
@@ -81,6 +81,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
81
81
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
82
82
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
83
83
|
async function generateEntryCode(entrypoint) {
|
|
84
|
+
var _a;
|
|
84
85
|
const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
|
85
86
|
if (isAutoMount) {
|
|
86
87
|
if (fileSystemRoutes) {
|
|
@@ -143,7 +144,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
143
144
|
ssrMode: useSSG ? "string" : mode,
|
|
144
145
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
145
146
|
entryName: entrypoint.entryName,
|
|
146
|
-
internalDirectory
|
|
147
|
+
internalDirectory,
|
|
148
|
+
splitRouteChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRouteChunks
|
|
147
149
|
})
|
|
148
150
|
});
|
|
149
151
|
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
|
|
@@ -227,6 +227,14 @@ var analyze_default = ({
|
|
|
227
227
|
imports
|
|
228
228
|
};
|
|
229
229
|
},
|
|
230
|
+
validateSchema() {
|
|
231
|
+
return {
|
|
232
|
+
target: "output.splitRouteChunks",
|
|
233
|
+
schema: {
|
|
234
|
+
type: "boolean"
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
},
|
|
230
238
|
async fileChange(e) {
|
|
231
239
|
const appContext = api.useAppContext();
|
|
232
240
|
const { appDirectory } = appContext;
|
|
@@ -139,13 +139,16 @@ const routesForServer = ({
|
|
|
139
139
|
${routesCode}
|
|
140
140
|
`;
|
|
141
141
|
};
|
|
142
|
+
const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^,]+)"`, "g");
|
|
142
143
|
const fileSystemRoutes = async ({
|
|
143
144
|
routes,
|
|
144
145
|
ssrMode,
|
|
145
146
|
nestedRoutesEntry,
|
|
146
147
|
entryName,
|
|
147
|
-
internalDirectory
|
|
148
|
+
internalDirectory,
|
|
149
|
+
splitRouteChunks = true
|
|
148
150
|
}) => {
|
|
151
|
+
const components = [];
|
|
149
152
|
const loadings = [];
|
|
150
153
|
const errors = [];
|
|
151
154
|
const loaders = [];
|
|
@@ -204,20 +207,30 @@ const fileSystemRoutes = async ({
|
|
|
204
207
|
};
|
|
205
208
|
}
|
|
206
209
|
if (route._component) {
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
if (splitRouteChunks) {
|
|
211
|
+
if (route.isRoot) {
|
|
212
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
213
|
+
component = `RootLayout`;
|
|
214
|
+
} else if (ssrMode === "string") {
|
|
215
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
216
|
+
component = `loadable(${lazyImport})`;
|
|
217
|
+
} else {
|
|
218
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
219
|
+
component = `lazy(${lazyImport})`;
|
|
220
|
+
}
|
|
213
221
|
} else {
|
|
214
|
-
|
|
215
|
-
component = `
|
|
222
|
+
components.push(route._component);
|
|
223
|
+
component = `component_${components.length - 1}`;
|
|
216
224
|
}
|
|
217
225
|
}
|
|
218
226
|
} else if (route._component) {
|
|
219
|
-
|
|
220
|
-
|
|
227
|
+
if (splitRouteChunks) {
|
|
228
|
+
lazyImport = `() => import('${route._component}')`;
|
|
229
|
+
component = `loadable(${lazyImport})`;
|
|
230
|
+
} else {
|
|
231
|
+
components.push(route._component);
|
|
232
|
+
component = `component_${components.length - 1}`;
|
|
233
|
+
}
|
|
221
234
|
}
|
|
222
235
|
const finalRoute = {
|
|
223
236
|
...route,
|
|
@@ -238,20 +251,38 @@ const fileSystemRoutes = async ({
|
|
|
238
251
|
for (const route of routes) {
|
|
239
252
|
if ("type" in route) {
|
|
240
253
|
const newRoute = traverseRouteTree(route);
|
|
241
|
-
|
|
254
|
+
const routeStr = JSON.stringify(newRoute, null, 2);
|
|
255
|
+
const keywords = [
|
|
256
|
+
"component",
|
|
257
|
+
"lazyImport",
|
|
258
|
+
"loader",
|
|
259
|
+
"loading",
|
|
260
|
+
"error"
|
|
261
|
+
];
|
|
262
|
+
const regs = keywords.map(createMatchReg);
|
|
263
|
+
const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
|
|
264
|
+
routeComponentsCode += `${newRouteStr},`;
|
|
242
265
|
} else {
|
|
243
266
|
const component = `loadable(() => import('${route._component}'))`;
|
|
244
267
|
const finalRoute = {
|
|
245
268
|
...route,
|
|
246
269
|
component
|
|
247
270
|
};
|
|
248
|
-
|
|
271
|
+
const keywords = ["component", "lazyImport"];
|
|
272
|
+
const routeStr = JSON.stringify(finalRoute, null, 2);
|
|
273
|
+
const regs = keywords.map(createMatchReg);
|
|
274
|
+
const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/\\"/g, '"');
|
|
275
|
+
routeComponentsCode += `${newRouteStr},`;
|
|
249
276
|
}
|
|
250
277
|
}
|
|
251
278
|
routeComponentsCode += `
|
|
252
279
|
];`;
|
|
253
280
|
const importLoadingCode = loadings.map((loading, index2) => {
|
|
254
281
|
return `import loading_${index2} from '${loading}';
|
|
282
|
+
`;
|
|
283
|
+
}).join("");
|
|
284
|
+
const importComponentsCode = components.map((component, index2) => {
|
|
285
|
+
return `import component_${index2} from '${component}';
|
|
255
286
|
`;
|
|
256
287
|
}).join("");
|
|
257
288
|
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
@@ -276,6 +307,7 @@ const fileSystemRoutes = async ({
|
|
|
276
307
|
await fs.writeJSON(loadersMapFile, loadersMap);
|
|
277
308
|
return `
|
|
278
309
|
${importLazyCode}
|
|
310
|
+
${importComponentsCode}
|
|
279
311
|
${rootLayoutCode}
|
|
280
312
|
${importLoadingCode}
|
|
281
313
|
${importErrorComponentsCode}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
|
|
2
2
|
import { generateBuilder } from "../generator";
|
|
3
3
|
function createRspackBuilderForModern(options) {
|
|
4
|
-
return generateBuilder(options, builderRspackProvider
|
|
4
|
+
return generateBuilder(options, builderRspackProvider, {
|
|
5
|
+
async modifyBuilderInstance(builder) {
|
|
6
|
+
applyBuilderPlugins(builder, options);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async function applyBuilderPlugins(builder, options) {
|
|
11
|
+
const { normalizedConfig } = options;
|
|
12
|
+
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
13
|
+
const { builderPluginNodePolyfill } = await import("@modern-js/builder-plugin-node-polyfill");
|
|
14
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
15
|
+
}
|
|
5
16
|
}
|
|
6
17
|
export {
|
|
7
18
|
createRspackBuilderForModern
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mergeBuilderConfig
|
|
3
3
|
} from "@modern-js/builder-shared";
|
|
4
|
-
import { fs } from "@modern-js/utils";
|
|
4
|
+
import { isSSR, fs } from "@modern-js/utils";
|
|
5
5
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
|
6
6
|
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
|
7
7
|
import { isHtmlEnabled } from "./adapterHtml";
|
|
@@ -22,13 +22,16 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
22
22
|
api.modifyBundlerChain(
|
|
23
23
|
async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
|
24
24
|
const builderConfig = api.getNormalizedConfig();
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const { normalizedConfig: normalizedConfig2 } = options;
|
|
26
|
+
if (isSSR(normalizedConfig2)) {
|
|
27
|
+
applyRouterPlugin(chain, options);
|
|
28
|
+
await applySSRLoaderEntry(chain, options, isServer);
|
|
29
|
+
}
|
|
27
30
|
if (["node", "service-worker"].includes(target)) {
|
|
28
31
|
applyFilterEntriesBySSRConfig({
|
|
29
32
|
isProd,
|
|
30
33
|
chain,
|
|
31
|
-
appNormalizedConfig:
|
|
34
|
+
appNormalizedConfig: normalizedConfig2
|
|
32
35
|
});
|
|
33
36
|
}
|
|
34
37
|
if (isHtmlEnabled(builderConfig, target)) {
|
|
@@ -35,12 +35,14 @@ export declare const fileSystemRoutes: ({
|
|
|
35
35
|
ssrMode,
|
|
36
36
|
nestedRoutesEntry,
|
|
37
37
|
entryName,
|
|
38
|
-
internalDirectory
|
|
38
|
+
internalDirectory,
|
|
39
|
+
splitRouteChunks
|
|
39
40
|
}: {
|
|
40
41
|
routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
|
|
41
42
|
ssrMode?: SSRMode | undefined;
|
|
42
43
|
nestedRoutesEntry?: string | undefined;
|
|
43
44
|
entryName: string;
|
|
44
45
|
internalDirectory: string;
|
|
46
|
+
splitRouteChunks?: boolean | undefined;
|
|
45
47
|
}) => Promise<string>;
|
|
46
48
|
export declare function ssrLoaderCombinedModule(entrypoints: Entrypoint[], entrypoint: Entrypoint, config: AppNormalizedConfig<'shared'>, appContext: IAppContext): string | null;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { BuilderInstance } from '@modern-js/builder-shared';
|
|
1
2
|
import { BuilderOptions } from '../shared';
|
|
2
|
-
export declare function createRspackBuilderForModern(options: BuilderOptions<'rspack'>): Promise<
|
|
3
|
+
export declare function createRspackBuilderForModern(options: BuilderOptions<'rspack'>): Promise<BuilderInstance<import("@modern-js/builder-shared").BuilderProvider<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>>;
|
|
@@ -7,6 +7,7 @@ export type BuilderOutputConfig = UnwrapBuilderConfig<BuilderConfig, 'output'>;
|
|
|
7
7
|
export type RsBuilderOutputConfig = UnwrapBuilderConfig<RsBuilderConfig, 'output'>;
|
|
8
8
|
export interface SharedOutputConfig extends BuilderSharedOutputConfig {
|
|
9
9
|
ssg?: SSGConfig;
|
|
10
|
+
splitRouteChunks?: boolean;
|
|
10
11
|
disableNodePolyfill?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export interface OutputUserConfig extends BuilderOutputConfig, SharedOutputConfig {}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.10.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/index.js",
|
|
@@ -22,18 +22,22 @@
|
|
|
22
22
|
"import": "./dist/esm/index.js",
|
|
23
23
|
"require": "./dist/cjs/index.js"
|
|
24
24
|
},
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
25
26
|
"default": "./dist/cjs/index.js"
|
|
26
27
|
},
|
|
27
28
|
"./cli": {
|
|
28
29
|
"jsnext:source": "./src/index.ts",
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
29
31
|
"default": "./dist/cjs/index.js"
|
|
30
32
|
},
|
|
31
33
|
"./types": {
|
|
32
34
|
"jsnext:source": "./lib/types.d.ts",
|
|
35
|
+
"types": "./lib/types.d.ts",
|
|
33
36
|
"default": "./lib/types.d.ts"
|
|
34
37
|
},
|
|
35
38
|
"./server": {
|
|
36
39
|
"jsnext:source": "./src/exports/server.ts",
|
|
40
|
+
"types": "./dist/types/exports/server.d.ts",
|
|
37
41
|
"default": "./dist/cjs/exports/server.js"
|
|
38
42
|
}
|
|
39
43
|
},
|
|
@@ -64,39 +68,39 @@
|
|
|
64
68
|
"@babel/types": "^7.18.0",
|
|
65
69
|
"es-module-lexer": "^1.1.0",
|
|
66
70
|
"esbuild": "0.15.7",
|
|
67
|
-
"@modern-js/builder": "2.
|
|
68
|
-
"@modern-js/builder-plugin-esbuild": "2.
|
|
69
|
-
"@modern-js/builder-plugin-node-polyfill": "2.
|
|
70
|
-
"@modern-js/builder-shared": "2.
|
|
71
|
-
"@modern-js/builder-webpack-provider": "2.
|
|
72
|
-
"@modern-js/core": "2.
|
|
73
|
-
"@modern-js/new-action": "2.
|
|
74
|
-
"@modern-js/node-bundle-require": "2.
|
|
75
|
-
"@modern-js/plugin": "2.
|
|
76
|
-
"@modern-js/plugin-data-loader": "2.
|
|
77
|
-
"@modern-js/plugin-i18n": "2.
|
|
78
|
-
"@modern-js/plugin-lint": "2.
|
|
79
|
-
"@modern-js/prod-server": "2.
|
|
80
|
-
"@modern-js/server": "2.
|
|
81
|
-
"@modern-js/types": "2.
|
|
82
|
-
"@modern-js/upgrade": "2.
|
|
83
|
-
"@modern-js/utils": "2.
|
|
71
|
+
"@modern-js/builder": "2.10.0",
|
|
72
|
+
"@modern-js/builder-plugin-esbuild": "2.10.0",
|
|
73
|
+
"@modern-js/builder-plugin-node-polyfill": "2.10.0",
|
|
74
|
+
"@modern-js/builder-shared": "2.10.0",
|
|
75
|
+
"@modern-js/builder-webpack-provider": "2.10.0",
|
|
76
|
+
"@modern-js/core": "2.10.0",
|
|
77
|
+
"@modern-js/new-action": "2.10.0",
|
|
78
|
+
"@modern-js/node-bundle-require": "2.10.0",
|
|
79
|
+
"@modern-js/plugin": "2.10.0",
|
|
80
|
+
"@modern-js/plugin-data-loader": "2.10.0",
|
|
81
|
+
"@modern-js/plugin-i18n": "2.10.0",
|
|
82
|
+
"@modern-js/plugin-lint": "2.10.0",
|
|
83
|
+
"@modern-js/prod-server": "2.10.0",
|
|
84
|
+
"@modern-js/server": "2.10.0",
|
|
85
|
+
"@modern-js/types": "2.10.0",
|
|
86
|
+
"@modern-js/upgrade": "2.10.0",
|
|
87
|
+
"@modern-js/utils": "2.10.0"
|
|
84
88
|
},
|
|
85
89
|
"devDependencies": {
|
|
86
90
|
"@types/babel__traverse": "^7.14.2",
|
|
87
|
-
"@types/jest": "^
|
|
91
|
+
"@types/jest": "^29",
|
|
88
92
|
"@types/node": "^14",
|
|
89
|
-
"jest": "^
|
|
93
|
+
"jest": "^29",
|
|
90
94
|
"typescript": "^4",
|
|
91
|
-
"webpack": "^5.
|
|
92
|
-
"@modern-js/builder-plugin-swc": "2.
|
|
93
|
-
"@modern-js/builder-rspack-provider": "2.
|
|
94
|
-
"@modern-js/server-core": "2.
|
|
95
|
-
"@scripts/
|
|
96
|
-
"@scripts/
|
|
95
|
+
"webpack": "^5.76.2",
|
|
96
|
+
"@modern-js/builder-plugin-swc": "2.10.0",
|
|
97
|
+
"@modern-js/builder-rspack-provider": "2.10.0",
|
|
98
|
+
"@modern-js/server-core": "2.10.0",
|
|
99
|
+
"@scripts/build": "2.10.0",
|
|
100
|
+
"@scripts/jest-config": "2.10.0"
|
|
97
101
|
},
|
|
98
102
|
"peerDependencies": {
|
|
99
|
-
"@modern-js/builder-rspack-provider": "^2.
|
|
103
|
+
"@modern-js/builder-rspack-provider": "^2.10.0"
|
|
100
104
|
},
|
|
101
105
|
"peerDependenciesMeta": {
|
|
102
106
|
"@modern-js/builder-rspack-provider": {
|