@modern-js/app-tools 2.26.1-alpha.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.27.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 8f5c6d6: fix: use PROCESS_ASSETS_STAGE_DEV_TOOLING instead of PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY
8
+ fix: 使用 PROCESS_ASSETS_STAGE_DEV_TOOLING 替代 PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY
9
+ - 5129771: fix: Optimize source-map generation in the router-plugin
10
+ fix: 优化 router plugin 中的 source-map 生成
11
+ - e5e6c26: perf: Optimize route manifest size for multiple entries
12
+ perf: 优化路由 manifest 在多 entry 场景下的体积
13
+ - Updated dependencies [645e111]
14
+ - Updated dependencies [91d14b8]
15
+ - Updated dependencies [8322a51]
16
+ - Updated dependencies [5376a22]
17
+ - Updated dependencies [d9080ed]
18
+ - Updated dependencies [67d0b0c]
19
+ - Updated dependencies [3f79dd7]
20
+ - Updated dependencies [6d7104d]
21
+ - @modern-js/builder-webpack-provider@2.27.0
22
+ - @modern-js/builder-rspack-provider@2.27.0
23
+ - @modern-js/builder-shared@2.27.0
24
+ - @modern-js/utils@2.27.0
25
+ - @modern-js/builder-plugin-node-polyfill@2.27.0
26
+ - @modern-js/builder-plugin-esbuild@2.27.0
27
+ - @modern-js/new-action@2.27.0
28
+ - @modern-js/builder@2.27.0
29
+ - @modern-js/plugin-i18n@2.27.0
30
+ - @modern-js/plugin-lint@2.27.0
31
+ - @modern-js/core@2.27.0
32
+ - @modern-js/plugin-data-loader@2.27.0
33
+ - @modern-js/server-core@2.27.0
34
+ - @modern-js/prod-server@2.27.0
35
+ - @modern-js/server@2.27.0
36
+ - @modern-js/node-bundle-require@2.27.0
37
+ - @modern-js/plugin@2.27.0
38
+ - @modern-js/upgrade@2.27.0
39
+ - @modern-js/types@2.27.0
40
+
3
41
  ## 2.26.0
4
42
 
5
43
  ### Patch Changes
@@ -8,9 +8,12 @@ Object.defineProperty(exports, "RouterPlugin", {
8
8
  return RouterPlugin;
9
9
  }
10
10
  });
11
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
+ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
11
13
  const _lodash = require("@modern-js/utils/lodash");
12
14
  const _utils = require("@modern-js/utils");
13
15
  const _constants = require("@modern-js/utils/universal/constants");
16
+ const _esbuild = require("esbuild");
14
17
  const PLUGIN_NAME = "ModernjsRoutePlugin";
