@modern-js/app-tools 2.30.0 → 2.31.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/cjs/analyze/getHtmlTemplate.js +6 -0
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +13 -3
  4. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +64 -82
  5. package/dist/cjs/config/default.js +2 -1
  6. package/dist/cjs/schema/index.js +3 -0
  7. package/dist/cjs/types/config/testing.js +4 -0
  8. package/dist/cjs/types/legacyConfig/testing.js +4 -0
  9. package/dist/esm/analyze/getHtmlTemplate.js +8 -1
  10. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +13 -3
  11. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +189 -249
  12. package/dist/esm/config/default.js +2 -1
  13. package/dist/esm/schema/index.js +3 -0
  14. package/dist/esm/types/config/testing.js +1 -0
  15. package/dist/esm/types/legacyConfig/testing.js +1 -0
  16. package/dist/esm-node/analyze/getHtmlTemplate.js +6 -0
  17. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +13 -3
  18. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +68 -85
  19. package/dist/esm-node/config/default.js +2 -1
  20. package/dist/esm-node/schema/index.js +3 -0
  21. package/dist/esm-node/types/config/testing.js +1 -0
  22. package/dist/esm-node/types/legacyConfig/testing.js +1 -0
  23. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +24 -0
  24. package/dist/types/types/config/index.d.ts +4 -1
  25. package/dist/types/types/config/output.d.ts +1 -0
  26. package/dist/types/types/config/security.d.ts +3 -1
  27. package/dist/types/types/config/testing.d.ts +8 -0
  28. package/dist/types/types/config/tools.d.ts +1 -1
  29. package/dist/types/types/legacyConfig/index.d.ts +2 -0
  30. package/dist/types/types/legacyConfig/testing.d.ts +8 -0
  31. package/dist/types/types/legacyConfig/tools.d.ts +1 -2
  32. package/package.json +25 -25
@@ -1,20 +1,35 @@
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";
7
- import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
8
- import path from "path";
8
+ import { createHash } from "crypto";
9
9
  import { mergeWith } from "@modern-js/utils/lodash";
10
10
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
11
11
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
12
- import { transform } from "esbuild";
13
12
  var PLUGIN_NAME = "ModernjsRoutePlugin";
