@modern-js/app-tools 2.47.1 → 2.48.1
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +7 -1
- package/dist/cjs/builder/generator/index.js +3 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +49 -0
- package/dist/cjs/builder/shared/builderPlugins/index.js +3 -1
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -3
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -5
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -8
- package/dist/cjs/index.js +5 -5
- package/dist/esm/builder/generator/index.js +4 -3
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -1
- package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +41 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +1 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +35 -43
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +24 -32
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +240 -261
- package/dist/esm/index.js +20 -19
- package/dist/esm-node/builder/generator/index.js +3 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +25 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +1 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -3
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -5
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +1 -8
- package/dist/esm-node/index.js +6 -6
- package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +2 -0
- package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -0
- package/dist/types/config/legacy/index.d.ts +1 -1
- package/dist/types/defineConfig.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +4 -3
- package/dist/types/types/config/tools.d.ts +5 -3
- package/dist/types/types/index.d.ts +2 -2
- package/package.json +21 -23
@@ -1,7 +1,5 @@
|
|
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
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
4
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
5
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
6
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
7
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
@@ -18,13 +16,7 @@ var RouterPlugin = /* @__PURE__ */ function() {
|
|
18
16
|
function RouterPlugin2(param) {
|
19
17
|
var _param_staticJsDir = param.staticJsDir, staticJsDir = _param_staticJsDir === void 0 ? "static/js" : _param_staticJsDir, HtmlBundlerPlugin = param.HtmlBundlerPlugin, enableInlineRouteManifests = param.enableInlineRouteManifests, _param_disableFilenameHash = param.disableFilenameHash, disableFilenameHash = _param_disableFilenameHash === void 0 ? false : _param_disableFilenameHash, _param_scriptLoading = param.scriptLoading, scriptLoading = _param_scriptLoading === void 0 ? "defer" : _param_scriptLoading, nonce = param.nonce;
|
20
18
|
_class_call_check(this, RouterPlugin2);
|
21
|
-
|
22
|
-
_define_property(this, "HtmlBundlerPlugin", void 0);
|
23
|
-
_define_property(this, "enableInlineRouteManifests", void 0);
|
24
|
-
_define_property(this, "staticJsDir", void 0);
|
25
|
-
_define_property(this, "disableFilenameHash", void 0);
|
26
|
-
_define_property(this, "scriptLoading", void 0);
|
27
|
-
_define_property(this, "nonce", void 0);
|
19
|
+
this.name = "RouterPlugin";
|
28
20
|
this.HtmlBundlerPlugin = HtmlBundlerPlugin;
|
29
21
|
this.enableInlineRouteManifests = enableInlineRouteManifests;
|
30
22
|
this.staticJsDir = staticJsDir;
|
@@ -32,276 +24,263 @@ var RouterPlugin = /* @__PURE__ */ function() {
|
|
32
24
|
this.scriptLoading = scriptLoading;
|
33
25
|
this.nonce = nonce;
|
34
26
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
return
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
27
|
+
var _proto = RouterPlugin2.prototype;
|
28
|
+
_proto.isTargetNodeOrWebWorker = function isTargetNodeOrWebWorker(target) {
|
29
|
+
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
return false;
|
36
|
+
};
|
37
|
+
_proto.getEntryChunks = 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
|
+
_proto.getEntryChunkFiles = function getEntryChunkFiles(entryChunks) {
|
51
|
+
return entryChunks.map(function(chunk) {
|
52
|
+
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
53
|
+
return fname.includes(".js");
|
54
|
+
});
|
55
|
+
});
|
56
|
+
};
|
57
|
+
_proto.apply = function apply(compiler) {
|
58
|
+
var _this = this;
|
59
|
+
var target = compiler.options.target;
|
60
|
+
if (this.isTargetNodeOrWebWorker(target)) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
var webpack = compiler.webpack;
|
64
|
+
var isRspack = "rspackVersion" in webpack;
|
65
|
+
var Compilation = webpack.Compilation, sources = webpack.sources;
|
66
|
+
var RawSource = sources.RawSource;
|
67
|
+
var normalizePath = function(path) {
|
68
|
+
if (!path.endsWith("/")) {
|
69
|
+
return "".concat(path, "/");
|
72
70
|
}
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
var
|
98
|
-
var
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
return _ts_generator(this, function(_state) {
|
110
|
-
_loop = function(i2) {
|
111
|
-
var entryName = entryNames[i2];
|
112
|
-
var file = entryChunkFiles[i2];
|
113
|
-
var chunkNames = entryChunks[i2].names;
|
114
|
-
var chunkId = entryChunkFileIds[i2];
|
115
|
-
var asset = compilation.assets[file];
|
116
|
-
if (!asset || !chunkId) {
|
117
|
-
return "continue";
|
118
|
-
}
|
119
|
-
var relatedAssets = {};
|
120
|
-
if (entryChunkFiles.length > 1) {
|
121
|
-
Object.keys(routeAssets).forEach(function(routeId) {
|
122
|
-
var segments = routeId.split("_");
|
123
|
-
var chunkName = segments[0];
|
124
|
-
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
125
|
-
relatedAssets[routeId] = routeAssets[routeId];
|
126
|
-
}
|
127
|
-
});
|
128
|
-
} else {
|
129
|
-
relatedAssets = routeAssets;
|
130
|
-
}
|
131
|
-
var manifest2 = {
|
132
|
-
routeAssets: relatedAssets
|
133
|
-
};
|
134
|
-
var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
|
135
|
-
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
136
|
-
return v.map(function(item) {
|
137
|
-
return item.replace(publicPath, "");
|
138
|
-
});
|
139
|
-
}
|
140
|
-
return v;
|
141
|
-
}), ";\n })();\n ");
|
142
|
-
var htmlName = void 0;
|
143
|
-
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
144
|
-
try {
|
145
|
-
var _loop2 = function() {
|
146
|
-
var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
|
147
|
-
if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
|
148
|
-
return value === chunks2[index];
|
149
|
-
})) {
|
150
|
-
htmlName = name2;
|
151
|
-
return "break";
|
152
|
-
}
|
153
|
-
};
|
154
|
-
for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
155
|
-
var _ret = _loop2();
|
156
|
-
if (_ret === "break")
|
157
|
-
break;
|
158
|
-
}
|
159
|
-
} catch (err) {
|
160
|
-
_didIteratorError2 = true;
|
161
|
-
_iteratorError2 = err;
|
162
|
-
} finally {
|
163
|
-
try {
|
164
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
165
|
-
_iterator2.return();
|
166
|
-
}
|
167
|
-
} finally {
|
168
|
-
if (_didIteratorError2) {
|
169
|
-
throw _iteratorError2;
|
170
|
-
}
|
171
|
-
}
|
71
|
+
return path;
|
72
|
+
};
|
73
|
+
var chunksToHtmlName = /* @__PURE__ */ new Map();
|
74
|
+
var ROUTE_MANIFEST_HOLDER = "route-manifest";
|
75
|
+
var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
|
76
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
|
77
|
+
_this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
|
78
|
+
var outputName = data.outputName;
|
79
|
+
var chunks = data.plugin.options.chunks;
|
80
|
+
chunksToHtmlName.set(chunks, outputName);
|
81
|
+
data.html = data.html.replace("</script>", "</script>".concat(placeholder));
|
82
|
+
callback(null, data);
|
83
|
+
});
|
84
|
+
var _this1 = _this;
|
85
|
+
compilation.hooks.processAssets.tapPromise({
|
86
|
+
name: PLUGIN_NAME,
|
87
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
88
|
+
}, /* @__PURE__ */ _async_to_generator(function() {
|
89
|
+
var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
|
90
|
+
return _ts_generator(this, function(_state) {
|
91
|
+
_loop = function(i2) {
|
92
|
+
var entryName = entryNames[i2];
|
93
|
+
var file = entryChunkFiles[i2];
|
94
|
+
var chunkNames = entryChunks[i2].names;
|
95
|
+
var chunkId = entryChunkFileIds[i2];
|
96
|
+
var asset = compilation.assets[file];
|
97
|
+
if (!asset || !chunkId) {
|
98
|
+
return "continue";
|
99
|
+
}
|
100
|
+
var relatedAssets = {};
|
101
|
+
if (entryChunkFiles.length > 1) {
|
102
|
+
Object.keys(routeAssets).forEach(function(routeId) {
|
103
|
+
var segments = routeId.split("_");
|
104
|
+
var chunkName = segments[0];
|
105
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
106
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
172
107
|
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
compilation.emitAsset(scriptPath, new RawSource(injectedContent));
|
199
|
-
}
|
108
|
+
});
|
109
|
+
} else {
|
110
|
+
relatedAssets = routeAssets;
|
111
|
+
}
|
112
|
+
var manifest2 = {
|
113
|
+
routeAssets: relatedAssets
|
114
|
+
};
|
115
|
+
var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
|
116
|
+
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
117
|
+
return v.map(function(item) {
|
118
|
+
return item.replace(publicPath, "");
|
119
|
+
});
|
120
|
+
}
|
121
|
+
return v;
|
122
|
+
}), ";\n })();\n ");
|
123
|
+
var htmlName = void 0;
|
124
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
125
|
+
try {
|
126
|
+
var _loop2 = function() {
|
127
|
+
var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
|
128
|
+
if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
|
129
|
+
return value === chunks2[index];
|
130
|
+
})) {
|
131
|
+
htmlName = name2;
|
132
|
+
return "break";
|
200
133
|
}
|
201
134
|
};
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
chunkGroups: true,
|
207
|
-
chunks: true,
|
208
|
-
ids: true
|
209
|
-
});
|
210
|
-
publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
|
211
|
-
routeAssets = {};
|
212
|
-
if (!namedChunkGroups) {
|
213
|
-
return [
|
214
|
-
2
|
215
|
-
];
|
135
|
+
for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
136
|
+
var _ret = _loop2();
|
137
|
+
if (_ret === "break")
|
138
|
+
break;
|
216
139
|
}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
prevManifest = JSON.parse(prevManifestStr);
|
222
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
140
|
+
} catch (err) {
|
141
|
+
_didIteratorError2 = true;
|
142
|
+
_iteratorError2 = err;
|
143
|
+
} finally {
|
223
144
|
try {
|
224
|
-
|
225
|
-
|
226
|
-
assets = chunkGroup.assets.map(function(asset) {
|
227
|
-
var filename = asset.name;
|
228
|
-
return publicPath ? normalizePath(publicPath) + filename : filename;
|
229
|
-
});
|
230
|
-
referenceCssAssets = assets.filter(function(asset) {
|
231
|
-
return /\.css$/.test(asset);
|
232
|
-
});
|
233
|
-
routeAssets[name] = {
|
234
|
-
chunkIds: chunkGroup.chunks,
|
235
|
-
assets,
|
236
|
-
referenceCssAssets
|
237
|
-
};
|
238
|
-
if (prevManifest.routeAssets[name]) {
|
239
|
-
mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
|
240
|
-
if (Array.isArray(obj)) {
|
241
|
-
return obj.concat(source);
|
242
|
-
}
|
243
|
-
return Object.assign(source, obj);
|
244
|
-
});
|
245
|
-
}
|
145
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
146
|
+
_iterator2.return();
|
246
147
|
}
|
247
|
-
} catch (err) {
|
248
|
-
_didIteratorError = true;
|
249
|
-
_iteratorError = err;
|
250
148
|
} finally {
|
251
|
-
|
252
|
-
|
253
|
-
_iterator.return();
|
254
|
-
}
|
255
|
-
} finally {
|
256
|
-
if (_didIteratorError) {
|
257
|
-
throw _iteratorError;
|
258
|
-
}
|
149
|
+
if (_didIteratorError2) {
|
150
|
+
throw _iteratorError2;
|
259
151
|
}
|
260
152
|
}
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
if (
|
267
|
-
entryChunks = _this1.getEntryChunks(compilation, chunks);
|
268
|
-
} else {
|
269
|
-
orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
|
270
|
-
var chunk = compilation.namedChunks.get(entryName);
|
271
|
-
if (chunk) {
|
272
|
-
return chunk.id;
|
273
|
-
}
|
274
|
-
return entryName;
|
275
|
-
});
|
276
|
-
entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
|
277
|
-
return orignalEntryIds.includes(chunk.id);
|
278
|
-
});
|
279
|
-
}
|
280
|
-
entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
|
281
|
-
entryChunkFileIds = entryChunks.map(function(chunk) {
|
282
|
-
return chunk.id;
|
283
|
-
});
|
284
|
-
for (i = 0; i < entryChunkFiles.length; i++)
|
285
|
-
_loop(i);
|
286
|
-
if (prevManifestAsset) {
|
153
|
+
}
|
154
|
+
var oldHtml = compilation.assets[htmlName];
|
155
|
+
var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
|
156
|
+
var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
|
157
|
+
if (oldHtml) {
|
158
|
+
if (enableInlineRouteManifests) {
|
287
159
|
compilation.updateAsset(
|
288
|
-
|
289
|
-
new RawSource(
|
160
|
+
htmlName,
|
161
|
+
new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
|
290
162
|
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
291
163
|
void 0
|
292
164
|
);
|
293
165
|
} else {
|
294
|
-
|
166
|
+
var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
|
167
|
+
var scriptUrl = "".concat(publicPath).concat(scriptPath);
|
168
|
+
var scriptLoadingAttr = (
|
169
|
+
// eslint-disable-next-line no-nested-ternary
|
170
|
+
scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
|
171
|
+
);
|
172
|
+
var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
|
173
|
+
compilation.updateAsset(
|
174
|
+
htmlName,
|
175
|
+
new RawSource(oldHtml.source().toString().replace(placeholder, script)),
|
176
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
177
|
+
void 0
|
178
|
+
);
|
179
|
+
compilation.emitAsset(scriptPath, new RawSource(injectedContent));
|
295
180
|
}
|
296
|
-
|
297
|
-
|
298
|
-
|
181
|
+
}
|
182
|
+
};
|
183
|
+
stats = compilation.getStats().toJson({
|
184
|
+
all: false,
|
185
|
+
publicPath: true,
|
186
|
+
assets: true,
|
187
|
+
chunkGroups: true,
|
188
|
+
chunks: true,
|
189
|
+
ids: true
|
190
|
+
});
|
191
|
+
publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
|
192
|
+
routeAssets = {};
|
193
|
+
if (!namedChunkGroups) {
|
194
|
+
return [
|
195
|
+
2
|
196
|
+
];
|
197
|
+
}
|
198
|
+
prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
|
199
|
+
prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
|
200
|
+
routeAssets: {}
|
201
|
+
});
|
202
|
+
prevManifest = JSON.parse(prevManifestStr);
|
203
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
204
|
+
try {
|
205
|
+
for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
206
|
+
_step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
|
207
|
+
assets = chunkGroup.assets.map(function(asset) {
|
208
|
+
var filename = asset.name;
|
209
|
+
return publicPath ? normalizePath(publicPath) + filename : filename;
|
210
|
+
});
|
211
|
+
referenceCssAssets = assets.filter(function(asset) {
|
212
|
+
return /\.css$/.test(asset);
|
213
|
+
});
|
214
|
+
routeAssets[name] = {
|
215
|
+
chunkIds: chunkGroup.chunks,
|
216
|
+
assets,
|
217
|
+
referenceCssAssets
|
218
|
+
};
|
219
|
+
if (prevManifest.routeAssets[name]) {
|
220
|
+
mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
|
221
|
+
if (Array.isArray(obj)) {
|
222
|
+
return obj.concat(source);
|
223
|
+
}
|
224
|
+
return Object.assign(source, obj);
|
225
|
+
});
|
226
|
+
}
|
227
|
+
}
|
228
|
+
} catch (err) {
|
229
|
+
_didIteratorError = true;
|
230
|
+
_iteratorError = err;
|
231
|
+
} finally {
|
232
|
+
try {
|
233
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
234
|
+
_iterator.return();
|
235
|
+
}
|
236
|
+
} finally {
|
237
|
+
if (_didIteratorError) {
|
238
|
+
throw _iteratorError;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
manifest = {
|
243
|
+
routeAssets
|
244
|
+
};
|
245
|
+
entryNames = Array.from(compilation.entrypoints.keys());
|
246
|
+
entryChunks = [];
|
247
|
+
if (isRspack) {
|
248
|
+
entryChunks = _this1.getEntryChunks(compilation, chunks);
|
249
|
+
} else {
|
250
|
+
orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
|
251
|
+
var chunk = compilation.namedChunks.get(entryName);
|
252
|
+
if (chunk) {
|
253
|
+
return chunk.id;
|
254
|
+
}
|
255
|
+
return entryName;
|
256
|
+
});
|
257
|
+
entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
|
258
|
+
return orignalEntryIds.includes(chunk.id);
|
299
259
|
});
|
300
|
-
}
|
260
|
+
}
|
261
|
+
entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
|
262
|
+
entryChunkFileIds = entryChunks.map(function(chunk) {
|
263
|
+
return chunk.id;
|
264
|
+
});
|
265
|
+
for (i = 0; i < entryChunkFiles.length; i++)
|
266
|
+
_loop(i);
|
267
|
+
if (prevManifestAsset) {
|
268
|
+
compilation.updateAsset(
|
269
|
+
ROUTE_MANIFEST_FILE,
|
270
|
+
new RawSource(JSON.stringify(manifest, null, 2)),
|
271
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
272
|
+
void 0
|
273
|
+
);
|
274
|
+
} else {
|
275
|
+
compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
|
276
|
+
}
|
277
|
+
return [
|
278
|
+
2
|
279
|
+
];
|
301
280
|
});
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
281
|
+
}));
|
282
|
+
});
|
283
|
+
};
|
305
284
|
return RouterPlugin2;
|
306
285
|
}();
|
307
286
|
export {
|
package/dist/esm/index.js
CHANGED
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import path from "path";
|
6
6
|
import { lintPlugin } from "@modern-js/plugin-lint";
|
7
|
-
import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
|
7
|
+
import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE, newAction, upgradeAction } from "@modern-js/utils";
|
8
8
|
import { castArray } from "@modern-js/utils/lodash";
|
9
9
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
10
10
|
import analyzePlugin from "./analyze";
|
@@ -328,7 +328,6 @@ var appTools = function() {
|
|
328
328
|
commands: function commands(param) {
|
329
329
|
var program = param.program;
|
330
330
|
return _async_to_generator(function() {
|
331
|
-
var defineCommand;
|
332
331
|
return _ts_generator(this, function(_state) {
|
333
332
|
switch (_state.label) {
|
334
333
|
case 0:
|
@@ -417,23 +416,16 @@ var appTools = function() {
|
|
417
416
|
}());
|
418
417
|
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--config-file <configFile>", i18n.t(localeKeys.command.shared.config)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)).action(function() {
|
419
418
|
var _ref = _async_to_generator(function(options2) {
|
420
|
-
var MWANewAction;
|
421
419
|
return _ts_generator(this, function(_state2) {
|
422
420
|
switch (_state2.label) {
|
423
421
|
case 0:
|
424
422
|
return [
|
425
423
|
4,
|
426
|
-
|
427
|
-
];
|
428
|
-
case 1:
|
429
|
-
MWANewAction = _state2.sent().MWANewAction;
|
430
|
-
return [
|
431
|
-
4,
|
432
|
-
MWANewAction(_object_spread_props(_object_spread({}, options2), {
|
424
|
+
newAction(_object_spread_props(_object_spread({}, options2), {
|
433
425
|
locale: options2.lang || locale
|
434
|
-
}))
|
426
|
+
}), "mwa")
|
435
427
|
];
|
436
|
-
case
|
428
|
+
case 1:
|
437
429
|
_state2.sent();
|
438
430
|
return [
|
439
431
|
2
|
@@ -468,13 +460,22 @@ var appTools = function() {
|
|
468
460
|
return _ref.apply(this, arguments);
|
469
461
|
};
|
470
462
|
}());
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
463
|
+
program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(/* @__PURE__ */ _async_to_generator(function() {
|
464
|
+
return _ts_generator(this, function(_state2) {
|
465
|
+
switch (_state2.label) {
|
466
|
+
case 0:
|
467
|
+
return [
|
468
|
+
4,
|
469
|
+
upgradeAction()
|
470
|
+
];
|
471
|
+
case 1:
|
472
|
+
_state2.sent();
|
473
|
+
return [
|
474
|
+
2
|
475
|
+
];
|
476
|
+
}
|
477
|
+
});
|
478
|
+
}));
|
478
479
|
return [
|
479
480
|
2
|
480
481
|
];
|
@@ -16,11 +16,12 @@ async function generateBuilder(options, bundlerType) {
|
|
16
16
|
return builder;
|
17
17
|
}
|
18
18
|
async function applyBuilderPlugins(builder, options) {
|
19
|
-
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins");
|
19
|
+
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
|
20
20
|
builder.addPlugins([
|
21
21
|
builderPluginAdapterBasic(),
|
22
22
|
builderPluginAdapterSSR(options),
|
23
|
-
builderPluginAdapterHtml(options)
|
23
|
+
builderPluginAdapterHtml(options),
|
24
|
+
builderPluginAdapterWorker()
|
24
25
|
]);
|
25
26
|
const { normalizedConfig } = options;
|
26
27
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import * as path from "path";
|
2
|
-
import { isHtmlDisabled
|
2
|
+
import { isHtmlDisabled } from "@rsbuild/shared";
|
3
|
+
import { mergeRsbuildConfig } from "@rsbuild/core";
|
3
4
|
import { isSSR, fs } from "@modern-js/utils";
|
4
5
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
5
6
|
import { getServerCombinedModueFile } from "../../../analyze/utils";
|