@modern-js/app-tools 2.10.1-alpha.0 → 2.11.1-alpha.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 +66 -0
- package/dist/cjs/analyze/index.js +1 -1
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +17 -12
- package/dist/cjs/utils/restart.js +1 -1
- package/dist/esm/analyze/index.js +2 -2
- package/dist/esm/builder/index.js +14 -9
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +20 -13
- package/dist/esm/utils/restart.js +2 -2
- package/dist/esm-node/analyze/index.js +3 -2
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +17 -12
- package/dist/esm-node/utils/restart.js +8 -2
- package/dist/js/modern/analyze/constants.js +3 -1
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +47 -46
- package/dist/js/modern/analyze/nestedRoutes.js +32 -3
- package/dist/js/modern/analyze/templates.js +4 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +48 -47
- package/dist/js/node/analyze/nestedRoutes.js +32 -3
- package/dist/js/node/analyze/templates.js +4 -10
- package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
- package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +3 -1
- package/dist/js/treeshaking/analyze/generateCode.js +14 -14
- package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
- package/dist/js/treeshaking/analyze/index.js +142 -137
- package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -13
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +36 -28
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/types/config/source.d.ts +2 -2
- package/package.json +24 -24
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.11.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 415bee6: fix: load chunk while can not load all css asset, when streaming ssr.
|
|
8
|
+
fix: 使用 streaming ssr 时,不能加载当前 chunk 的所有 css 资源
|
|
9
|
+
- c0ba89b: feat: 控制台输出 rspack 版本
|
|
10
|
+
feat: Print the version of rspack in the console.
|
|
11
|
+
- 0bd018b: feat: support use node api run dev & build & deploy command
|
|
12
|
+
feat: 支持通过 node api 运行 dev & build & deploy 命令
|
|
13
|
+
- 5d624fd: feat: assets and data prefetching is supported
|
|
14
|
+
feat: 支持资源和数据预加载
|
|
15
|
+
- 7017909: fix: distpath.root not take effect when serve
|
|
16
|
+
|
|
17
|
+
fix: 修复 distpath.root 在 run serve 时不生效的问题
|
|
18
|
+
|
|
19
|
+
- 381a3b9: feat(utils): move universal utils to the universal folder
|
|
20
|
+
|
|
21
|
+
feat(utils): 将运行时使用的 utils 移动到 universal 目录
|
|
22
|
+
|
|
23
|
+
- a47543a: fix: should hide publicPath in injected manifest
|
|
24
|
+
fix: 应该隐藏 publicPath 在注入的 manifest 中
|
|
25
|
+
- Updated dependencies [adcedad]
|
|
26
|
+
- Updated dependencies [cfb058f]
|
|
27
|
+
- Updated dependencies [a9c6083]
|
|
28
|
+
- Updated dependencies [55b07fd]
|
|
29
|
+
- Updated dependencies [c0ba89b]
|
|
30
|
+
- Updated dependencies [0bd018b]
|
|
31
|
+
- Updated dependencies [8b90c79]
|
|
32
|
+
- Updated dependencies [a8c08c3]
|
|
33
|
+
- Updated dependencies [3aa318d]
|
|
34
|
+
- Updated dependencies [5d624fd]
|
|
35
|
+
- Updated dependencies [e2466a1]
|
|
36
|
+
- Updated dependencies [58faba2]
|
|
37
|
+
- Updated dependencies [53b0a63]
|
|
38
|
+
- Updated dependencies [02bb383]
|
|
39
|
+
- Updated dependencies [3171c9d]
|
|
40
|
+
- Updated dependencies [381a3b9]
|
|
41
|
+
- Updated dependencies [7a60f10]
|
|
42
|
+
- Updated dependencies [73cfc9b]
|
|
43
|
+
- Updated dependencies [cd1040f]
|
|
44
|
+
- Updated dependencies [e262a99]
|
|
45
|
+
- Updated dependencies [7178795]
|
|
46
|
+
- Updated dependencies [1140a69]
|
|
47
|
+
- Updated dependencies [b71cef1]
|
|
48
|
+
- Updated dependencies [274b2e5]
|
|
49
|
+
- Updated dependencies [b9e1c54]
|
|
50
|
+
- @modern-js/builder-shared@2.11.0
|
|
51
|
+
- @modern-js/builder-webpack-provider@2.11.0
|
|
52
|
+
- @modern-js/builder@2.11.0
|
|
53
|
+
- @modern-js/utils@2.11.0
|
|
54
|
+
- @modern-js/builder-rspack-provider@2.11.0
|
|
55
|
+
- @modern-js/core@2.11.0
|
|
56
|
+
- @modern-js/builder-plugin-node-polyfill@2.11.0
|
|
57
|
+
- @modern-js/plugin-data-loader@2.11.0
|
|
58
|
+
- @modern-js/plugin-lint@2.11.0
|
|
59
|
+
- @modern-js/prod-server@2.11.0
|
|
60
|
+
- @modern-js/server@2.11.0
|
|
61
|
+
- @modern-js/builder-plugin-esbuild@2.11.0
|
|
62
|
+
- @modern-js/plugin-i18n@2.11.0
|
|
63
|
+
- @modern-js/new-action@2.11.0
|
|
64
|
+
- @modern-js/node-bundle-require@2.11.0
|
|
65
|
+
- @modern-js/upgrade@2.11.0
|
|
66
|
+
- @modern-js/plugin@2.11.0
|
|
67
|
+
- @modern-js/types@2.11.0
|
|
68
|
+
|
|
3
69
|
## 2.10.0
|
|
4
70
|
|
|
5
71
|
### Patch Changes
|
|
@@ -118,7 +118,7 @@ var analyze_default = ({
|
|
|
118
118
|
debug(`add Define Types`);
|
|
119
119
|
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
120
120
|
if ((0, import_utils.isDevCommand)()) {
|
|
121
|
-
const { entry } = (0, import_utils.minimist)(
|
|
121
|
+
const { entry } = (0, import_utils.minimist)((0, import_utils.getArgv)());
|
|
122
122
|
checkedEntries = await (0, import_getSelectedEntries.getSelectedEntries)(
|
|
123
123
|
typeof entry === "string" ? entry.split(",") : entry,
|
|
124
124
|
entrypoints
|
|
@@ -31,12 +31,12 @@ __export(builder_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(builder_exports);
|
|
33
33
|
var import_utils = require("@modern-js/utils");
|
|
34
|
-
var import_builder_rspack_provider = require("@modern-js/builder-rspack-provider");
|
|
35
34
|
async function createBuilderGenerator(bundler) {
|
|
36
35
|
if (bundler === "rspack") {
|
|
37
36
|
try {
|
|
38
37
|
const { createRspackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-rspack")));
|
|
39
|
-
const
|
|
38
|
+
const { getRspackVersion } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-rspack-provider")));
|
|
39
|
+
const version = await getRspackVersion();
|
|
40
40
|
import_utils.logger.info(`Using Rspack v${version} 🦀`);
|
|
41
41
|
return createRspackBuilderForModern;
|
|
42
42
|
} catch (_) {
|
|
@@ -43,8 +43,8 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
43
43
|
async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
|
44
44
|
const builderConfig = api.getNormalizedConfig();
|
|
45
45
|
const { normalizedConfig: normalizedConfig2 } = options;
|
|
46
|
+
applyRouterPlugin(chain, options);
|
|
46
47
|
if ((0, import_utils.isSSR)(normalizedConfig2)) {
|
|
47
|
-
applyRouterPlugin(chain, options);
|
|
48
48
|
await applySSRLoaderEntry(chain, options, isServer);
|
|
49
49
|
}
|
|
50
50
|
if (["node", "service-worker"].includes(target)) {
|
|
@@ -71,9 +71,9 @@ class RouterPlugin {
|
|
|
71
71
|
chunks: true,
|
|
72
72
|
ids: true
|
|
73
73
|
});
|
|
74
|
-
const { publicPath, chunks = [] } = stats;
|
|
74
|
+
const { publicPath, chunks = [], assetsByChunkName } = stats;
|
|
75
75
|
const routeAssets = {};
|
|
76
|
-
const { namedChunkGroups
|
|
76
|
+
const { namedChunkGroups } = stats;
|
|
77
77
|
if (!namedChunkGroups || !assetsByChunkName) {
|
|
78
78
|
import_utils.logger.warn(
|
|
79
79
|
"Route manifest does not exist, performance will be affected"
|
|
@@ -81,14 +81,17 @@ class RouterPlugin {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
const referenceCssAssets = chunkGroup.assets.filter((asset) => /\.css$/.test(asset.name)).map((asset) => {
|
|
85
|
+
const item = asset.name;
|
|
86
|
+
return publicPath ? normalizePath(publicPath) + item : item;
|
|
87
|
+
});
|
|
88
|
+
routeAssets[name] = {
|
|
89
|
+
chunkIds: chunkGroup.chunks,
|
|
90
|
+
assets: assetsByChunkName[name].map(
|
|
91
|
+
(item) => publicPath ? normalizePath(publicPath) + item : item
|
|
92
|
+
),
|
|
93
|
+
referenceCssAssets
|
|
94
|
+
};
|
|
92
95
|
}
|
|
93
96
|
const manifest = {
|
|
94
97
|
routeAssets
|
|
@@ -96,8 +99,10 @@ class RouterPlugin {
|
|
|
96
99
|
const injectedContent = `
|
|
97
100
|
;(function(){
|
|
98
101
|
window.${import_constants2.ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
|
|
99
|
-
if (k === "assets") {
|
|
100
|
-
return
|
|
102
|
+
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
|
103
|
+
return v.map((item) => {
|
|
104
|
+
return item.replace(publicPath, "");
|
|
105
|
+
});
|
|
101
106
|
}
|
|
102
107
|
return v;
|
|
103
108
|
})};
|
|
@@ -221,7 +221,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import * as path from "path";
|
|
224
|
-
import { createDebugger, findExists, fs, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
|
|
224
|
+
import { createDebugger, findExists, fs, isApiOnly, minimist, getCommand, isDevCommand, getArgv } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
226
|
import { printInstructions } from "../utils/printInstructions";
|
|
227
227
|
import { generateRoutes } from "../utils/routes";
|
|
@@ -358,7 +358,7 @@ var analyze_default = function(param) {
|
|
|
358
358
|
3,
|
|
359
359
|
11
|
|
360
360
|
];
|
|
361
|
-
entry = minimist(
|
|
361
|
+
entry = minimist(getArgv()).entry;
|
|
362
362
|
return [
|
|
363
363
|
4,
|
|
364
364
|
getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
|
|
@@ -123,27 +123,26 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
import { logger } from "@modern-js/utils";
|
|
126
|
-
import { getRspackVersion } from "@modern-js/builder-rspack-provider";
|
|
127
126
|
function createBuilderGenerator(bundler) {
|
|
128
127
|
return _createBuilderGenerator.apply(this, arguments);
|
|
129
128
|
}
|
|
130
129
|
function _createBuilderGenerator() {
|
|
131
130
|
_createBuilderGenerator = _asyncToGenerator(function(bundler) {
|
|
132
|
-
var createRspackBuilderForModern, version, _, createWebpackBuilderForModern;
|
|
131
|
+
var createRspackBuilderForModern, getRspackVersion, version, _, createWebpackBuilderForModern;
|
|
133
132
|
return __generator(this, function(_state) {
|
|
134
133
|
switch(_state.label){
|
|
135
134
|
case 0:
|
|
136
135
|
if (!(bundler === "rspack")) return [
|
|
137
136
|
3,
|
|
138
|
-
|
|
137
|
+
6
|
|
139
138
|
];
|
|
140
139
|
_state.label = 1;
|
|
141
140
|
case 1:
|
|
142
141
|
_state.trys.push([
|
|
143
142
|
1,
|
|
144
|
-
|
|
143
|
+
5,
|
|
145
144
|
,
|
|
146
|
-
|
|
145
|
+
6
|
|
147
146
|
]);
|
|
148
147
|
return [
|
|
149
148
|
4,
|
|
@@ -153,24 +152,30 @@ function _createBuilderGenerator() {
|
|
|
153
152
|
createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
|
|
154
153
|
return [
|
|
155
154
|
4,
|
|
156
|
-
|
|
155
|
+
import("@modern-js/builder-rspack-provider")
|
|
157
156
|
];
|
|
158
157
|
case 3:
|
|
158
|
+
getRspackVersion = _state.sent().getRspackVersion;
|
|
159
|
+
return [
|
|
160
|
+
4,
|
|
161
|
+
getRspackVersion()
|
|
162
|
+
];
|
|
163
|
+
case 4:
|
|
159
164
|
version = _state.sent();
|
|
160
165
|
logger.info("Using Rspack v".concat(version, " \uD83E\uDD80"));
|
|
161
166
|
return [
|
|
162
167
|
2,
|
|
163
168
|
createRspackBuilderForModern
|
|
164
169
|
];
|
|
165
|
-
case
|
|
170
|
+
case 5:
|
|
166
171
|
_ = _state.sent();
|
|
167
172
|
throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
|
|
168
|
-
case
|
|
173
|
+
case 6:
|
|
169
174
|
return [
|
|
170
175
|
4,
|
|
171
176
|
import("./builder-webpack")
|
|
172
177
|
];
|
|
173
|
-
case
|
|
178
|
+
case 7:
|
|
174
179
|
createWebpackBuilderForModern = _state.sent().createWebpackBuilderForModern;
|
|
175
180
|
return [
|
|
176
181
|
2,
|
|
@@ -151,11 +151,11 @@ var builderPluginAdapterSSR = function(options) {
|
|
|
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
153
|
normalizedConfig2 = options.normalizedConfig;
|
|
154
|
+
applyRouterPlugin(chain, options);
|
|
154
155
|
if (!isSSR(normalizedConfig2)) return [
|
|
155
156
|
3,
|
|
156
157
|
2
|
|
157
158
|
];
|
|
158
|
-
applyRouterPlugin(chain, options);
|
|
159
159
|
return [
|
|
160
160
|
4,
|
|
161
161
|
applySSRLoaderEntry(chain, options, isServer)
|
|
@@ -237,7 +237,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
237
237
|
name: PLUGIN_NAME,
|
|
238
238
|
stage: PROCESS_ASSETS_STAGE_REPORT
|
|
239
239
|
}, /*#__PURE__*/ _asyncToGenerator(function() {
|
|
240
|
-
var stats, publicPath, _stats_chunks, chunks, routeAssets, namedChunkGroups,
|
|
240
|
+
var stats, publicPath, _stats_chunks, chunks, assetsByChunkName, routeAssets, namedChunkGroups, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, referenceCssAssets, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, file, asset, newContent, filename;
|
|
241
241
|
return __generator(this, function(_state) {
|
|
242
242
|
switch(_state.label){
|
|
243
243
|
case 0:
|
|
@@ -249,9 +249,9 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
249
249
|
chunks: true,
|
|
250
250
|
ids: true
|
|
251
251
|
});
|
|
252
|
-
publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks;
|
|
252
|
+
publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, assetsByChunkName = stats.assetsByChunkName;
|
|
253
253
|
routeAssets = {};
|
|
254
|
-
namedChunkGroups = stats.namedChunkGroups
|
|
254
|
+
namedChunkGroups = stats.namedChunkGroups;
|
|
255
255
|
if (!namedChunkGroups || !assetsByChunkName) {
|
|
256
256
|
logger.warn("Route manifest does not exist, performance will be affected");
|
|
257
257
|
return [
|
|
@@ -262,14 +262,19 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
262
262
|
try {
|
|
263
263
|
for(_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
264
264
|
_step_value = _slicedToArray(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
referenceCssAssets = chunkGroup.assets.filter(function(asset) {
|
|
266
|
+
return /\.css$/.test(asset.name);
|
|
267
|
+
}).map(function(asset) {
|
|
268
|
+
var item = asset.name;
|
|
269
|
+
return publicPath ? normalizePath(publicPath) + item : item;
|
|
270
|
+
});
|
|
271
|
+
routeAssets[name] = {
|
|
272
|
+
chunkIds: chunkGroup.chunks,
|
|
273
|
+
assets: assetsByChunkName[name].map(function(item) {
|
|
274
|
+
return publicPath ? normalizePath(publicPath) + item : item;
|
|
275
|
+
}),
|
|
276
|
+
referenceCssAssets: referenceCssAssets
|
|
277
|
+
};
|
|
273
278
|
}
|
|
274
279
|
} catch (err) {
|
|
275
280
|
_didIteratorError = true;
|
|
@@ -289,8 +294,10 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
289
294
|
routeAssets: routeAssets
|
|
290
295
|
};
|
|
291
296
|
injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest, function(k, v) {
|
|
292
|
-
if (k === "assets") {
|
|
293
|
-
return
|
|
297
|
+
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
|
298
|
+
return v.map(function(item) {
|
|
299
|
+
return item.replace(publicPath, "");
|
|
300
|
+
});
|
|
294
301
|
}
|
|
295
302
|
return v;
|
|
296
303
|
}), ";\n })();\n ");
|
|
@@ -123,7 +123,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
import { cli } from "@modern-js/core";
|
|
126
|
-
import { chalk, clearConsole, logger, program } from "@modern-js/utils";
|
|
126
|
+
import { chalk, clearConsole, getArgv, logger, program } from "@modern-js/utils";
|
|
127
127
|
function restart(hooksRunner, filename) {
|
|
128
128
|
return _restart.apply(this, arguments);
|
|
129
129
|
}
|
|
@@ -170,7 +170,7 @@ function _restart() {
|
|
|
170
170
|
];
|
|
171
171
|
case 5:
|
|
172
172
|
if (!hasGetError) {
|
|
173
|
-
program.parse(
|
|
173
|
+
program.parse(getArgv());
|
|
174
174
|
}
|
|
175
175
|
return [
|
|
176
176
|
7
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
isApiOnly,
|
|
7
7
|
minimist,
|
|
8
8
|
getCommand,
|
|
9
|
-
isDevCommand
|
|
9
|
+
isDevCommand,
|
|
10
|
+
getArgv
|
|
10
11
|
} from "@modern-js/utils";
|
|
11
12
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
12
13
|
import { printInstructions } from "../utils/printInstructions";
|
|
@@ -98,7 +99,7 @@ var analyze_default = ({
|
|
|
98
99
|
debug(`add Define Types`);
|
|
99
100
|
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
100
101
|
if (isDevCommand()) {
|
|
101
|
-
const { entry } = minimist(
|
|
102
|
+
const { entry } = minimist(getArgv());
|
|
102
103
|
checkedEntries = await getSelectedEntries(
|
|
103
104
|
typeof entry === "string" ? entry.split(",") : entry,
|
|
104
105
|
entrypoints
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { logger } from "@modern-js/utils";
|
|
2
|
-
import { getRspackVersion } from "@modern-js/builder-rspack-provider";
|
|
3
2
|
async function createBuilderGenerator(bundler) {
|
|
4
3
|
if (bundler === "rspack") {
|
|
5
4
|
try {
|
|
6
5
|
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
|
6
|
+
const { getRspackVersion } = await import("@modern-js/builder-rspack-provider");
|
|
7
7
|
const version = await getRspackVersion();
|
|
8
8
|
logger.info(`Using Rspack v${version} 🦀`);
|
|
9
9
|
return createRspackBuilderForModern;
|
|
@@ -23,8 +23,8 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
23
23
|
async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
|
24
24
|
const builderConfig = api.getNormalizedConfig();
|
|
25
25
|
const { normalizedConfig: normalizedConfig2 } = options;
|
|
26
|
+
applyRouterPlugin(chain, options);
|
|
26
27
|
if (isSSR(normalizedConfig2)) {
|
|
27
|
-
applyRouterPlugin(chain, options);
|
|
28
28
|
await applySSRLoaderEntry(chain, options, isServer);
|
|
29
29
|
}
|
|
30
30
|
if (["node", "service-worker"].includes(target)) {
|
|
@@ -39,9 +39,9 @@ class RouterPlugin {
|
|
|
39
39
|
chunks: true,
|
|
40
40
|
ids: true
|
|
41
41
|
});
|
|
42
|
-
const { publicPath, chunks = [] } = stats;
|
|
42
|
+
const { publicPath, chunks = [], assetsByChunkName } = stats;
|
|
43
43
|
const routeAssets = {};
|
|
44
|
-
const { namedChunkGroups
|
|
44
|
+
const { namedChunkGroups } = stats;
|
|
45
45
|
if (!namedChunkGroups || !assetsByChunkName) {
|
|
46
46
|
logger.warn(
|
|
47
47
|
"Route manifest does not exist, performance will be affected"
|
|
@@ -49,14 +49,17 @@ class RouterPlugin {
|
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const referenceCssAssets = chunkGroup.assets.filter((asset) => /\.css$/.test(asset.name)).map((asset) => {
|
|
53
|
+
const item = asset.name;
|
|
54
|
+
return publicPath ? normalizePath(publicPath) + item : item;
|
|
55
|
+
});
|
|
56
|
+
routeAssets[name] = {
|
|
57
|
+
chunkIds: chunkGroup.chunks,
|
|
58
|
+
assets: assetsByChunkName[name].map(
|
|
59
|
+
(item) => publicPath ? normalizePath(publicPath) + item : item
|
|
60
|
+
),
|
|
61
|
+
referenceCssAssets
|
|
62
|
+
};
|
|
60
63
|
}
|
|
61
64
|
const manifest = {
|
|
62
65
|
routeAssets
|
|
@@ -64,8 +67,10 @@ class RouterPlugin {
|
|
|
64
67
|
const injectedContent = `
|
|
65
68
|
;(function(){
|
|
66
69
|
window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
|
|
67
|
-
if (k === "assets") {
|
|
68
|
-
return
|
|
70
|
+
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
|
71
|
+
return v.map((item) => {
|
|
72
|
+
return item.replace(publicPath, "");
|
|
73
|
+
});
|
|
69
74
|
}
|
|
70
75
|
return v;
|
|
71
76
|
})};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { cli } from "@modern-js/core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
chalk,
|
|
4
|
+
clearConsole,
|
|
5
|
+
getArgv,
|
|
6
|
+
logger,
|
|
7
|
+
program
|
|
8
|
+
} from "@modern-js/utils";
|
|
3
9
|
async function restart(hooksRunner, filename) {
|
|
4
10
|
clearConsole();
|
|
5
11
|
logger.info(`Restart because ${chalk.yellow(filename)} is changed...
|
|
@@ -13,7 +19,7 @@ async function restart(hooksRunner, filename) {
|
|
|
13
19
|
hasGetError = true;
|
|
14
20
|
} finally {
|
|
15
21
|
if (!hasGetError) {
|
|
16
|
-
program.parse(
|
|
22
|
+
program.parse(getArgv());
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
25
|
}
|
|
@@ -23,7 +23,9 @@ const NESTED_ROUTE = {
|
|
|
23
23
|
PAGE_LOADER_FILE: "page.loader",
|
|
24
24
|
LOADING_FILE: "loading",
|
|
25
25
|
ERROR_FILE: "error",
|
|
26
|
-
LOADER_FILE: "loader"
|
|
26
|
+
LOADER_FILE: "loader",
|
|
27
|
+
SPLATE_FILE: "$",
|
|
28
|
+
SPLATE_LOADER_FILE: "$.loader"
|
|
27
29
|
};
|
|
28
30
|
const APP_CONFIG_NAME = "config";
|
|
29
31
|
const APP_INIT_EXPORTED = "init";
|
|
@@ -38,7 +38,8 @@ import {
|
|
|
38
38
|
getEntryOptions,
|
|
39
39
|
SERVER_BUNDLE_DIRECTORY,
|
|
40
40
|
MAIN_ENTRY_NAME,
|
|
41
|
-
removeTailSlash
|
|
41
|
+
removeTailSlash,
|
|
42
|
+
SERVER_WORKER_BUNDLE_DIRECTORY
|
|
42
43
|
} from "@modern-js/utils";
|
|
43
44
|
import { walkDirectory } from "./utils";
|
|
44
45
|
const applyBaseUrl = (baseUrl, routes) => {
|
|
@@ -101,7 +102,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
101
102
|
const {
|
|
102
103
|
html: { disableHtmlFolder },
|
|
103
104
|
output: { distPath: { html: htmlPath } = {} },
|
|
104
|
-
server: { baseUrl, routes, ssr, ssrByEntries }
|
|
105
|
+
server: { baseUrl, routes, ssr, ssrByEntries, worker }
|
|
105
106
|
} = config;
|
|
106
107
|
const { packageName } = appContext;
|
|
107
108
|
let htmlRoutes = entrypoints.reduce(
|
|
@@ -113,6 +114,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
113
114
|
packageName
|
|
114
115
|
);
|
|
115
116
|
const isSSR = Boolean(entryOptions);
|
|
117
|
+
const isWorker = Boolean(worker);
|
|
116
118
|
const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
|
|
117
119
|
let route = {
|
|
118
120
|
urlPath: `/${entryName === MAIN_ENTRY_NAME ? "" : entryName}`,
|
|
@@ -125,6 +127,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
125
127
|
isSPA: true,
|
|
126
128
|
isSSR,
|
|
127
129
|
responseHeaders: resHeaders,
|
|
130
|
+
worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
|
|
128
131
|
bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
|
|
129
132
|
};
|
|
130
133
|
if (routes == null ? void 0 : routes.hasOwnProperty(entryName)) {
|
|
@@ -49,12 +49,12 @@ import {
|
|
|
49
49
|
isDevCommand
|
|
50
50
|
} from "@modern-js/utils";
|
|
51
51
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
52
|
-
import { createBuilderForModern } from "../builder";
|
|
53
52
|
import { printInstructions } from "../utils/printInstructions";
|
|
54
53
|
import { generateRoutes } from "../utils/routes";
|
|
55
54
|
import { emitResolvedConfig } from "../utils/config";
|
|
56
55
|
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
57
56
|
import { initialNormalizedConfig } from "../config";
|
|
57
|
+
import { createBuilderGenerator } from "../builder";
|
|
58
58
|
import {
|
|
59
59
|
getServerLoadersFile,
|
|
60
60
|
isPageComponentFile,
|
|
@@ -67,7 +67,9 @@ import {
|
|
|
67
67
|
APP_INIT_IMPORTED
|
|
68
68
|
} from "./constants";
|
|
69
69
|
const debug = createDebugger("plugin-analyze");
|
|
70
|
-
var analyze_default = (
|
|
70
|
+
var analyze_default = ({
|
|
71
|
+
bundler
|
|
72
|
+
}) => ({
|
|
71
73
|
name: "@modern-js/plugin-analyze",
|
|
72
74
|
setup: (api) => {
|
|
73
75
|
let pagesDir = [];
|
|
@@ -159,56 +161,55 @@ var analyze_default = () => ({
|
|
|
159
161
|
if (buildCommands.includes(command)) {
|
|
160
162
|
let _b;
|
|
161
163
|
const normalizedConfig = api.useResolvedConfigContext();
|
|
164
|
+
const createBuilderForModern = yield createBuilderGenerator(bundler);
|
|
162
165
|
const builder = yield createBuilderForModern({
|
|
163
166
|
normalizedConfig,
|
|
164
167
|
appContext,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
onBeforeBuild(_0) {
|
|
169
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
170
|
+
const hookRunners2 = api.useHookRunners();
|
|
171
|
+
yield generateRoutes(appContext);
|
|
172
|
+
yield hookRunners2.beforeBuild({
|
|
173
|
+
bundlerConfigs
|
|
171
174
|
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
appContext,
|
|
192
|
-
normalizedConfig
|
|
193
|
-
);
|
|
194
|
-
}
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
onAfterBuild(_0) {
|
|
178
|
+
return __async(this, arguments, function* ({ stats }) {
|
|
179
|
+
const hookRunners2 = api.useHookRunners();
|
|
180
|
+
yield hookRunners2.afterBuild({ stats });
|
|
181
|
+
yield emitResolvedConfig(
|
|
182
|
+
appContext.appDirectory,
|
|
183
|
+
normalizedConfig
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
onDevCompileDone(_0) {
|
|
188
|
+
return __async(this, arguments, function* ({ isFirstCompile }) {
|
|
189
|
+
const hookRunners2 = api.useHookRunners();
|
|
190
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
191
|
+
hookRunners2.afterDev();
|
|
192
|
+
if (isFirstCompile) {
|
|
193
|
+
printInstructions(hookRunners2, appContext, normalizedConfig);
|
|
195
194
|
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
onBeforeCreateCompiler(_0) {
|
|
199
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
200
|
+
const hookRunners2 = api.useHookRunners();
|
|
201
|
+
yield hookRunners2.beforeCreateCompiler({
|
|
202
|
+
bundlerConfigs
|
|
196
203
|
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
},
|
|
206
|
-
onAfterCreateCompiler(_0) {
|
|
207
|
-
return __async(this, arguments, function* ({ compiler }) {
|
|
208
|
-
const hookRunners2 = api.useHookRunners();
|
|
209
|
-
yield hookRunners2.afterCreateCompiler({ compiler });
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
onAfterCreateCompiler(_0) {
|
|
207
|
+
return __async(this, arguments, function* ({ compiler }) {
|
|
208
|
+
const hookRunners2 = api.useHookRunners();
|
|
209
|
+
yield hookRunners2.afterCreateCompiler({
|
|
210
|
+
compiler
|
|
210
211
|
});
|
|
211
|
-
}
|
|
212
|
+
});
|
|
212
213
|
}
|
|
213
214
|
});
|
|
214
215
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
@@ -251,7 +252,7 @@ var analyze_default = () => ({
|
|
|
251
252
|
},
|
|
252
253
|
resolvedConfig({ resolved }) {
|
|
253
254
|
const appContext = api.useAppContext();
|
|
254
|
-
const config = initialNormalizedConfig(resolved, appContext);
|
|
255
|
+
const config = initialNormalizedConfig(resolved, appContext, bundler);
|
|
255
256
|
return {
|
|
256
257
|
resolved: config
|
|
257
258
|
};
|