13
+ var generateContentHash = function(content) {
14
+ return createHash("md5").update(content).digest("hex").slice(0, 8);
15
+ };
14
16
  export var RouterPlugin = /* @__PURE__ */ function() {
15
17
  "use strict";
16
- function RouterPlugin2() {
18
+ function RouterPlugin2(param) {
19
+ 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;
17
20
  _class_call_check(this, RouterPlugin2);
21
+ _define_property(this, "HtmlBundlerPlugin", void 0);
22
+ _define_property(this, "enableInlineRouteManifests", void 0);
23
+ _define_property(this, "staticJsDir", void 0);
24
+ _define_property(this, "disableFilenameHash", void 0);
25
+ _define_property(this, "scriptLoading", void 0);
26
+ _define_property(this, "nonce", void 0);
27
+ this.HtmlBundlerPlugin = HtmlBundlerPlugin;
28
+ this.enableInlineRouteManifests = enableInlineRouteManifests;
29
+ this.staticJsDir = staticJsDir;
30
+ this.disableFilenameHash = disableFilenameHash;
31
+ this.scriptLoading = scriptLoading;
32
+ this.nonce = nonce;
18
33
  }
19
34
  _create_class(RouterPlugin2, [
20
35
  {
@@ -65,282 +80,207 @@ export var RouterPlugin = /* @__PURE__ */ function() {
65
80
  }
66
81
  var webpack = compiler.webpack;
67
82
  var Compilation = webpack.Compilation, sources = webpack.sources;
68
- var RawSource = sources.RawSource, SourceMapSource = sources.SourceMapSource;
69
- var normalizePath = function(path2) {
70
- if (!path2.endsWith("/")) {
71
- return "".concat(path2, "/");
83
+ var RawSource = sources.RawSource;
84
+ var normalizePath = function(path) {
85
+ if (!path.endsWith("/")) {
86
+ return "".concat(path, "/");
72
87
  }
73
- return path2;
88
+ return path;
74
89
  };
75
- var chunkToSource = /* @__PURE__ */ new Map();
76
- var chunkToMap = /* @__PURE__ */ new Map();
77
- var minimize = compiler.options.optimization.minimize;
90
+ var chunksToHtmlName = /* @__PURE__ */ new Map();
91
+ var ROUTE_MANIFEST_HOLDER = "route-manifest";
92
+ var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
78
93
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
94
+ _this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
95
+ var outputName = data.outputName;
96
+ var chunks = data.plugin.options.chunks;
97
+ chunksToHtmlName.set(chunks, outputName);
98
+ data.html = data.html.replace("</script>", "</script>".concat(placeholder));
99
+ callback(null, data);
100
+ });
79
101
  var _this1 = _this;
80
102
  compilation.hooks.processAssets.tapPromise({
81
103
  name: PLUGIN_NAME,
82
- stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING
104
+ stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
83
105
  }, /* @__PURE__ */ _async_to_generator(function() {
84
- var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, map;
106
+ 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, entryChunkFiles, entryChunkFileIds, i;
85
107
  return _ts_generator(this, function(_state) {
108
+ _loop = function(i2) {
109
+ var entryName = entryNames[i2];
110
+ var file = entryChunkFiles[i2];
111
+ var chunkNames = entryChunks[i2].names;
112
+ var chunkId = entryChunkFileIds[i2];
113
+ var asset = compilation.assets[file];
114
+ if (!asset || !chunkId) {
115
+ return "continue";
116
+ }
117
+ var relatedAssets = {};
118
+ if (entryChunkFiles.length > 1) {
119
+ Object.keys(routeAssets).forEach(function(routeId) {
120
+ var _chunkNames;
121
+ var segments = routeId.split("_");
122
+ var chunkName = segments[0];
123
+ if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
124
+ relatedAssets[routeId] = routeAssets[routeId];
125
+ }
126
+ });
127
+ } else {
128
+ relatedAssets = routeAssets;
129
+ }
130
+ var manifest2 = {
131
+ routeAssets: relatedAssets
132
+ };
133
+ var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
134
+ if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
135
+ return v.map(function(item) {
136
+ return item.replace(publicPath, "");
137
+ });
138
+ }
139
+ return v;
140
+ }), ";\n })();\n ");
141
+ var htmlName = void 0;
142
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
143
+ try {
144
+ var _loop2 = function() {
145
+ var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
146
+ if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
147
+ return value === chunks2[index];
148
+ })) {
149
+ htmlName = name2;
150
+ return "break";
151
+ }
152
+ };
153
+ for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
154
+ var _ret = _loop2();
155
+ if (_ret === "break")
156
+ break;
157
+ }
158
+ } catch (err) {
159
+ _didIteratorError2 = true;
160
+ _iteratorError2 = err;
161
+ } finally {
162
+ try {
163
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
164
+ _iterator2.return();
165
+ }
166
+ } finally {
167
+ if (_didIteratorError2) {
168
+ throw _iteratorError2;
169
+ }
170
+ }
171
+ }
172
+ var oldHtml = compilation.assets[htmlName];
173
+ var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
174
+ var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
175
+ if (enableInlineRouteManifests) {
176
+ compilation.updateAsset(
177
+ htmlName,
178
+ new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
179
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
180
+ void 0
181
+ );
182
+ } else {
183
+ var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
184
+ var scriptUrl = "".concat(publicPath).concat(scriptPath);
185
+ var scriptLoadingAttr = (
186
+ // eslint-disable-next-line no-nested-ternary
187
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
188
+ );
189
+ var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
190
+ compilation.updateAsset(
191
+ htmlName,
192
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
193
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
194
+ void 0
195
+ );
196
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
197
+ }
198
+ };
86
199
  stats = compilation.getStats().toJson({
87
200
  all: false,
201
+ publicPath: true,
202
+ assets: true,
88
203
  chunkGroups: true,
89
204
  chunks: true,
90
205
  ids: true
91
206
  });
92
- _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
207
+ publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
208
+ routeAssets = {};
93
209
  if (!namedChunkGroups) {
94
210
  return [
95
211
  2
96
212
  ];
97
213
  }
98
- entryChunks = _this1.getEntryChunks(compilation, chunks);
99
- entryChunkFiles = entryChunks.map(function(chunk) {
100
- return _to_consumable_array(chunk.files || []).find(function(fname) {
101
- return fname.includes(".js");
102
- });
103
- });
104
- entryChunkFileIds = entryChunks.map(function(chunk) {
105
- return chunk.id;
214
+ prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
215
+ prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
216
+ routeAssets: {}
106
217
  });