15
18
  class RouterPlugin {
16
19
  isTargetNodeOrWebWorker(target) {
@@ -36,7 +39,7 @@ class RouterPlugin {
36
39
  }
37
40
  return path;
38
41
  };
39
- const chunkToSourceMap = /* @__PURE__ */ new Map();
42
+ const chunkToSourceAndMap = /* @__PURE__ */ new Map();
40
43
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
41
44
  compilation.hooks.processAssets.tapPromise({
42
45
  name: PLUGIN_NAME,
@@ -45,7 +48,8 @@ class RouterPlugin {
45
48
  const stats = compilation.getStats().toJson({
46
49
  all: false,
47
50
  chunkGroups: true,
48
- chunks: true
51
+ chunks: true,
52
+ ids: true
49
53
  });
50
54
  const { chunks = [], namedChunkGroups } = stats;
51
55
  if (!namedChunkGroups) {
@@ -70,8 +74,11 @@ class RouterPlugin {
70
74
  if (!asset) {
71
75
  continue;
72
76
  }
73
- const { map } = asset.sourceAndMap();
74
- chunkToSourceMap.set(chunkId, map);
77
+ const { source, map } = asset.sourceAndMap();
78
+ chunkToSourceAndMap.set(chunkId, {
79
+ source,
80
+ map
81
+ });
75
82
  }
76
83
  });
77
84
  compilation.hooks.processAssets.tapPromise({
@@ -135,12 +142,12 @@ class RouterPlugin {
135
142
  const file = entryChunkFiles[i];
136
143
  const chunkId = entryChunkFileIds[i];
137
144
  const asset = compilation.assets[file];
138
- if (!asset) {
145
+ if (!asset || !chunkId) {
139
146
  continue;
140
147
  }
141
148
  const relatedAssets = {};
142
149
  Object.keys(routeAssets).forEach((routeId) => {
143
- if (routeId.startsWith(`${chunkId}_`)) {
150
+ if (routeId.startsWith(`${chunkId}`)) {
144
151
  relatedAssets[routeId] = routeAssets[routeId];
145
152
  }
146
153
  });
@@ -159,10 +166,14 @@ class RouterPlugin {
159
166
  })};
160
167
  })();
161
168
  `;
162
- const { source } = asset.sourceAndMap();
163
- const map = chunkToSourceMap.get(chunkId);
169
+ const { source, map } = chunkToSourceAndMap.get(chunkId);
164
170
  const newContent = `${injectedContent}${source.toString()}`;
165
- const newSource = new SourceMapSource(newContent, file, map, source.toString(), map);
171
+ const result = await (0, _esbuild.transform)(newContent, {
172
+ loader: _path.default.extname(file).slice(1),
173
+ sourcemap: true,
174
+ minify: process.env.NODE_ENV === "production"
175
+ });
176
+ const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
166
177
  compilation.updateAsset(
167
178
  file,
168
179
  newSource,
@@ -4,9 +4,12 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
4
4
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
5
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
6
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
+ import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
8
+ import path from "path";
7
9
  import { mergeWith } from "@modern-js/utils/lodash";
8
10
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
9
11
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
12
+ import { transform } from "esbuild";
10
13
  var PLUGIN_NAME = "ModernjsRoutePlugin";
11
14
  export var RouterPlugin = /* @__PURE__ */ function() {
12
15
  "use strict";
@@ -36,24 +39,25 @@ export var RouterPlugin = /* @__PURE__ */ function() {
36
39
  var webpack = compiler.webpack;
37
40
  var Compilation = webpack.Compilation, sources = webpack.sources;
38
41
  var RawSource = sources.RawSource, SourceMapSource = sources.SourceMapSource;
39
- var normalizePath = function(path) {
40
- if (!path.endsWith("/")) {
41
- return "".concat(path, "/");
42
+ var normalizePath = function(path2) {
43
+ if (!path2.endsWith("/")) {
44
+ return "".concat(path2, "/");
42
45
  }
43
- return path;
46
+ return path2;
44
47
  };
45
- var chunkToSourceMap = /* @__PURE__ */ new Map();
48
+ var chunkToSourceAndMap = /* @__PURE__ */ new Map();
46
49
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
47
50
  compilation.hooks.processAssets.tapPromise({
48
51
  name: PLUGIN_NAME,
49
52
  stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING
50
53
  }, /* @__PURE__ */ _async_to_generator(function() {
51
- var stats, _stats_chunks, chunks, namedChunkGroups, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, map;
54
+ var stats, _stats_chunks, chunks, namedChunkGroups, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, _asset_sourceAndMap, source, map;
52
55
  return _ts_generator(this, function(_state) {
53
56
  stats = compilation.getStats().toJson({
54
57
  all: false,
55
58
  chunkGroups: true,
56
- chunks: true
59
+ chunks: true,
60
+ ids: true
57
61
  });
58
62
  _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
59
63
  if (!namedChunkGroups) {
@@ -86,8 +90,11 @@ export var RouterPlugin = /* @__PURE__ */ function() {
86
90
  if (!asset) {
87
91
  continue;
88
92
  }
89
- map = asset.sourceAndMap().map;
90
- chunkToSourceMap.set(chunkId, map);
93
+ _asset_sourceAndMap = asset.sourceAndMap(), source = _asset_sourceAndMap.source, map = _asset_sourceAndMap.map;
94
+ chunkToSourceAndMap.set(chunkId, {
95
+ source: source,
96
+ map: map
97
+ });
91
98
  }
92
99
  return [
93
100
  2
@@ -100,136 +107,180 @@ export var RouterPlugin = /* @__PURE__ */ function() {
100
107
  }, /* @__PURE__ */ _async_to_generator(function() {
101
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, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, entryChunkFileIds, i;
102
109
  return _ts_generator(this, function(_state) {
103
- _loop = function(i2) {
104
- var file = entryChunkFiles[i2];
105
- var chunkId = entryChunkFileIds[i2];
106
- var asset = compilation.assets[file];
107
- if (!asset) {
108
- return "continue";
109
- }
110
- var relatedAssets = {};
111
- Object.keys(routeAssets).forEach(function(routeId) {
112
- if (routeId.startsWith("".concat(chunkId, "_"))) {
113
- relatedAssets[routeId] = routeAssets[routeId];
114
- }
115
- });
116
- var manifest2 = {
117
- routeAssets: relatedAssets
118
- };
119
- var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
120
- if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
121
- return v.map(function(item) {
122
- return item.replace(publicPath, "");
110
+ switch (_state.label) {
111
+ case 0:
112
+ _loop = function(i2) {
113
+ var file, chunkId, asset, relatedAssets, manifest2, injectedContent, _chunkToSourceAndMap_get, source, map, newContent, result, newSource;
114
+ return _ts_generator(this, function(_state2) {
115
+ switch (_state2.label) {
116
+ case 0:
117
+ file = entryChunkFiles[i2];
118
+ chunkId = entryChunkFileIds[i2];
119
+ asset = compilation.assets[file];
120
+ if (!asset || !chunkId) {
121
+ return [
122
+ 2,
123
+ "continue"
124
+ ];
125
+ }
126
+ relatedAssets = {};
127
+ Object.keys(routeAssets).forEach(function(routeId) {
128
+ if (routeId.startsWith("".concat(chunkId))) {
129
+ relatedAssets[routeId] = routeAssets[routeId];
130
+ }
131
+ });
132
+ manifest2 = {
133
+ routeAssets: relatedAssets
134
+ };
135
+ injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
136
+ if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
137
+ return v.map(function(item) {
138
+ return item.replace(publicPath, "");
139
+ });
140
+ }
141
+ return v;
142
+ }), ";\n })();\n ");
143
+ _chunkToSourceAndMap_get = chunkToSourceAndMap.get(chunkId), source = _chunkToSourceAndMap_get.source, map = _chunkToSourceAndMap_get.map;
144
+ newContent = "".concat(injectedContent).concat(source.toString());
145
+ return [
146
+ 4,
147
+ transform(newContent, {
148
+ loader: path.extname(file).slice(1),
149
+ sourcemap: true,
150
+ minify: process.env.NODE_ENV === "production"
151
+ })
152
+ ];
153
+ case 1:
154
+ result = _state2.sent();
155
+ newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
156
+ compilation.updateAsset(
157
+ file,
158
+ newSource,
159
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
160
+ void 0
161
+ );
162
+ return [
163
+ 2
164
+ ];
165
+ }
123
166
  });
124
- }
125
- return v;
126
- }), ";\n })();\n ");
127
- var source = asset.sourceAndMap().source;
128
- var map = chunkToSourceMap.get(chunkId);
129
- var newContent = "".concat(injectedContent).concat(source.toString());
130
- var newSource = new SourceMapSource(newContent, file, map, source.toString(), map);
131
- compilation.updateAsset(
132
- file,
133
- newSource,
134
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
135
- void 0
136
- );
137
- };
138
- stats = compilation.getStats().toJson({
139
- all: false,
140
- publicPath: true,
141
- assets: true,
142
- chunkGroups: true,
143
- chunks: true,
144
- ids: true
145
- });
146
- publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
147
- routeAssets = {};
148
- if (!namedChunkGroups) {
149
- return [
150
- 2
151
- ];
152
- }
153
- prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
154
- prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
155
- routeAssets: {}
156
- });
157
- prevManifest = JSON.parse(prevManifestStr);
158
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
159
- try {
160
- for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
161
- _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
162
- assets = chunkGroup.assets.map(function(asset) {
163
- var filename = asset.name;
164
- return publicPath ? normalizePath(publicPath) + filename : filename;
167
+ };
168
+ stats = compilation.getStats().toJson({
169
+ all: false,
170
+ publicPath: true,
171
+ assets: true,
172
+ chunkGroups: true,
173
+ chunks: true,
174
+ ids: true
165
175
  });
166
- referenceCssAssets = assets.filter(function(asset) {
167
- return /\.css$/.test(asset);
176
+ publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
177
+ routeAssets = {};
178
+ if (!namedChunkGroups) {
179
+ return [
180
+ 2
181
+ ];
182
+ }
183
+ prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
184
+ prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
185
+ routeAssets: {}
168
186
  });
169
- routeAssets[name] = {
170
- chunkIds: chunkGroup.chunks,
171
- assets: assets,
172
- referenceCssAssets: referenceCssAssets
173
- };
174
- if (prevManifest.routeAssets[name]) {
175
- mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
176
- if (Array.isArray(obj)) {
177
- return obj.concat(source);
187
+ prevManifest = JSON.parse(prevManifestStr);
188
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
189
+ try {
190
+ for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
191
+ _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
192
+ assets = chunkGroup.assets.map(function(asset) {
193
+ var filename = asset.name;
194
+ return publicPath ? normalizePath(publicPath) + filename : filename;
195
+ });
196
+ referenceCssAssets = assets.filter(function(asset) {
197
+ return /\.css$/.test(asset);
198
+ });
199
+ routeAssets[name] = {
200
+ chunkIds: chunkGroup.chunks,
201
+ assets: assets,
202
+ referenceCssAssets: referenceCssAssets
203
+ };
204
+ if (prevManifest.routeAssets[name]) {
205
+ mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
206
+ if (Array.isArray(obj)) {
207
+ return obj.concat(source);
208
+ }
209
+ return Object.assign(source, obj);
210
+ });
178
211
  }
179
- return Object.assign(source, obj);
180
- });
181
- }
182
- }
183
- } catch (err) {
184
- _didIteratorError = true;
185
- _iteratorError = err;
186
- } finally {
187
- try {
188
- if (!_iteratorNormalCompletion && _iterator.return != null) {
189
- _iterator.return();
212
+ }
213
+ } catch (err) {
214
+ _didIteratorError = true;
215
+ _iteratorError = err;
216
+ } finally {
217
+ try {
218
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
219
+ _iterator.return();
220
+ }
221
+ } finally {
222
+ if (_didIteratorError) {
223
+ throw _iteratorError;
224
+ }
225
+ }
190
226
  }
191
- } finally {
192
- if (_didIteratorError) {
193
- throw _iteratorError;
227
+ manifest = {
228
+ routeAssets: routeAssets
229
+ };
230
+ entrypointsArray = Array.from(compilation.entrypoints.entries());
231
+ entryChunkIds = entrypointsArray.map(function(entrypoint) {
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
+ });
245
+ entryChunkFileIds = entryChunks.map(function(chunk) {
246
+ return chunk.id;
247
+ });
248
+ i = 0;
249
+ _state.label = 1;
250
+ case 1:
251
+ if (!(i <= entryChunkFiles.length - 1))
252
+ return [
253
+ 3,
254
+ 4
255
+ ];
256
+ return [
257
+ 5,
258
+ _ts_values(_loop(i))
259
+ ];
260
+ case 2:
261
+ _state.sent();
262
+ _state.label = 3;
263
+ case 3:
264
+ i++;
265
+ return [
266
+ 3,
267
+ 1
268
+ ];
269
+ case 4:
270
+ if (prevManifestAsset) {
271
+ compilation.updateAsset(
272
+ ROUTE_MANIFEST_FILE,
273
+ new RawSource(JSON.stringify(manifest, null, 2)),
274
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
275
+ void 0
276
+ );
277
+ } else {
278
+ compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
194
279
  }
195
- }
196
- }
197
- manifest = {
198
- routeAssets: routeAssets
199
- };
200
- entrypointsArray = Array.from(compilation.entrypoints.entries());
201
- entryChunkIds = entrypointsArray.map(function(entrypoint) {
202
- return entrypoint[0];
203
- });
204
- entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
205
- var _chunk_names;
206
- return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name2) {
207
- return entryChunkIds.includes(name2);
208
- });
209
- });
210
- entryChunkFiles = entryChunks.map(function(chunk) {
211
- return _to_consumable_array(chunk.files || []).find(function(fname) {
212
- return fname.includes(".js");
213
- });
214
- });
215
- entryChunkFileIds = entryChunks.map(function(chunk) {
216
- return chunk.id;
217
- });
218
- for (i = 0; i <= entryChunkFiles.length - 1; i++)
219
- _loop(i);
220
- if (prevManifestAsset) {
221
- compilation.updateAsset(
222
- ROUTE_MANIFEST_FILE,
223
- new RawSource(JSON.stringify(manifest, null, 2)),
224
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
225
- void 0
226
- );
227
- } else {
228
- compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
280
+ return [
281
+ 2
282
+ ];
229
283
  }
230
- return [
231
- 2
232
- ];
233
284
  });
234
285
  }));
235
286
  });
@@ -1,6 +1,8 @@
1
+ import path from "path";
1
2
  import { mergeWith } from "@modern-js/utils/lodash";
2
3
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
3
4
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
5
+ import { transform } from "esbuild";
4
6
  const PLUGIN_NAME = "ModernjsRoutePlugin";
5
7
  export class RouterPlugin {
6
8
  isTargetNodeOrWebWorker(target) {
@@ -20,13 +22,13 @@ export class RouterPlugin {
20
22
  const { webpack } = compiler;
21
23
  const { Compilation, sources } = webpack;
22
24
  const { RawSource, SourceMapSource } = sources;
23
- const normalizePath = (path) => {
24
- if (!path.endsWith("/")) {
25
- return `${path}/`;
25
+ const normalizePath = (path2) => {
26
+ if (!path2.endsWith("/")) {
27
+ return `${path2}/`;
26
28
  }
27
- return path;
29
+ return path2;
28
30
  };
29
- const chunkToSourceMap = /* @__PURE__ */ new Map();
31
+ const chunkToSourceAndMap = /* @__PURE__ */ new Map();
30
32
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
31
33
  compilation.hooks.processAssets.tapPromise({
32
34
  name: PLUGIN_NAME,
@@ -35,7 +37,8 @@ export class RouterPlugin {
35
37
  const stats = compilation.getStats().toJson({
36
38
  all: false,
37
39
  chunkGroups: true,
38
- chunks: true
40
+ chunks: true,
41
+ ids: true
39
42
  });
40
43
  const { chunks = [], namedChunkGroups } = stats;
41
44
  if (!namedChunkGroups) {
@@ -60,8 +63,11 @@ export class RouterPlugin {
60
63
  if (!asset) {
61
64
  continue;
62
65
  }
63
- const { map } = asset.sourceAndMap();
64
- chunkToSourceMap.set(chunkId, map);
66
+ const { source, map } = asset.sourceAndMap();
67
+ chunkToSourceAndMap.set(chunkId, {
68
+ source,
69
+ map
70
+ });
65
71
  }
66
72
  });
67
73
  compilation.hooks.processAssets.tapPromise({
@@ -125,12 +131,12 @@ export class RouterPlugin {
125
131
  const file = entryChunkFiles[i];
126
132
  const chunkId = entryChunkFileIds[i];
127
133
  const asset = compilation.assets[file];
128
- if (!asset) {
134
+ if (!asset || !chunkId) {
129
135
  continue;
130
136
  }
131
137
  const relatedAssets = {};
132
138
  Object.keys(routeAssets).forEach((routeId) => {
133
- if (routeId.startsWith(`${chunkId}_`)) {
139
+ if (routeId.startsWith(`${chunkId}`)) {
134
140
  relatedAssets[routeId] = routeAssets[routeId];
135
141
  }
136
142
  });
@@ -149,10 +155,14 @@ export class RouterPlugin {
149
155
  })};
150
156
  })();
151
157
  `;
152
- const { source } = asset.sourceAndMap();
153
- const map = chunkToSourceMap.get(chunkId);
158
+ const { source, map } = chunkToSourceAndMap.get(chunkId);
154
159
  const newContent = `${injectedContent}${source.toString()}`;
155
- const newSource = new SourceMapSource(newContent, file, map, source.toString(), map);
160
+ const result = await transform(newContent, {
161
+ loader: path.extname(file).slice(1),
162
+ sourcemap: true,
163
+ minify: process.env.NODE_ENV === "production"
164
+ });
165
+ const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
156
166
  compilation.updateAsset(
157
167
  file,
158
168
  newSource,
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.26.1-alpha.0",
18
+ "version": "2.27.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -73,24 +73,24 @@
73
73
  "esbuild": "0.17.19",
74
74
  "rspack-plugin-virtual-module": "0.1.0",
75
75
  "@swc/helpers": "0.5.1",
76
- "@modern-js/builder": "2.26.0",
77
- "@modern-js/builder-plugin-node-polyfill": "2.26.0",
78
- "@modern-js/builder-plugin-esbuild": "2.26.0",
79
- "@modern-js/core": "2.26.0",
80
- "@modern-js/builder-shared": "2.26.0",
81
- "@modern-js/builder-webpack-provider": "2.26.0",
82
- "@modern-js/new-action": "2.26.0",
83
- "@modern-js/node-bundle-require": "2.26.0",
84
- "@modern-js/plugin": "2.26.0",
85
- "@modern-js/plugin-lint": "2.26.0",
86
- "@modern-js/prod-server": "2.26.0",
87
- "@modern-js/plugin-i18n": "2.26.0",
88
- "@modern-js/server": "2.26.0",
89
- "@modern-js/types": "2.26.0",
90
- "@modern-js/utils": "2.26.0",
91
- "@modern-js/server-core": "2.26.0",
92
- "@modern-js/upgrade": "2.26.0",
93
- "@modern-js/plugin-data-loader": "2.26.0"
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
+ "@modern-js/builder-webpack-provider": "2.27.0",
81
+ "@modern-js/core": "2.27.0",
82
+ "@modern-js/new-action": "2.27.0",
83
+ "@modern-js/node-bundle-require": "2.27.0",
84
+ "@modern-js/plugin": "2.27.0",
85
+ "@modern-js/plugin-data-loader": "2.27.0",
86
+ "@modern-js/plugin-i18n": "2.27.0",
87
+ "@modern-js/plugin-lint": "2.27.0",
88
+ "@modern-js/prod-server": "2.27.0",
89
+ "@modern-js/server": "2.27.0",
90
+ "@modern-js/types": "2.27.0",
91
+ "@modern-js/upgrade": "2.27.0",
92
+ "@modern-js/utils": "2.27.0",
93
+ "@modern-js/server-core": "2.27.0"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@types/babel__traverse": "^7.14.2",
@@ -99,13 +99,13 @@
99
99
  "jest": "^29",
100
100
  "typescript": "^5",
101
101
  "webpack": "^5.88.1",
102
- "@modern-js/builder-rspack-provider": "2.26.0",
103
- "@modern-js/builder-plugin-swc": "2.26.0",
104
- "@scripts/build": "2.26.0",
105
- "@scripts/jest-config": "2.26.0"
102
+ "@modern-js/builder-plugin-swc": "2.27.0",
103
+ "@modern-js/builder-rspack-provider": "2.27.0",
104
+ "@scripts/build": "2.27.0",
105
+ "@scripts/jest-config": "2.27.0"
106
106
  },
107
107
  "peerDependencies": {
108
- "@modern-js/builder-rspack-provider": "^2.26.0"
108
+ "@modern-js/builder-rspack-provider": "^2.27.0"
109
109
  },
110
110
  "peerDependenciesMeta": {
111
111
  "@modern-js/builder-rspack-provider": {