@modern-js/app-tools 2.27.0 → 2.27.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/dist/cjs/analyze/utils.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +75 -33
- package/dist/cjs/commands/dev.js +3 -2
- package/dist/cjs/index.js +4 -0
- package/dist/esm/analyze/utils.js +2 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -1
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +101 -41
- package/dist/esm/commands/dev.js +5 -3
- package/dist/esm/index.js +4 -3
- package/dist/esm-node/analyze/utils.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +6 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +75 -33
- package/dist/esm-node/commands/dev.js +3 -2
- package/dist/esm-node/index.js +3 -2
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +2 -2
- package/dist/types/analyze/nestedRoutes.d.ts +2 -2
- package/dist/types/analyze/templates.d.ts +3 -3
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +8 -0
- package/dist/types/commands/dev.d.ts +4 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types/hooks.d.ts +2 -2
- package/package.json +12 -12
|
@@ -87,8 +87,13 @@ function applyRouterPlugin(chain, options) {
|
|
|
87
87
|
const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
88
88
|
const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
89
89
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
90
|
+
const minimize = !normalizedConfig.output.disableMinimize && process.env.NODE_ENV === "production";
|
|
90
91
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
91
|
-
chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin
|
|
92
|
+
chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin, [
|
|
93
|
+
{
|
|
94
|
+
minimize
|
|
95
|
+
}
|
|
96
|
+
]);
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "RouterPlugin", {
|
|
|
8
8
|
return RouterPlugin;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _define_property = require("@swc/helpers/_/_define_property");
|
|
11
12
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
13
|
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
13
14
|
const _lodash = require("@modern-js/utils/lodash");
|
|
@@ -25,6 +26,22 @@ class RouterPlugin {
|
|
|
25
26
|
}
|
|
26
27
|
return false;
|
|
27
28
|
}
|
|
29
|
+
getEntryChunks(compilation, chunks) {
|
|
30
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
31
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
32
|
+
const entryChunks = [
|
|
33
|
+
...chunks
|
|
34
|
+
].filter((chunk) => {
|
|
35
|
+
var _chunk_names;
|
|
36
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
37
|
+
});
|
|
38
|
+
return entryChunks;
|
|
39
|
+
}
|
|
40
|
+
getEntryChunkFiles(entryChunks) {
|
|
41
|
+
return entryChunks.map((chunk) => [
|
|
42
|
+
...chunk.files || []
|
|
43
|
+
].find((fname) => fname.includes(".js")));
|
|
44
|
+
}
|
|
28
45
|
apply(compiler) {
|
|
29
46
|
const { target } = compiler.options;
|
|
30
47
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
@@ -39,7 +56,8 @@ class RouterPlugin {
|
|
|
39
56
|
}
|
|
40
57
|
return path;
|
|
41
58
|
};
|
|
42
|
-
const
|
|
59
|
+
const chunkToSource = /* @__PURE__ */ new Map();
|
|
60
|
+
const chunkToMap = /* @__PURE__ */ new Map();
|
|
43
61
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
44
62
|
compilation.hooks.processAssets.tapPromise({
|
|
45
63
|
name: PLUGIN_NAME,
|
|
@@ -55,14 +73,37 @@ class RouterPlugin {
|
|
|
55
73
|
if (!namedChunkGroups) {
|
|
56
74
|
return;
|
|
57
75
|
}
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
77
|
+
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
78
|
+
...chunk.files || []
|
|
79
|
+
].find((fname) => fname.includes(".js")));
|
|
80
|
+
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
81
|
+
for (let i = 0; i <= entryChunkFiles.length - 1; i++) {
|
|
82
|
+
const file = entryChunkFiles[i];
|
|
83
|
+
const chunkId = entryChunkFileIds[i];
|
|
84
|
+
const asset = compilation.assets[file];
|
|
85
|
+
if (!asset) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const { map } = asset.sourceAndMap();
|
|
89
|
+
chunkToMap.set(chunkId, map);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
compilation.hooks.processAssets.tapPromise({
|
|
93
|
+
name: PLUGIN_NAME,
|
|
94
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
95
|
+
}, async () => {
|
|
96
|
+
const stats = compilation.getStats().toJson({
|
|
97
|
+
all: false,
|
|
98
|
+
chunkGroups: true,
|
|
99
|
+
chunks: true,
|
|
100
|
+
ids: true
|
|
65
101
|
});
|
|
102
|
+
const { chunks = [], namedChunkGroups } = stats;
|
|
103
|
+
if (!namedChunkGroups) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
66
107
|
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
67
108
|
...chunk.files || []
|
|
68
109
|
].find((fname) => fname.includes(".js")));
|
|
@@ -74,11 +115,8 @@ class RouterPlugin {
|
|
|
74
115
|
if (!asset) {
|
|
75
116
|
continue;
|
|
76
117
|
}
|
|
77
|
-
const { source
|
|
78
|
-
|
|
79
|
-
source,
|
|
80
|
-
map
|
|
81
|
-
});
|
|
118
|
+
const { source } = asset.sourceAndMap();
|
|
119
|
+
chunkToSource.set(chunkId, source);
|
|
82
120
|
}
|
|
83
121
|
});
|
|
84
122
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -111,6 +149,7 @@ class RouterPlugin {
|
|
|
111
149
|
const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
|
|
112
150
|
routeAssets[name] = {
|
|
113
151
|
chunkIds: chunkGroup.chunks,
|
|
152
|
+
chunkName: chunkGroup.name,
|
|
114
153
|
assets,
|
|
115
154
|
referenceCssAssets
|
|
116
155
|
};
|
|
@@ -126,31 +165,29 @@ class RouterPlugin {
|
|
|
126
165
|
const manifest = {
|
|
127
166
|
routeAssets
|
|
128
167
|
};
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const entryChunks = [
|
|
132
|
-
...chunks
|
|
133
|
-
].filter((chunk) => {
|
|
134
|
-
var _chunk_names;
|
|
135
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
136
|
-
});
|
|
137
|
-
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
138
|
-
...chunk.files || []
|
|
139
|
-
].find((fname) => fname.includes(".js")));
|
|
168
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
169
|
+
const entryChunkFiles = this.getEntryChunkFiles(entryChunks);
|
|
140
170
|
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
141
|
-
for (let i = 0; i
|
|
171
|
+
for (let i = 0; i < entryChunkFiles.length; i++) {
|
|
142
172
|
const file = entryChunkFiles[i];
|
|
173
|
+
const chunkNames = entryChunks[i].names;
|
|
143
174
|
const chunkId = entryChunkFileIds[i];
|
|
144
175
|
const asset = compilation.assets[file];
|
|
145
176
|
if (!asset || !chunkId) {
|
|
146
177
|
continue;
|
|
147
178
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
179
|
+
let relatedAssets = {};
|
|
180
|
+
if (entryChunkFiles.length > 1) {
|
|
181
|
+
Object.keys(routeAssets).forEach((routeId) => {
|
|
182
|
+
const segments = routeId.split("_");
|
|
183
|
+
const chunkName = segments[0];
|
|
184
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
|
185
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
relatedAssets = routeAssets;
|
|
190
|
+
}
|
|
154
191
|
const manifest2 = {
|
|
155
192
|
routeAssets: relatedAssets
|
|
156
193
|
};
|
|
@@ -166,12 +203,13 @@ class RouterPlugin {
|
|
|
166
203
|
})};
|
|
167
204
|
})();
|
|
168
205
|
`;
|
|
169
|
-
const
|
|
206
|
+
const source = chunkToSource.get(chunkId);
|
|
207
|
+
const map = chunkToMap.get(chunkId);
|
|
170
208
|
const newContent = `${injectedContent}${source.toString()}`;
|
|
171
209
|
const result = await (0, _esbuild.transform)(newContent, {
|
|
172
210
|
loader: _path.default.extname(file).slice(1),
|
|
173
211
|
sourcemap: true,
|
|
174
|
-
minify:
|
|
212
|
+
minify: this.minimize
|
|
175
213
|
});
|
|
176
214
|
const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
177
215
|
compilation.updateAsset(
|
|
@@ -194,4 +232,8 @@ class RouterPlugin {
|
|
|
194
232
|
});
|
|
195
233
|
});
|
|
196
234
|
}
|
|
235
|
+
constructor(options) {
|
|
236
|
+
_define_property._(this, "minimize", false);
|
|
237
|
+
this.minimize = options.minimize;
|
|
238
|
+
}
|
|
197
239
|
}
|
package/dist/cjs/commands/dev.js
CHANGED
|
@@ -15,7 +15,7 @@ const _createServer = require("../utils/createServer");
|
|
|
15
15
|
const _routes = require("../utils/routes");
|
|
16
16
|
const _config = require("../utils/config");
|
|
17
17
|
const _getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
18
|
-
const dev = async (api, options) => {
|
|
18
|
+
const dev = async (api, options, devServerOptions = {}) => {
|
|
19
19
|
var _normalizedConfig_tools;
|
|
20
20
|
if (options.analyze) {
|
|
21
21
|
process.env.BUNDLE_ANALYZE = "true";
|
|
@@ -58,7 +58,8 @@ const dev = async (api, options) => {
|
|
|
58
58
|
pwd: appDirectory,
|
|
59
59
|
config: normalizedConfig,
|
|
60
60
|
serverConfigFile,
|
|
61
|
-
internalPlugins: (0, _createServer.injectDataLoaderPlugin)(serverInternalPlugins)
|
|
61
|
+
internalPlugins: (0, _createServer.injectDataLoaderPlugin)(serverInternalPlugins),
|
|
62
|
+
...devServerOptions
|
|
62
63
|
};
|
|
63
64
|
if (apiOnly) {
|
|
64
65
|
var _normalizedConfig_dev;
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,6 +13,9 @@ _export(exports, {
|
|
|
13
13
|
mergeConfig: function() {
|
|
14
14
|
return _core.mergeConfig;
|
|
15
15
|
},
|
|
16
|
+
dev: function() {
|
|
17
|
+
return _commands.dev;
|
|
18
|
+
},
|
|
16
19
|
devCommand: function() {
|
|
17
20
|
return devCommand;
|
|
18
21
|
},
|
|
@@ -41,6 +44,7 @@ const _locale = require("./locale");
|
|
|
41
44
|
const _restart = require("./utils/restart");
|
|
42
45
|
const _generateWatchFiles = require("./utils/generateWatchFiles");
|
|
43
46
|
const _core = require("@modern-js/core");
|
|
47
|
+
const _commands = require("./commands");
|
|
44
48
|
_export_star._(require("./defineConfig"), exports);
|
|
45
49
|
_export_star._(require("./types"), exports);
|
|
46
50
|
const devCommand = async (program, api) => {
|
|
@@ -127,8 +127,13 @@ function applyRouterPlugin(chain, options) {
|
|
|
127
127
|
var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
128
128
|
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
129
129
|
var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
130
|
+
var minimize = !normalizedConfig.output.disableMinimize && process.env.NODE_ENV === "production";
|
|
130
131
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
131
|
-
chain.plugin("route-plugin").use(RouterPlugin
|
|
132
|
+
chain.plugin("route-plugin").use(RouterPlugin, [
|
|
133
|
+
{
|
|
134
|
+
minimize: minimize
|
|
135
|
+
}
|
|
136
|
+
]);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
function applyFilterEntriesBySSRConfig(param) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
3
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
4
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
5
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
5
6
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
6
7
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
@@ -13,8 +14,10 @@ import { transform } from "esbuild";
|
|
|
13
14
|
var PLUGIN_NAME = "ModernjsRoutePlugin";
|
|
14
15
|
export var RouterPlugin = /* @__PURE__ */ function() {
|
|
15
16
|
"use strict";
|
|
16
|
-
function RouterPlugin2() {
|
|
17
|
+
function RouterPlugin2(options) {
|
|
17
18
|
_class_call_check(this, RouterPlugin2);
|
|
19
|
+
_define_property(this, "minimize", false);
|
|
20
|
+
this.minimize = options.minimize;
|
|
18
21
|
}
|
|
19
22
|
_create_class(RouterPlugin2, [
|
|
20
23
|
{
|
|
@@ -29,9 +32,36 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
29
32
|
return false;
|
|
30
33
|
}
|
|
31
34
|
},
|
|
35
|
+
{
|
|
36
|
+
key: "getEntryChunks",
|
|
37
|
+
value: function getEntryChunks(compilation, chunks) {
|
|
38
|
+
var entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
39
|
+
var entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
|
40
|
+
return entrypoint[0];
|
|
41
|
+
});
|
|
42
|
+
var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
43
|
+
var _chunk_names;
|
|
44
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
|
|
45
|
+
return entryChunkIds.includes(name);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return entryChunks;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "getEntryChunkFiles",
|
|
53
|
+
value: function getEntryChunkFiles(entryChunks) {
|
|
54
|
+
return entryChunks.map(function(chunk) {
|
|
55
|
+
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
56
|
+
return fname.includes(".js");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
32
61
|
{
|
|
33
62
|
key: "apply",
|
|
34
63
|
value: function apply(compiler) {
|
|
64
|
+
var _this = this;
|
|
35
65
|
var target = compiler.options.target;
|
|
36
66
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
37
67
|
return;
|
|
@@ -45,13 +75,15 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
45
75
|
}
|
|
46
76
|
return path2;
|
|
47
77
|
};
|
|
48
|
-
var
|
|
78
|
+
var chunkToSource = /* @__PURE__ */ new Map();
|
|
79
|
+
var chunkToMap = /* @__PURE__ */ new Map();
|
|
49
80
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
|
|
81
|
+
var _this1 = _this;
|
|
50
82
|
compilation.hooks.processAssets.tapPromise({
|
|
51
83
|
name: PLUGIN_NAME,
|
|
52
84
|
stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING
|
|
53
85
|
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
54
|
-
var stats, _stats_chunks, chunks, namedChunkGroups,
|
|
86
|
+
var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, map;
|
|
55
87
|
return _ts_generator(this, function(_state) {
|
|
56
88
|
stats = compilation.getStats().toJson({
|
|
57
89
|
all: false,
|
|
@@ -65,16 +97,50 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
65
97
|
2
|
|
66
98
|
];
|
|
67
99
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
73
|
-
var _chunk_names;
|
|
74
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
|
|
75
|
-
return entryChunkIds.includes(name);
|
|
100
|
+
entryChunks = _this1.getEntryChunks(compilation, chunks);
|
|
101
|
+
entryChunkFiles = entryChunks.map(function(chunk) {
|
|
102
|
+
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
103
|
+
return fname.includes(".js");
|
|
76
104
|
});
|
|
77
105
|
});
|
|
106
|
+
entryChunkFileIds = entryChunks.map(function(chunk) {
|
|
107
|
+
return chunk.id;
|
|
108
|
+
});
|
|
109
|
+
for (i = 0; i <= entryChunkFiles.length - 1; i++) {
|
|
110
|
+
file = entryChunkFiles[i];
|
|
111
|
+
chunkId = entryChunkFileIds[i];
|
|
112
|
+
asset = compilation.assets[file];
|
|
113
|
+
if (!asset) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
map = asset.sourceAndMap().map;
|
|
117
|
+
chunkToMap.set(chunkId, map);
|
|
118
|
+
}
|
|
119
|
+
return [
|
|
120
|
+
2
|
|
121
|
+
];
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
var _this2 = _this;
|
|
125
|
+
compilation.hooks.processAssets.tapPromise({
|
|
126
|
+
name: PLUGIN_NAME,
|
|
127
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
128
|
+
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
129
|
+
var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, source;
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
stats = compilation.getStats().toJson({
|
|
132
|
+
all: false,
|
|
133
|
+
chunkGroups: true,
|
|
134
|
+
chunks: true,
|
|
135
|
+
ids: true
|
|
136
|
+
});
|
|
137
|
+
_stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
|
|
138
|
+
if (!namedChunkGroups) {
|
|
139
|
+
return [
|
|
140
|
+
2
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
entryChunks = _this2.getEntryChunks(compilation, chunks);
|
|
78
144
|
entryChunkFiles = entryChunks.map(function(chunk) {
|
|
79
145
|
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
80
146
|
return fname.includes(".js");
|
|
@@ -90,31 +156,30 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
90
156
|
if (!asset) {
|
|
91
157
|
continue;
|
|
92
158
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
source: source,
|
|
96
|
-
map: map
|
|
97
|
-
});
|
|
159
|
+
source = asset.sourceAndMap().source;
|
|
160
|
+
chunkToSource.set(chunkId, source);
|
|
98
161
|
}
|
|
99
162
|
return [
|
|
100
163
|
2
|
|
101
164
|
];
|
|
102
165
|
});
|
|
103
166
|
}));
|
|
167
|
+
var _this3 = _this;
|
|
104
168
|
compilation.hooks.processAssets.tapPromise({
|
|
105
169
|
name: PLUGIN_NAME,
|
|
106
170
|
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
107
171
|
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
108
|
-
var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest,
|
|
172
|
+
var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryChunks, entryChunkFiles, entryChunkFileIds, i;
|
|
109
173
|
return _ts_generator(this, function(_state) {
|
|
110
174
|
switch (_state.label) {
|
|
111
175
|
case 0:
|
|
112
176
|
_loop = function(i2) {
|
|
113
|
-
var file, chunkId, asset, relatedAssets, manifest2, injectedContent,
|
|
177
|
+
var file, chunkNames, chunkId, asset, relatedAssets, manifest2, injectedContent, source, map, newContent, result, newSource;
|
|
114
178
|
return _ts_generator(this, function(_state2) {
|
|
115
179
|
switch (_state2.label) {
|
|
116
180
|
case 0:
|
|
117
181
|
file = entryChunkFiles[i2];
|
|
182
|
+
chunkNames = entryChunks[i2].names;
|
|
118
183
|
chunkId = entryChunkFileIds[i2];
|
|
119
184
|
asset = compilation.assets[file];
|
|
120
185
|
if (!asset || !chunkId) {
|
|
@@ -124,11 +189,17 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
124
189
|
];
|
|
125
190
|
}
|
|
126
191
|
relatedAssets = {};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
192
|
+
if (entryChunkFiles.length > 1) {
|
|
193
|
+
Object.keys(routeAssets).forEach(function(routeId) {
|
|
194
|
+
var segments = routeId.split("_");
|
|
195
|
+
var chunkName = segments[0];
|
|
196
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
|
197
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
relatedAssets = routeAssets;
|
|
202
|
+
}
|
|
132
203
|
manifest2 = {
|
|
133
204
|
routeAssets: relatedAssets
|
|
134
205
|
};
|
|
@@ -140,14 +211,15 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
140
211
|
}
|
|
141
212
|
return v;
|
|
142
213
|
}), ";\n })();\n ");
|
|
143
|
-
|
|
214
|
+
source = chunkToSource.get(chunkId);
|
|
215
|
+
map = chunkToMap.get(chunkId);
|
|
144
216
|
newContent = "".concat(injectedContent).concat(source.toString());
|
|
145
217
|
return [
|
|
146
218
|
4,
|
|
147
219
|
transform(newContent, {
|
|
148
220
|
loader: path.extname(file).slice(1),
|
|
149
221
|
sourcemap: true,
|
|
150
|
-
minify:
|
|
222
|
+
minify: _this3.minimize
|
|
151
223
|
})
|
|
152
224
|
];
|
|
153
225
|
case 1:
|
|
@@ -198,6 +270,7 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
198
270
|
});
|
|
199
271
|
routeAssets[name] = {
|
|
200
272
|
chunkIds: chunkGroup.chunks,
|
|
273
|
+
chunkName: chunkGroup.name,
|
|
201
274
|
assets: assets,
|
|
202
275
|
referenceCssAssets: referenceCssAssets
|
|
203
276
|
};
|
|
@@ -227,28 +300,15 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
227
300
|
manifest = {
|
|
228
301
|
routeAssets: routeAssets
|
|
229
302
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return entrypoint[0];
|
|
233
|
-
});
|
|
234
|
-
entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
235
|
-
var _chunk_names;
|
|
236
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name2) {
|
|
237
|
-
return entryChunkIds.includes(name2);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
entryChunkFiles = entryChunks.map(function(chunk) {
|
|
241
|
-
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
242
|
-
return fname.includes(".js");
|
|
243
|
-
});
|
|
244
|
-
});
|
|
303
|
+
entryChunks = _this3.getEntryChunks(compilation, chunks);
|
|
304
|
+
entryChunkFiles = _this3.getEntryChunkFiles(entryChunks);
|
|
245
305
|
entryChunkFileIds = entryChunks.map(function(chunk) {
|
|
246
306
|
return chunk.id;
|
|
247
307
|
});
|
|
248
308
|
i = 0;
|
|
249
309
|
_state.label = 1;
|
|
250
310
|
case 1:
|
|
251
|
-
if (!(i
|
|
311
|
+
if (!(i < entryChunkFiles.length))
|
|
252
312
|
return [
|
|
253
313
|
3,
|
|
254
314
|
4
|
package/dist/esm/commands/dev.js
CHANGED
|
@@ -11,10 +11,12 @@ import { buildServerConfig } from "../utils/config";
|
|
|
11
11
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
12
12
|
export var dev = function() {
|
|
13
13
|
var _ref = _async_to_generator(function(api, options) {
|
|
14
|
-
var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
|
14
|
+
var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
|
15
|
+
var _arguments = arguments;
|
|
15
16
|
return _ts_generator(this, function(_state) {
|
|
16
17
|
switch (_state.label) {
|
|
17
18
|
case 0:
|
|
19
|
+
devServerOptions = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
|
|
18
20
|
if (options.analyze) {
|
|
19
21
|
process.env.BUNDLE_ANALYZE = "true";
|
|
20
22
|
}
|
|
@@ -58,7 +60,7 @@ export var dev = function() {
|
|
|
58
60
|
];
|
|
59
61
|
case 4:
|
|
60
62
|
serverInternalPlugins = _state.sent();
|
|
61
|
-
serverOptions = {
|
|
63
|
+
serverOptions = _object_spread({
|
|
62
64
|
dev: _object_spread({
|
|
63
65
|
port: port,
|
|
64
66
|
https: normalizedConfig.dev.https,
|
|
@@ -75,7 +77,7 @@ export var dev = function() {
|
|
|
75
77
|
config: normalizedConfig,
|
|
76
78
|
serverConfigFile: serverConfigFile,
|
|
77
79
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
78
|
-
};
|
|
80
|
+
}, devServerOptions);
|
|
79
81
|
if (!apiOnly)
|
|
80
82
|
return [
|
|
81
83
|
3,
|
package/dist/esm/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { i18n, localeKeys } from "./locale";
|
|
|
14
14
|
import { restart } from "./utils/restart";
|
|
15
15
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
16
16
|
export { mergeConfig } from "@modern-js/core";
|
|
17
|
+
export { dev } from "./commands";
|
|
17
18
|
export * from "./defineConfig";
|
|
18
19
|
export * from "./types";
|
|
19
20
|
export var devCommand = function() {
|
|
@@ -31,7 +32,7 @@ export var devCommand = function() {
|
|
|
31
32
|
devToolMetas = _state.sent();
|
|
32
33
|
devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(function() {
|
|
33
34
|
var _ref2 = _async_to_generator(function(options) {
|
|
34
|
-
var
|
|
35
|
+
var dev2;
|
|
35
36
|
return _ts_generator(this, function(_state2) {
|
|
36
37
|
switch (_state2.label) {
|
|
37
38
|
case 0:
|
|
@@ -40,10 +41,10 @@ export var devCommand = function() {
|
|
|
40
41
|
import("./commands/dev")
|
|
41
42
|
];
|
|
42
43
|
case 1:
|
|
43
|
-
|
|
44
|
+
dev2 = _state2.sent().dev;
|
|
44
45
|
return [
|
|
45
46
|
4,
|
|
46
|
-
|
|
47
|
+
dev2(api, options)
|
|
47
48
|
];
|
|
48
49
|
case 2:
|
|
49
50
|
_state2.sent();
|
|
@@ -76,8 +76,13 @@ function applyRouterPlugin(chain, options) {
|
|
|
76
76
|
const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
77
77
|
const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
78
78
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
79
|
+
const minimize = !normalizedConfig.output.disableMinimize && process.env.NODE_ENV === "production";
|
|
79
80
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
80
|
-
chain.plugin("route-plugin").use(RouterPlugin
|
|
81
|
+
chain.plugin("route-plugin").use(RouterPlugin, [
|
|
82
|
+
{
|
|
83
|
+
minimize
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import { mergeWith } from "@modern-js/utils/lodash";
|
|
3
4
|
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
|
|
@@ -14,6 +15,22 @@ export class RouterPlugin {
|
|
|
14
15
|
}
|
|
15
16
|
return false;
|
|
16
17
|
}
|
|
18
|
+
getEntryChunks(compilation, chunks) {
|
|
19
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
20
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
21
|
+
const entryChunks = [
|
|
22
|
+
...chunks
|
|
23
|
+
].filter((chunk) => {
|
|
24
|
+
var _chunk_names;
|
|
25
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
26
|
+
});
|
|
27
|
+
return entryChunks;
|
|
28
|
+
}
|
|
29
|
+
getEntryChunkFiles(entryChunks) {
|
|
30
|
+
return entryChunks.map((chunk) => [
|
|
31
|
+
...chunk.files || []
|
|
32
|
+
].find((fname) => fname.includes(".js")));
|
|
33
|
+
}
|
|
17
34
|
apply(compiler) {
|
|
18
35
|
const { target } = compiler.options;
|
|
19
36
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
@@ -28,7 +45,8 @@ export class RouterPlugin {
|
|
|
28
45
|
}
|
|
29
46
|
return path2;
|
|
30
47
|
};
|
|
31
|
-
const
|
|
48
|
+
const chunkToSource = /* @__PURE__ */ new Map();
|
|
49
|
+
const chunkToMap = /* @__PURE__ */ new Map();
|
|
32
50
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
33
51
|
compilation.hooks.processAssets.tapPromise({
|
|
34
52
|
name: PLUGIN_NAME,
|
|
@@ -44,14 +62,37 @@ export class RouterPlugin {
|
|
|
44
62
|
if (!namedChunkGroups) {
|
|
45
63
|
return;
|
|
46
64
|
}
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
66
|
+
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
67
|
+
...chunk.files || []
|
|
68
|
+
].find((fname) => fname.includes(".js")));
|
|
69
|
+
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
70
|
+
for (let i = 0; i <= entryChunkFiles.length - 1; i++) {
|
|
71
|
+
const file = entryChunkFiles[i];
|
|
72
|
+
const chunkId = entryChunkFileIds[i];
|
|
73
|
+
const asset = compilation.assets[file];
|
|
74
|
+
if (!asset) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const { map } = asset.sourceAndMap();
|
|
78
|
+
chunkToMap.set(chunkId, map);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
compilation.hooks.processAssets.tapPromise({
|
|
82
|
+
name: PLUGIN_NAME,
|
|
83
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
84
|
+
}, async () => {
|
|
85
|
+
const stats = compilation.getStats().toJson({
|
|
86
|
+
all: false,
|
|
87
|
+
chunkGroups: true,
|
|
88
|
+
chunks: true,
|
|
89
|
+
ids: true
|
|
54
90
|
});
|
|
91
|
+
const { chunks = [], namedChunkGroups } = stats;
|
|
92
|
+
if (!namedChunkGroups) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
55
96
|
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
56
97
|
...chunk.files || []
|
|
57
98
|
].find((fname) => fname.includes(".js")));
|
|
@@ -63,11 +104,8 @@ export class RouterPlugin {
|
|
|
63
104
|
if (!asset) {
|
|
64
105
|
continue;
|
|
65
106
|
}
|
|
66
|
-
const { source
|
|
67
|
-
|
|
68
|
-
source,
|
|
69
|
-
map
|
|
70
|
-
});
|
|
107
|
+
const { source } = asset.sourceAndMap();
|
|
108
|
+
chunkToSource.set(chunkId, source);
|
|
71
109
|
}
|
|
72
110
|
});
|
|
73
111
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -100,6 +138,7 @@ export class RouterPlugin {
|
|
|
100
138
|
const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
|
|
101
139
|
routeAssets[name] = {
|
|
102
140
|
chunkIds: chunkGroup.chunks,
|
|
141
|
+
chunkName: chunkGroup.name,
|
|
103
142
|
assets,
|
|
104
143
|
referenceCssAssets
|
|
105
144
|
};
|
|
@@ -115,31 +154,29 @@ export class RouterPlugin {
|
|
|
115
154
|
const manifest = {
|
|
116
155
|
routeAssets
|
|
117
156
|
};
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
const entryChunks = [
|
|
121
|
-
...chunks
|
|
122
|
-
].filter((chunk) => {
|
|
123
|
-
var _chunk_names;
|
|
124
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
125
|
-
});
|
|
126
|
-
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
127
|
-
...chunk.files || []
|
|
128
|
-
].find((fname) => fname.includes(".js")));
|
|
157
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
158
|
+
const entryChunkFiles = this.getEntryChunkFiles(entryChunks);
|
|
129
159
|
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
130
|
-
for (let i = 0; i
|
|
160
|
+
for (let i = 0; i < entryChunkFiles.length; i++) {
|
|
131
161
|
const file = entryChunkFiles[i];
|
|
162
|
+
const chunkNames = entryChunks[i].names;
|
|
132
163
|
const chunkId = entryChunkFileIds[i];
|
|
133
164
|
const asset = compilation.assets[file];
|
|
134
165
|
if (!asset || !chunkId) {
|
|
135
166
|
continue;
|
|
136
167
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
168
|
+
let relatedAssets = {};
|
|
169
|
+
if (entryChunkFiles.length > 1) {
|
|
170
|
+
Object.keys(routeAssets).forEach((routeId) => {
|
|
171
|
+
const segments = routeId.split("_");
|
|
172
|
+
const chunkName = segments[0];
|
|
173
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
|
174
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
relatedAssets = routeAssets;
|
|
179
|
+
}
|
|
143
180
|
const manifest2 = {
|
|
144
181
|
routeAssets: relatedAssets
|
|
145
182
|
};
|
|
@@ -155,12 +192,13 @@ export class RouterPlugin {
|
|
|
155
192
|
})};
|
|
156
193
|
})();
|
|
157
194
|
`;
|
|
158
|
-
const
|
|
195
|
+
const source = chunkToSource.get(chunkId);
|
|
196
|
+
const map = chunkToMap.get(chunkId);
|
|
159
197
|
const newContent = `${injectedContent}${source.toString()}`;
|
|
160
198
|
const result = await transform(newContent, {
|
|
161
199
|
loader: path.extname(file).slice(1),
|
|
162
200
|
sourcemap: true,
|
|
163
|
-
minify:
|
|
201
|
+
minify: this.minimize
|
|
164
202
|
});
|
|
165
203
|
const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
166
204
|
compilation.updateAsset(
|
|
@@ -183,4 +221,8 @@ export class RouterPlugin {
|
|
|
183
221
|
});
|
|
184
222
|
});
|
|
185
223
|
}
|
|
224
|
+
constructor(options) {
|
|
225
|
+
_define_property(this, "minimize", false);
|
|
226
|
+
this.minimize = options.minimize;
|
|
227
|
+
}
|
|
186
228
|
}
|
|
@@ -5,7 +5,7 @@ import { setServer, createServer, injectDataLoaderPlugin } from "../utils/create
|
|
|
5
5
|
import { generateRoutes } from "../utils/routes";
|
|
6
6
|
import { buildServerConfig } from "../utils/config";
|
|
7
7
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
8
|
-
export const dev = async (api, options) => {
|
|
8
|
+
export const dev = async (api, options, devServerOptions = {}) => {
|
|
9
9
|
var _normalizedConfig_tools;
|
|
10
10
|
if (options.analyze) {
|
|
11
11
|
process.env.BUNDLE_ANALYZE = "true";
|
|
@@ -48,7 +48,8 @@ export const dev = async (api, options) => {
|
|
|
48
48
|
pwd: appDirectory,
|
|
49
49
|
config: normalizedConfig,
|
|
50
50
|
serverConfigFile,
|
|
51
|
-
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
51
|
+
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
|
|
52
|
+
...devServerOptions
|
|
52
53
|
};
|
|
53
54
|
if (apiOnly) {
|
|
54
55
|
var _normalizedConfig_dev;
|
package/dist/esm-node/index.js
CHANGED
|
@@ -10,14 +10,15 @@ import { i18n, localeKeys } from "./locale";
|
|
|
10
10
|
import { restart } from "./utils/restart";
|
|
11
11
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
12
12
|
export { mergeConfig } from "@modern-js/core";
|
|
13
|
+
export { dev } from "./commands";
|
|
13
14
|
export * from "./defineConfig";
|
|
14
15
|
export * from "./types";
|
|
15
16
|
export const devCommand = async (program, api) => {
|
|
16
17
|
const runner = api.useHookRunners();
|
|
17
18
|
const devToolMetas = await runner.registerDev();
|
|
18
19
|
const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
19
|
-
const { dev } = await import("./commands/dev");
|
|
20
|
-
await
|
|
20
|
+
const { dev: dev2 } = await import("./commands/dev");
|
|
21
|
+
await dev2(api, options);
|
|
21
22
|
});
|
|
22
23
|
for (const meta of devToolMetas) {
|
|
23
24
|
if (!meta.subCommands) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entrypoint,
|
|
1
|
+
import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
2
2
|
export declare const getClientRoutes: ({
|
|
3
3
|
entrypoint,
|
|
4
4
|
srcDirectory,
|
|
@@ -11,4 +11,4 @@ export declare const getClientRoutes: ({
|
|
|
11
11
|
srcAlias: string;
|
|
12
12
|
internalDirectory: string;
|
|
13
13
|
internalDirAlias: string;
|
|
14
|
-
}) => (
|
|
14
|
+
}) => (NestedRouteForCli | PageRoute)[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NestedRouteForCli } from '@modern-js/types';
|
|
2
2
|
export declare const getRouteId: (componentPath: string, routesDir: string, entryName: string, isMainEntry: boolean) => string;
|
|
3
3
|
export declare const walk: (dirname: string, rootDir: string, alias: {
|
|
4
4
|
name: string;
|
|
5
5
|
basename: string;
|
|
6
|
-
}, entryName: string, isMainEntry: boolean) => Promise<
|
|
6
|
+
}, entryName: string, isMainEntry: boolean) => Promise<NestedRouteForCli | null>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entrypoint,
|
|
1
|
+
import type { Entrypoint, NestedRouteForCli, PageRoute, RouteLegacy, SSRMode } from '@modern-js/types';
|
|
2
2
|
import type { AppNormalizedConfig, IAppContext, RuntimePlugin } from '../types';
|
|
3
3
|
export declare const index: ({
|
|
4
4
|
mountId,
|
|
@@ -28,7 +28,7 @@ export declare const html: (partials: {
|
|
|
28
28
|
export declare const routesForServer: ({
|
|
29
29
|
routes
|
|
30
30
|
}: {
|
|
31
|
-
routes: (
|
|
31
|
+
routes: (NestedRouteForCli | PageRoute)[];
|
|
32
32
|
}) => string;
|
|
33
33
|
export declare const fileSystemRoutes: ({
|
|
34
34
|
routes,
|
|
@@ -38,7 +38,7 @@ export declare const fileSystemRoutes: ({
|
|
|
38
38
|
internalDirectory,
|
|
39
39
|
splitRouteChunks
|
|
40
40
|
}: {
|
|
41
|
-
routes: RouteLegacy[] | (
|
|
41
|
+
routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
|
|
42
42
|
ssrMode?: SSRMode | undefined;
|
|
43
43
|
nestedRoutesEntry?: string | undefined;
|
|
44
44
|
entryName: string;
|
|
@@ -3,13 +3,21 @@ import type { Rspack } from '@modern-js/builder-rspack-provider';
|
|
|
3
3
|
export interface RouteAssets {
|
|
4
4
|
[routeId: string]: {
|
|
5
5
|
chunkIds?: (string | number)[];
|
|
6
|
+
chunkName: string;
|
|
6
7
|
assets?: string[];
|
|
7
8
|
referenceCssAssets?: string[];
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
11
|
type Compiler = webpack.Compiler | Rspack.Compiler;
|
|
12
|
+
type Options = {
|
|
13
|
+
minimize: boolean;
|
|
14
|
+
};
|
|
11
15
|
export declare class RouterPlugin {
|
|
16
|
+
private minimize;
|
|
17
|
+
constructor(options: Options);
|
|
12
18
|
private isTargetNodeOrWebWorker;
|
|
19
|
+
private getEntryChunks;
|
|
20
|
+
private getEntryChunkFiles;
|
|
13
21
|
apply(compiler: Compiler): void;
|
|
14
22
|
}
|
|
15
23
|
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { PluginAPI } from '@modern-js/core';
|
|
2
2
|
import { DevOptions } from '../utils/types';
|
|
3
3
|
import type { AppTools } from '../types';
|
|
4
|
-
export
|
|
4
|
+
export interface ExtraServerOptions {
|
|
5
|
+
useSSRWorker?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const dev: (api: PluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Command } from '@modern-js/utils';
|
|
|
2
2
|
import { CliPlugin, PluginAPI } from '@modern-js/core';
|
|
3
3
|
import { AppTools } from './types';
|
|
4
4
|
export { mergeConfig } from '@modern-js/core';
|
|
5
|
+
export { dev } from './commands';
|
|
5
6
|
export * from './defineConfig';
|
|
6
7
|
export * from './types';
|
|
7
8
|
export type { RuntimeUserConfig } from './types/config';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { webpack } from '@modern-js/builder-webpack-provider';
|
|
2
2
|
import type { AsyncWaterfall, AsyncWorkflow, ParallelWorkflow } from '@modern-js/plugin';
|
|
3
|
-
import type { Entrypoint, HtmlPartials,
|
|
3
|
+
import type { Entrypoint, HtmlPartials, NestedRouteForCli, PageRoute, RouteLegacy, ServerRoute } from '@modern-js/types';
|
|
4
4
|
import type { RegisterBuildPlatformResult, DevToolData } from '@modern-js/core';
|
|
5
5
|
import type { Stats, MultiStats } from '@modern-js/builder-shared';
|
|
6
6
|
import type { Rspack } from '@modern-js/builder-rspack-provider';
|
|
@@ -43,7 +43,7 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
|
|
|
43
43
|
}>;
|
|
44
44
|
modifyFileSystemRoutes: AsyncWaterfall<{
|
|
45
45
|
entrypoint: Entrypoint;
|
|
46
|
-
routes: RouteLegacy[] | (
|
|
46
|
+
routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
|
|
47
47
|
}>;
|
|
48
48
|
modifyServerRoutes: AsyncWaterfall<{
|
|
49
49
|
routes: ServerRoute[];
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.27.0",
|
|
18
|
+
"version": "2.27.1-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -74,23 +74,23 @@
|
|
|
74
74
|
"rspack-plugin-virtual-module": "0.1.0",
|
|
75
75
|
"@swc/helpers": "0.5.1",
|
|
76
76
|
"@modern-js/builder": "2.27.0",
|
|
77
|
-
"@modern-js/builder-plugin-esbuild": "2.27.0",
|
|
78
|
-
"@modern-js/builder-plugin-node-polyfill": "2.27.0",
|
|
79
|
-
"@modern-js/builder-shared": "2.27.0",
|
|
80
77
|
"@modern-js/builder-webpack-provider": "2.27.0",
|
|
81
|
-
"@modern-js/
|
|
78
|
+
"@modern-js/builder-plugin-esbuild": "2.27.0",
|
|
82
79
|
"@modern-js/new-action": "2.27.0",
|
|
80
|
+
"@modern-js/core": "2.27.0",
|
|
81
|
+
"@modern-js/builder-shared": "2.27.0",
|
|
83
82
|
"@modern-js/node-bundle-require": "2.27.0",
|
|
84
|
-
"@modern-js/plugin": "2.27.0",
|
|
85
|
-
"@modern-js/plugin-data-loader": "2.27.0",
|
|
83
|
+
"@modern-js/builder-plugin-node-polyfill": "2.27.0",
|
|
86
84
|
"@modern-js/plugin-i18n": "2.27.0",
|
|
87
|
-
"@modern-js/plugin-lint": "2.27.0",
|
|
88
85
|
"@modern-js/prod-server": "2.27.0",
|
|
86
|
+
"@modern-js/plugin-lint": "2.27.0",
|
|
87
|
+
"@modern-js/plugin": "2.27.0",
|
|
89
88
|
"@modern-js/server": "2.27.0",
|
|
90
89
|
"@modern-js/types": "2.27.0",
|
|
91
90
|
"@modern-js/upgrade": "2.27.0",
|
|
92
91
|
"@modern-js/utils": "2.27.0",
|
|
93
|
-
"@modern-js/server-core": "2.27.0"
|
|
92
|
+
"@modern-js/server-core": "2.27.0",
|
|
93
|
+
"@modern-js/plugin-data-loader": "2.27.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@types/babel__traverse": "^7.14.2",
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"jest": "^29",
|
|
100
100
|
"typescript": "^5",
|
|
101
101
|
"webpack": "^5.88.1",
|
|
102
|
-
"@modern-js/builder-plugin-swc": "2.27.0",
|
|
103
102
|
"@modern-js/builder-rspack-provider": "2.27.0",
|
|
104
|
-
"@
|
|
105
|
-
"@scripts/jest-config": "2.27.0"
|
|
103
|
+
"@modern-js/builder-plugin-swc": "2.27.0",
|
|
104
|
+
"@scripts/jest-config": "2.27.0",
|
|
105
|
+
"@scripts/build": "2.27.0"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"@modern-js/builder-rspack-provider": "^2.27.0"
|