107
- for (i = 0; i <= entryChunkFiles.length - 1; i++) {
108
- file = entryChunkFiles[i];
109
- chunkId = entryChunkFileIds[i];
110
- asset = compilation.assets[file];
111
- if (!asset) {
112
- continue;
218
+ prevManifest = JSON.parse(prevManifestStr);
219
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
220
+ try {
221
+ for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
222
+ _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
223
+ assets = chunkGroup.assets.map(function(asset) {
224
+ var filename = asset.name;
225
+ return publicPath ? normalizePath(publicPath) + filename : filename;
226
+ });
227
+ referenceCssAssets = assets.filter(function(asset) {
228
+ return /\.css$/.test(asset);
229
+ });
230
+ routeAssets[name] = {
231
+ chunkIds: chunkGroup.chunks,
232
+ assets: assets,
233
+ referenceCssAssets: referenceCssAssets
234
+ };
235
+ if (prevManifest.routeAssets[name]) {
236
+ mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
237
+ if (Array.isArray(obj)) {
238
+ return obj.concat(source);
239
+ }
240
+ return Object.assign(source, obj);
241
+ });
242
+ }
243
+ }
244
+ } catch (err) {
245
+ _didIteratorError = true;
246
+ _iteratorError = err;
247
+ } finally {
248
+ try {
249
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
250
+ _iterator.return();
251
+ }
252
+ } finally {
253
+ if (_didIteratorError) {
254
+ throw _iteratorError;
255
+ }
113
256
  }
114
- map = asset.sourceAndMap().map;
115
- chunkToMap.set(chunkId, map);
116
- }
117
- return [
118
- 2
119
- ];
120
- });
121
- }));
122
- var _this2 = _this;
123
- compilation.hooks.processAssets.tapPromise({
124
- name: PLUGIN_NAME,
125
- stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
126
- }, /* @__PURE__ */ _async_to_generator(function() {
127
- var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, source;
128
- return _ts_generator(this, function(_state) {
129
- stats = compilation.getStats().toJson({
130
- all: false,
131
- chunkGroups: true,
132
- chunks: true,
133
- ids: true
134
- });
135
- _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
136
- if (!namedChunkGroups) {
137
- return [
138
- 2
139
- ];
140
257
  }
141
- entryChunks = _this2.getEntryChunks(compilation, chunks);
142
- entryChunkFiles = entryChunks.map(function(chunk) {
143
- return _to_consumable_array(chunk.files || []).find(function(fname) {
144
- return fname.includes(".js");
145
- });
146
- });
258
+ manifest = {
259
+ routeAssets: routeAssets
260
+ };
261
+ entryNames = Array.from(compilation.entrypoints.keys());
262
+ entryChunks = _this1.getEntryChunks(compilation, chunks);
263
+ entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
147
264
  entryChunkFileIds = entryChunks.map(function(chunk) {
148
265
  return chunk.id;
149
266
  });
150
- for (i = 0; i <= entryChunkFiles.length - 1; i++) {
151
- file = entryChunkFiles[i];
152
- chunkId = entryChunkFileIds[i];
153
- asset = compilation.assets[file];
154
- if (!asset) {
155
- continue;
156
- }
157
- source = asset.sourceAndMap().source;
158
- chunkToSource.set(chunkId, source);
267
+ for (i = 0; i < entryChunkFiles.length; i++)
268
+ _loop(i);
269
+ if (prevManifestAsset) {
270
+ compilation.updateAsset(
271
+ ROUTE_MANIFEST_FILE,
272
+ new RawSource(JSON.stringify(manifest, null, 2)),
273
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
274
+ void 0
275
+ );
276
+ } else {
277
+ compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
159
278
  }
160
279
  return [
161
280
  2
162
281
  ];
163
282
  });
164
283
  }));
165
- var _this3 = _this;
166
- compilation.hooks.processAssets.tapPromise({
167
- name: PLUGIN_NAME,
168
- stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
169
- }, /* @__PURE__ */ _async_to_generator(function() {
170
- 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;
171
- return _ts_generator(this, function(_state) {
172
- switch (_state.label) {
173
- case 0:
174
- _loop = function(i2) {
175
- var _source, _source1, file, chunkNames, chunkId, asset, relatedAssets, manifest2, injectedContent, source, map, newContent, result, newSource;
176
- return _ts_generator(this, function(_state2) {
177
- switch (_state2.label) {
178
- case 0:
179
- file = entryChunkFiles[i2];
180
- chunkNames = entryChunks[i2].names;
181
- chunkId = entryChunkFileIds[i2];
182
- asset = compilation.assets[file];
183
- if (!asset || !chunkId) {
184
- return [
185
- 2,
186
- "continue"
187
- ];
188
- }
189
- relatedAssets = {};
190
- if (entryChunkFiles.length > 1) {
191
- Object.keys(routeAssets).forEach(function(routeId) {
192
- var _chunkNames;
193
- var segments = routeId.split("_");
194
- var chunkName = segments[0];
195
- if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
196
- relatedAssets[routeId] = routeAssets[routeId];
197
- }
198
- });
199
- } else {
200
- relatedAssets = routeAssets;
201
- }
202
- manifest2 = {
203
- routeAssets: relatedAssets
204
- };
205
- injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
206
- if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
207
- return v.map(function(item) {
208
- return item.replace(publicPath, "");
209
- });
210
- }
211
- return v;
212
- }), ";\n })();\n ");
213
- source = chunkToSource.get(chunkId);
214
- map = chunkToMap.get(chunkId);
215
- newContent = "".concat(injectedContent).concat((_source = source) === null || _source === void 0 ? void 0 : _source.toString());
216
- return [
217
- 4,
218
- transform(newContent, {
219
- loader: path.extname(file).slice(1),
220
- sourcemap: true,
221
- minify: minimize
222
- })
223
- ];
224
- case 1:
225
- result = _state2.sent();
226
- newSource = new SourceMapSource(result.code, file, result.map, (_source1 = source) === null || _source1 === void 0 ? void 0 : _source1.toString(), map);
227
- compilation.updateAsset(
228
- file,
229
- newSource,
230
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
231
- void 0
232
- );
233
- return [
234
- 2
235
- ];
236
- }
237
- });
238
- };
239
- stats = compilation.getStats().toJson({
240
- all: false,
241
- publicPath: true,
242
- assets: true,
243
- chunkGroups: true,
244
- chunks: true,
245
- ids: true
246
- });
247
- publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
248
- routeAssets = {};
249
- if (!namedChunkGroups) {
250
- return [
251
- 2
252
- ];
253
- }
254
- prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
255
- prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
256
- routeAssets: {}
257
- });
258
- prevManifest = JSON.parse(prevManifestStr);
259
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
260
- try {
261
- for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
262
- _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
263
- assets = chunkGroup.assets.map(function(asset) {
264
- var filename = asset.name;
265
- return publicPath ? normalizePath(publicPath) + filename : filename;
266
- });
267
- referenceCssAssets = assets.filter(function(asset) {
268
- return /\.css$/.test(asset);
269
- });
270
- routeAssets[name] = {
271
- chunkIds: chunkGroup.chunks,
272
- assets: assets,
273
- referenceCssAssets: referenceCssAssets
274
- };
275
- if (prevManifest.routeAssets[name]) {
276
- mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
277
- if (Array.isArray(obj)) {
278
- return obj.concat(source);
279
- }
280
- return Object.assign(source, obj);
281
- });
282
- }
283
- }
284
- } catch (err) {
285
- _didIteratorError = true;
286
- _iteratorError = err;
287
- } finally {
288
- try {
289
- if (!_iteratorNormalCompletion && _iterator.return != null) {
290
- _iterator.return();
291
- }
292
- } finally {
293
- if (_didIteratorError) {
294
- throw _iteratorError;
295
- }
296
- }
297
- }
298
- manifest = {
299
- routeAssets: routeAssets
300
- };
301
- entryChunks = _this3.getEntryChunks(compilation, chunks);
302
- entryChunkFiles = _this3.getEntryChunkFiles(entryChunks);
303
- entryChunkFileIds = entryChunks.map(function(chunk) {
304
- return chunk.id;
305
- });
306
- i = 0;
307
- _state.label = 1;
308
- case 1:
309
- if (!(i < entryChunkFiles.length))
310
- return [
311
- 3,
312
- 4
313
- ];
314
- return [
315
- 5,
316
- _ts_values(_loop(i))
317
- ];
318
- case 2:
319
- _state.sent();
320
- _state.label = 3;
321
- case 3:
322
- i++;
323
- return [
324
- 3,
325
- 1
326
- ];
327
- case 4:
328
- if (prevManifestAsset) {
329
- compilation.updateAsset(
330
- ROUTE_MANIFEST_FILE,
331
- new RawSource(JSON.stringify(manifest, null, 2)),
332
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
333
- void 0
334
- );
335
- } else {
336
- compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
337
- }
338
- return [
339
- 2
340
- ];
341
- }
342
- });
343
- }));
344
284
  });
345
285
  }
346
286
  }
@@ -12,7 +12,8 @@ export function createDefaultConfig(appContext, bundler) {
12
12
  port: void 0
13
13
  });
14
14
  var output = _object_spread_props(_object_spread({}, defaultBuilderConfig.output), {
15
- disableNodePolyfill: true
15
+ disableNodePolyfill: true,
16
+ enableInlineRouteManifests: true
16
17
  });
17
18
  var _obj;
18
19
  var source = _object_spread_props(_object_spread({}, defaultBuilderConfig.source), {
@@ -86,6 +86,9 @@ var output = {
86
86
  },
87
87
  disableNodePolyfill: {
88
88
  type: "boolean"
89
+ },
90
+ enableInlineRouteManifests: {
91
+ type: "boolean"
89
92
  }
90
93
  };
91
94
  var dev = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -26,6 +26,7 @@ export const getHtmlTemplate = async (entrypoints, api, { appContext, config })
26
26
  const { source: { configDir } } = config;
27
27
  const htmlDir = path.resolve(appDirectory, configDir || "", HTML_PARTIALS_FOLDER);
28
28
  const htmlTemplates = {};
29
+ const partialsByEntrypoint = {};
29
30
  for (const entrypoint of entrypoints) {
30
31
  const { entryName, isMainEntry } = entrypoint;
31
32
  const name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
@@ -55,11 +56,16 @@ export const getHtmlTemplate = async (entrypoints, api, { appContext, config })
55
56
  const templatePath = path.resolve(internalDirectory, entryName, "index.html");
56
57
  fs.outputFileSync(templatePath, templates.html(partials), "utf8");
57
58
  htmlTemplates[entryName] = templatePath;
59
+ partialsByEntrypoint[entryName] = partials;
58
60
  const bottomTemplate = findPartials(htmlDir, name, PartialPosition.BOTTOM);
59
61
  if (bottomTemplate) {
60
62
  htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
61
63
  }
62
64
  }
63
65
  }
66
+ api.setAppContext({
67
+ ...api.useAppContext(),
68
+ partialsByEntrypoint
69
+ });
64
70
  return htmlTemplates;
65
71
  };
@@ -20,7 +20,7 @@ export const builderPluginAdapterSSR = (options) => ({
20
20
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
21
21
  const builderConfig = api.getNormalizedConfig();
22
22
  const { normalizedConfig: normalizedConfig2 } = options;
23
- applyRouterPlugin(chain, options);
23
+ applyRouterPlugin(chain, options, HtmlBundlerPlugin);
24
24
  if (isSSR(normalizedConfig2)) {
25
25
  await applySSRLoaderEntry(chain, options, isServer);
26
26
  applySSRDataLoader(chain, options);
@@ -69,7 +69,7 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
69
69
  ]);
70
70
  }
71
71
  }
72
- function applyRouterPlugin(chain, options) {
72
+ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
73
73
  var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
74
74
  const { appContext, normalizedConfig } = options;
75
75
  const { entrypoints } = appContext;
@@ -78,7 +78,17 @@ function applyRouterPlugin(chain, options) {
78
78
  const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
79
79
  const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
80
80
  if (existNestedRoutes || routerManifest || workerSSR) {
81
- chain.plugin("route-plugin").use(RouterPlugin);
81
+ var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
82
+ chain.plugin("route-plugin").use(RouterPlugin, [
83
+ {
84
+ HtmlBundlerPlugin,
85
+ enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
86
+ staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
87
+ disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
88
+ scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
89
+ nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
90
+ }
91
+ ]);
82
92
  }
83
93
  }
84
94
  function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {