@modern-js/app-tools 2.28.1-alpha.1 → 2.28.1-alpha.3
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/generateCode.js +2 -2
- package/dist/cjs/analyze/nestedRoutes.js +16 -17
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +74 -35
- package/dist/cjs/config/default.js +14 -2
- package/dist/cjs/config/initialize/index.js +0 -3
- package/dist/cjs/config/initialize/inits.js +0 -31
- package/dist/esm/analyze/generateCode.js +2 -2
- package/dist/esm/analyze/nestedRoutes.js +16 -22
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +100 -42
- package/dist/esm/config/default.js +12 -1
- package/dist/esm/config/initialize/index.js +1 -4
- package/dist/esm/config/initialize/inits.js +1 -30
- package/dist/esm-node/analyze/generateCode.js +2 -2
- package/dist/esm-node/analyze/nestedRoutes.js +16 -17
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +74 -35
- package/dist/esm-node/config/default.js +14 -2
- package/dist/esm-node/config/initialize/index.js +1 -4
- package/dist/esm-node/config/initialize/inits.js +1 -29
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +2 -0
- package/dist/types/config/initialize/inits.d.ts +1 -2
- package/package.json +11 -11
|
@@ -74,13 +74,13 @@ ${initialize || ""}`);
|
|
|
74
74
|
${initialize || ""}`).join("\n");
|
|
75
75
|
};
|
|
76
76
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
77
|
-
var _config,
|
|
77
|
+
var _config, _config1;
|
|
78
78
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
79
79
|
const hookRunners = api.useHookRunners();
|
|
80
80
|
const isV5 = (0, _utils.isRouterV5)(config);
|
|
81
81
|
const getRoutes = isV5 ? _getClientRoutes.getClientRoutesLegacy : _getClientRoutes.getClientRoutes;
|
|
82
82
|
const importsStatemets = /* @__PURE__ */ new Map();
|
|
83
|
-
const oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean((_config1 = config) === null || _config1 === void 0 ? void 0 :
|
|
83
|
+
const oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean(((_config1 = config) === null || _config1 === void 0 ? void 0 : _config1.runtime.router).oldVersion) : false;
|
|
84
84
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
85
85
|
return {
|
|
86
86
|
importsStatemets
|
|
@@ -66,20 +66,28 @@ const optimizeRoute = (routeTree) => {
|
|
|
66
66
|
];
|
|
67
67
|
}
|
|
68
68
|
const { children } = routeTree;
|
|
69
|
-
if (!routeTree._component) {
|
|
69
|
+
if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
|
|
70
70
|
const newRoutes = children.map((child) => {
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
return {
|
|
71
|
+
const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
|
|
72
|
+
const newRoute = {
|
|
74
73
|
...child,
|
|
75
|
-
path: routePath
|
|
74
|
+
path: routePath.replace(/\/\//g, "/")
|
|
76
75
|
};
|
|
76
|
+
if (routePath.length > 0) {
|
|
77
|
+
delete newRoute.index;
|
|
78
|
+
} else {
|
|
79
|
+
delete newRoute.path;
|
|
80
|
+
}
|
|
81
|
+
return newRoute;
|
|
77
82
|
});
|
|
78
|
-
return newRoutes.flatMap(
|
|
83
|
+
return Array.from(new Set(newRoutes)).flatMap(optimizeRoute);
|
|
79
84
|
} else {
|
|
80
|
-
|
|
85
|
+
const optimizedChildren = routeTree.children.flatMap(optimizeRoute);
|
|
81
86
|
return [
|
|
82
|
-
|
|
87
|
+
{
|
|
88
|
+
...routeTree,
|
|
89
|
+
children: optimizedChildren
|
|
90
|
+
}
|
|
83
91
|
];
|
|
84
92
|
}
|
|
85
93
|
};
|
|
@@ -200,15 +208,6 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
|
|
|
200
208
|
};
|
|
201
209
|
}
|
|
202
210
|
}
|
|
203
|
-
if (splatRoute) {
|
|
204
|
-
var _childRoutes;
|
|
205
|
-
const slatRouteIndex = (_childRoutes = childRoutes) === null || _childRoutes === void 0 ? void 0 : _childRoutes.findIndex((childRoute) => childRoute === splatRoute);
|
|
206
|
-
if (typeof slatRouteIndex === "number" && slatRouteIndex !== -1) {
|
|
207
|
-
var _childRoutes1, _childRoutes2;
|
|
208
|
-
(_childRoutes1 = childRoutes) === null || _childRoutes1 === void 0 ? void 0 : _childRoutes1.splice(slatRouteIndex, 1);
|
|
209
|
-
(_childRoutes2 = childRoutes) === null || _childRoutes2 === void 0 ? void 0 : _childRoutes2.push(splatRoute);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
211
|
if (isRoot && !oldVersion) {
|
|
213
212
|
const optimizedRoutes = optimizeRoute(finalRoute);
|
|
214
213
|
return optimizedRoutes;
|
|
@@ -25,6 +25,22 @@ class RouterPlugin {
|
|
|
25
25
|
}
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
|
+
getEntryChunks(compilation, chunks) {
|
|
29
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
30
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
31
|
+
const entryChunks = [
|
|
32
|
+
...chunks
|
|
33
|
+
].filter((chunk) => {
|
|
34
|
+
var _chunk_names;
|
|
35
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
36
|
+
});
|
|
37
|
+
return entryChunks;
|
|
38
|
+
}
|
|
39
|
+
getEntryChunkFiles(entryChunks) {
|
|
40
|
+
return entryChunks.map((chunk) => [
|
|
41
|
+
...chunk.files || []
|
|
42
|
+
].find((fname) => fname.includes(".js")));
|
|
43
|
+
}
|
|
28
44
|
apply(compiler) {
|
|
29
45
|
const { target } = compiler.options;
|
|
30
46
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
@@ -39,7 +55,9 @@ class RouterPlugin {
|
|
|
39
55
|
}
|
|
40
56
|
return path;
|
|
41
57
|
};
|
|
42
|
-
const
|
|
58
|
+
const chunkToSource = /* @__PURE__ */ new Map();
|
|
59
|
+
const chunkToMap = /* @__PURE__ */ new Map();
|
|
60
|
+
const { minimize } = compiler.options.optimization;
|
|
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({
|
|
@@ -126,31 +164,31 @@ class RouterPlugin {
|
|
|
126
164
|
const manifest = {
|
|
127
165
|
routeAssets
|
|
128
166
|
};
|
|
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")));
|
|
167
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
168
|
+
const entryChunkFiles = this.getEntryChunkFiles(entryChunks);
|
|
140
169
|
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
141
|
-
for (let i = 0; i
|
|
170
|
+
for (let i = 0; i < entryChunkFiles.length; i++) {
|
|
171
|
+
var _source, _source1;
|
|
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
|
+
var _chunkNames;
|
|
183
|
+
const segments = routeId.split("_");
|
|
184
|
+
const chunkName = segments[0];
|
|
185
|
+
if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
|
|
186
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
relatedAssets = routeAssets;
|
|
191
|
+
}
|
|
154
192
|
const manifest2 = {
|
|
155
193
|
routeAssets: relatedAssets
|
|
156
194
|
};
|
|
@@ -166,14 +204,15 @@ class RouterPlugin {
|
|
|
166
204
|
})};
|
|
167
205
|
})();
|
|
168
206
|
`;
|
|
169
|
-
const
|
|
170
|
-
const
|
|
207
|
+
const source = chunkToSource.get(chunkId);
|
|
208
|
+
const map = chunkToMap.get(chunkId);
|
|
209
|
+
const newContent = `${injectedContent}${(_source = source) === null || _source === void 0 ? void 0 : _source.toString()}`;
|
|
171
210
|
const result = await (0, _esbuild.transform)(newContent, {
|
|
172
211
|
loader: _path.default.extname(file).slice(1),
|
|
173
212
|
sourcemap: true,
|
|
174
|
-
minify:
|
|
213
|
+
minify: minimize
|
|
175
214
|
});
|
|
176
|
-
const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
215
|
+
const newSource = new SourceMapSource(result.code, file, result.map, (_source1 = source) === null || _source1 === void 0 ? void 0 : _source1.toString(), map);
|
|
177
216
|
compilation.updateAsset(
|
|
178
217
|
file,
|
|
179
218
|
newSource,
|
|
@@ -75,9 +75,21 @@ function createDefaultConfig(appContext, bundler) {
|
|
|
75
75
|
baseUrl: "/",
|
|
76
76
|
port: 8080
|
|
77
77
|
};
|
|
78
|
+
const defaultTsCheckerConfig = {
|
|
79
|
+
tsChecker: {
|
|
80
|
+
issue: {
|
|
81
|
+
include: [
|
|
82
|
+
{
|
|
83
|
+
file: "**/src/**/*"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
78
89
|
const tools = bundler === "webpack" ? {
|
|
79
|
-
...defaultBuilderConfig.tools
|
|
80
|
-
|
|
90
|
+
...defaultBuilderConfig.tools,
|
|
91
|
+
...defaultTsCheckerConfig
|
|
92
|
+
} : defaultTsCheckerConfig;
|
|
81
93
|
return {
|
|
82
94
|
source,
|
|
83
95
|
output,
|
|
@@ -12,8 +12,5 @@ const _inits = require("./inits");
|
|
|
12
12
|
function initialNormalizedConfig(config, appContext, bundler) {
|
|
13
13
|
(0, _inits.initHtmlConfig)(config, appContext);
|
|
14
14
|
(0, _inits.initSourceConfig)(config, appContext, bundler);
|
|
15
|
-
if (bundler === "webpack") {
|
|
16
|
-
(0, _inits.initToolsConfig)(config);
|
|
17
|
-
}
|
|
18
15
|
return config;
|
|
19
16
|
}
|
|
@@ -15,9 +15,6 @@ _export(exports, {
|
|
|
15
15
|
},
|
|
16
16
|
initSourceConfig: function() {
|
|
17
17
|
return initSourceConfig;
|
|
18
|
-
},
|
|
19
|
-
initToolsConfig: function() {
|
|
20
|
-
return initToolsConfig;
|
|
21
18
|
}
|
|
22
19
|
});
|
|
23
20
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
@@ -116,31 +113,3 @@ function initSourceConfig(config, appContext, bundler) {
|
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
|
-
function initToolsConfig(config) {
|
|
120
|
-
const defaultTsChecker = {
|
|
121
|
-
issue: {
|
|
122
|
-
include: [
|
|
123
|
-
{
|
|
124
|
-
file: "**/src/**/*"
|
|
125
|
-
}
|
|
126
|
-
],
|
|
127
|
-
exclude: [
|
|
128
|
-
{
|
|
129
|
-
file: "**/*.(spec|test).ts"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
file: "**/node_modules/**/*"
|
|
133
|
-
}
|
|
134
|
-
]
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const { tsChecker, tsLoader } = config.tools;
|
|
138
|
-
config.tools.tsChecker = (0, _utils.applyOptionsChain)(defaultTsChecker, tsChecker);
|
|
139
|
-
tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
|
|
140
|
-
(0, _utils.applyOptionsChain)({
|
|
141
|
-
...tsLoaderConfig,
|
|
142
|
-
transpileOnly: false,
|
|
143
|
-
allowTsInNodeModules: true
|
|
144
|
-
}, tsLoader || {}, utils);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
@@ -94,7 +94,7 @@ export var createImportStatements = function(statements) {
|
|
|
94
94
|
};
|
|
95
95
|
export var generateCode = function() {
|
|
96
96
|
var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
|
|
97
|
-
var _config,
|
|
97
|
+
var _config, _config1, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets, oldVersion;
|
|
98
98
|
function generateEntryCode(entrypoint) {
|
|
99
99
|
return _generateEntryCode.apply(this, arguments);
|
|
100
100
|
}
|
|
@@ -294,7 +294,7 @@ export var generateCode = function() {
|
|
|
294
294
|
isV5 = isRouterV5(config);
|
|
295
295
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
296
296
|
importsStatemets = /* @__PURE__ */ new Map();
|
|
297
|
-
oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean((_config1 = config) === null || _config1 === void 0 ? void 0 :
|
|
297
|
+
oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean(((_config1 = config) === null || _config1 === void 0 ? void 0 : _config1.runtime.router).oldVersion) : false;
|
|
298
298
|
return [
|
|
299
299
|
4,
|
|
300
300
|
Promise.all(entrypoints.map(generateEntryCode))
|
|
@@ -45,27 +45,32 @@ export var optimizeRoute = function(routeTree) {
|
|
|
45
45
|
];
|
|
46
46
|
}
|
|
47
47
|
var children = routeTree.children;
|
|
48
|
-
if (!routeTree._component) {
|
|
48
|
+
if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
|
|
49
49
|
var newRoutes = children.map(function(child) {
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
path: routePath
|
|
50
|
+
var routePath = "".concat(routeTree.path ? routeTree.path : "").concat(child.path ? "/".concat(child.path) : "");
|
|
51
|
+
var newRoute = _object_spread_props(_object_spread({}, child), {
|
|
52
|
+
path: routePath.replace(/\/\//g, "/")
|
|
54
53
|
});
|
|
54
|
+
if (routePath.length > 0) {
|
|
55
|
+
delete newRoute.index;
|
|
56
|
+
} else {
|
|
57
|
+
delete newRoute.path;
|
|
58
|
+
}
|
|
59
|
+
return newRoute;
|
|
55
60
|
});
|
|
56
|
-
return newRoutes.flatMap(
|
|
57
|
-
return optimizeRoute(newRoute);
|
|
58
|
-
});
|
|
61
|
+
return Array.from(new Set(newRoutes)).flatMap(optimizeRoute);
|
|
59
62
|
} else {
|
|
60
|
-
|
|
63
|
+
var optimizedChildren = routeTree.children.flatMap(optimizeRoute);
|
|
61
64
|
return [
|
|
62
|
-
routeTree
|
|
65
|
+
_object_spread_props(_object_spread({}, routeTree), {
|
|
66
|
+
children: optimizedChildren
|
|
67
|
+
})
|
|
63
68
|
];
|
|
64
69
|
}
|
|
65
70
|
};
|
|
66
71
|
export var walk = function() {
|
|
67
72
|
var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
|
|
68
|
-
var _routePath, _finalRoute_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path,
|
|
73
|
+
var _routePath, _finalRoute_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path, optimizedRoutes;
|
|
69
74
|
return _ts_generator(this, function(_state) {
|
|
70
75
|
switch (_state.label) {
|
|
71
76
|
case 0:
|
|
@@ -277,17 +282,6 @@ export var walk = function() {
|
|
|
277
282
|
});
|
|
278
283
|
}
|
|
279
284
|
}
|
|
280
|
-
if (splatRoute) {
|
|
281
|
-
;
|
|
282
|
-
slatRouteIndex = (_childRoutes = childRoutes) === null || _childRoutes === void 0 ? void 0 : _childRoutes.findIndex(function(childRoute2) {
|
|
283
|
-
return childRoute2 === splatRoute;
|
|
284
|
-
});
|
|
285
|
-
if (typeof slatRouteIndex === "number" && slatRouteIndex !== -1) {
|
|
286
|
-
;
|
|
287
|
-
(_childRoutes1 = childRoutes) === null || _childRoutes1 === void 0 ? void 0 : _childRoutes1.splice(slatRouteIndex, 1);
|
|
288
|
-
(_childRoutes2 = childRoutes) === null || _childRoutes2 === void 0 ? void 0 : _childRoutes2.push(splatRoute);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
285
|
if (isRoot && !oldVersion) {
|
|
292
286
|
optimizedRoutes = optimizeRoute(finalRoute);
|
|
293
287
|
return [
|
|
@@ -29,9 +29,36 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
key: "getEntryChunks",
|
|
34
|
+
value: function getEntryChunks(compilation, chunks) {
|
|
35
|
+
var entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
36
|
+
var entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
|
37
|
+
return entrypoint[0];
|
|
38
|
+
});
|
|
39
|
+
var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
40
|
+
var _chunk_names;
|
|
41
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
|
|
42
|
+
return entryChunkIds.includes(name);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return entryChunks;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "getEntryChunkFiles",
|
|
50
|
+
value: 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
|
+
},
|
|
32
58
|
{
|
|
33
59
|
key: "apply",
|
|
34
60
|
value: function apply(compiler) {
|
|
61
|
+
var _this = this;
|
|
35
62
|
var target = compiler.options.target;
|
|
36
63
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
37
64
|
return;
|
|
@@ -45,13 +72,16 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
45
72
|
}
|
|
46
73
|
return path2;
|
|
47
74
|
};
|
|
48
|
-
var
|
|
75
|
+
var chunkToSource = /* @__PURE__ */ new Map();
|
|
76
|
+
var chunkToMap = /* @__PURE__ */ new Map();
|
|
77
|
+
var minimize = compiler.options.optimization.minimize;
|
|
49
78
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
|
|
79
|
+
var _this1 = _this;
|
|
50
80
|
compilation.hooks.processAssets.tapPromise({
|
|
51
81
|
name: PLUGIN_NAME,
|
|
52
82
|
stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING
|
|
53
83
|
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
54
|
-
var stats, _stats_chunks, chunks, namedChunkGroups,
|
|
84
|
+
var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, map;
|
|
55
85
|
return _ts_generator(this, function(_state) {
|
|
56
86
|
stats = compilation.getStats().toJson({
|
|
57
87
|
all: false,
|
|
@@ -65,16 +95,50 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
65
95
|
2
|
|
66
96
|
];
|
|
67
97
|
}
|
|
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);
|
|
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");
|
|
76
102
|
});
|
|
77
103
|
});
|
|
104
|
+
entryChunkFileIds = entryChunks.map(function(chunk) {
|
|
105
|
+
return chunk.id;
|
|
106
|
+
});
|
|
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;
|
|
113
|
+
}
|
|
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
|
+
}
|
|
141
|
+
entryChunks = _this2.getEntryChunks(compilation, chunks);
|
|
78
142
|
entryChunkFiles = entryChunks.map(function(chunk) {
|
|
79
143
|
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
80
144
|
return fname.includes(".js");
|
|
@@ -90,31 +154,30 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
90
154
|
if (!asset) {
|
|
91
155
|
continue;
|
|
92
156
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
source: source,
|
|
96
|
-
map: map
|
|
97
|
-
});
|
|
157
|
+
source = asset.sourceAndMap().source;
|
|
158
|
+
chunkToSource.set(chunkId, source);
|
|
98
159
|
}
|
|
99
160
|
return [
|
|
100
161
|
2
|
|
101
162
|
];
|
|
102
163
|
});
|
|
103
164
|
}));
|
|
165
|
+
var _this3 = _this;
|
|
104
166
|
compilation.hooks.processAssets.tapPromise({
|
|
105
167
|
name: PLUGIN_NAME,
|
|
106
168
|
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
107
169
|
}, /* @__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,
|
|
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;
|
|
109
171
|
return _ts_generator(this, function(_state) {
|
|
110
172
|
switch (_state.label) {
|
|
111
173
|
case 0:
|
|
112
174
|
_loop = function(i2) {
|
|
113
|
-
var file, chunkId, asset, relatedAssets, manifest2, injectedContent,
|
|
175
|
+
var _source, _source1, file, chunkNames, chunkId, asset, relatedAssets, manifest2, injectedContent, source, map, newContent, result, newSource;
|
|
114
176
|
return _ts_generator(this, function(_state2) {
|
|
115
177
|
switch (_state2.label) {
|
|
116
178
|
case 0:
|
|
117
179
|
file = entryChunkFiles[i2];
|
|
180
|
+
chunkNames = entryChunks[i2].names;
|
|
118
181
|
chunkId = entryChunkFileIds[i2];
|
|
119
182
|
asset = compilation.assets[file];
|
|
120
183
|
if (!asset || !chunkId) {
|
|
@@ -124,11 +187,18 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
124
187
|
];
|
|
125
188
|
}
|
|
126
189
|
relatedAssets = {};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
}
|
|
132
202
|
manifest2 = {
|
|
133
203
|
routeAssets: relatedAssets
|
|
134
204
|
};
|
|
@@ -140,19 +210,20 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
140
210
|
}
|
|
141
211
|
return v;
|
|
142
212
|
}), ";\n })();\n ");
|
|
143
|
-
|
|
144
|
-
|
|
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());
|
|
145
216
|
return [
|
|
146
217
|
4,
|
|
147
218
|
transform(newContent, {
|
|
148
219
|
loader: path.extname(file).slice(1),
|
|
149
220
|
sourcemap: true,
|
|
150
|
-
minify:
|
|
221
|
+
minify: minimize
|
|
151
222
|
})
|
|
152
223
|
];
|
|
153
224
|
case 1:
|
|
154
225
|
result = _state2.sent();
|
|
155
|
-
newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
226
|
+
newSource = new SourceMapSource(result.code, file, result.map, (_source1 = source) === null || _source1 === void 0 ? void 0 : _source1.toString(), map);
|
|
156
227
|
compilation.updateAsset(
|
|
157
228
|
file,
|
|
158
229
|
newSource,
|
|
@@ -227,28 +298,15 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
227
298
|
manifest = {
|
|
228
299
|
routeAssets: routeAssets
|
|
229
300
|
};
|
|
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
|
-
});
|
|
301
|
+
entryChunks = _this3.getEntryChunks(compilation, chunks);
|
|
302
|
+
entryChunkFiles = _this3.getEntryChunkFiles(entryChunks);
|
|
245
303
|
entryChunkFileIds = entryChunks.map(function(chunk) {
|
|
246
304
|
return chunk.id;
|
|
247
305
|
});
|
|
248
306
|
i = 0;
|
|
249
307
|
_state.label = 1;
|
|
250
308
|
case 1:
|
|
251
|
-
if (!(i
|
|
309
|
+
if (!(i < entryChunkFiles.length))
|
|
252
310
|
return [
|
|
253
311
|
3,
|
|
254
312
|
4
|
|
@@ -51,7 +51,18 @@ export function createDefaultConfig(appContext, bundler) {
|
|
|
51
51
|
baseUrl: "/",
|
|
52
52
|
port: 8080
|
|
53
53
|
};
|
|
54
|
-
var
|
|
54
|
+
var defaultTsCheckerConfig = {
|
|
55
|
+
tsChecker: {
|
|
56
|
+
issue: {
|
|
57
|
+
include: [
|
|
58
|
+
{
|
|
59
|
+
file: "**/src/**/*"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var tools = bundler === "webpack" ? _object_spread({}, defaultBuilderConfig.tools, defaultTsCheckerConfig) : defaultTsCheckerConfig;
|
|
55
66
|
return {
|
|
56
67
|
source: source,
|
|
57
68
|
output: output,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { initHtmlConfig, initSourceConfig
|
|
1
|
+
import { initHtmlConfig, initSourceConfig } from "./inits";
|
|
2
2
|
export function initialNormalizedConfig(config, appContext, bundler) {
|
|
3
3
|
initHtmlConfig(config, appContext);
|
|
4
4
|
initSourceConfig(config, appContext, bundler);
|
|
5
|
-
if (bundler === "webpack") {
|
|
6
|
-
initToolsConfig(config);
|
|
7
|
-
}
|
|
8
5
|
return config;
|
|
9
6
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
1
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
2
|
import path, { dirname, isAbsolute, posix, sep } from "path";
|
|
5
|
-
import {
|
|
3
|
+
import { findExists, findMonorepoRoot, globby, isModernjsMonorepo } from "@modern-js/utils";
|
|
6
4
|
export function initHtmlConfig(config, appContext) {
|
|
7
5
|
var createBuilderAppIcon = function createBuilderAppIcon2(config2, appContext2) {
|
|
8
6
|
var configDir = config2.source.configDir;
|
|
@@ -100,30 +98,3 @@ export function initSourceConfig(config, appContext, bundler) {
|
|
|
100
98
|
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
|
-
export function initToolsConfig(config) {
|
|
104
|
-
var defaultTsChecker = {
|
|
105
|
-
issue: {
|
|
106
|
-
include: [
|
|
107
|
-
{
|
|
108
|
-
file: "**/src/**/*"
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
exclude: [
|
|
112
|
-
{
|
|
113
|
-
file: "**/*.(spec|test).ts"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
file: "**/node_modules/**/*"
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var _config_tools = config.tools, tsChecker = _config_tools.tsChecker, tsLoader = _config_tools.tsLoader;
|
|
122
|
-
config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
|
|
123
|
-
tsLoader && (config.tools.tsLoader = function(tsLoaderConfig, utils) {
|
|
124
|
-
applyOptionsChain(_object_spread_props(_object_spread({}, tsLoaderConfig), {
|
|
125
|
-
transpileOnly: false,
|
|
126
|
-
allowTsInNodeModules: true
|
|
127
|
-
}), tsLoader || {}, utils);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
@@ -50,13 +50,13 @@ ${initialize || ""}`);
|
|
|
50
50
|
${initialize || ""}`).join("\n");
|
|
51
51
|
};
|
|
52
52
|
export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
53
|
-
var _config,
|
|
53
|
+
var _config, _config1;
|
|
54
54
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
55
55
|
const hookRunners = api.useHookRunners();
|
|
56
56
|
const isV5 = isRouterV5(config);
|
|
57
57
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
58
58
|
const importsStatemets = /* @__PURE__ */ new Map();
|
|
59
|
-
const oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean((_config1 = config) === null || _config1 === void 0 ? void 0 :
|
|
59
|
+
const oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean(((_config1 = config) === null || _config1 === void 0 ? void 0 : _config1.runtime.router).oldVersion) : false;
|
|
60
60
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
61
61
|
return {
|
|
62
62
|
importsStatemets
|
|
@@ -43,20 +43,28 @@ export const optimizeRoute = (routeTree) => {
|
|
|
43
43
|
];
|
|
44
44
|
}
|
|
45
45
|
const { children } = routeTree;
|
|
46
|
-
if (!routeTree._component) {
|
|
46
|
+
if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
|
|
47
47
|
const newRoutes = children.map((child) => {
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
return {
|
|
48
|
+
const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
|
|
49
|
+
const newRoute = {
|
|
51
50
|
...child,
|
|
52
|
-
path: routePath
|
|
51
|
+
path: routePath.replace(/\/\//g, "/")
|
|
53
52
|
};
|
|
53
|
+
if (routePath.length > 0) {
|
|
54
|
+
delete newRoute.index;
|
|
55
|
+
} else {
|
|
56
|
+
delete newRoute.path;
|
|
57
|
+
}
|
|
58
|
+
return newRoute;
|
|
54
59
|
});
|
|
55
|
-
return newRoutes.flatMap(
|
|
60
|
+
return Array.from(new Set(newRoutes)).flatMap(optimizeRoute);
|
|
56
61
|
} else {
|
|
57
|
-
|
|
62
|
+
const optimizedChildren = routeTree.children.flatMap(optimizeRoute);
|
|
58
63
|
return [
|
|
59
|
-
|
|
64
|
+
{
|
|
65
|
+
...routeTree,
|
|
66
|
+
children: optimizedChildren
|
|
67
|
+
}
|
|
60
68
|
];
|
|
61
69
|
}
|
|
62
70
|
};
|
|
@@ -177,15 +185,6 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
|
|
|
177
185
|
};
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
|
-
if (splatRoute) {
|
|
181
|
-
var _childRoutes;
|
|
182
|
-
const slatRouteIndex = (_childRoutes = childRoutes) === null || _childRoutes === void 0 ? void 0 : _childRoutes.findIndex((childRoute) => childRoute === splatRoute);
|
|
183
|
-
if (typeof slatRouteIndex === "number" && slatRouteIndex !== -1) {
|
|
184
|
-
var _childRoutes1, _childRoutes2;
|
|
185
|
-
(_childRoutes1 = childRoutes) === null || _childRoutes1 === void 0 ? void 0 : _childRoutes1.splice(slatRouteIndex, 1);
|
|
186
|
-
(_childRoutes2 = childRoutes) === null || _childRoutes2 === void 0 ? void 0 : _childRoutes2.push(splatRoute);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
188
|
if (isRoot && !oldVersion) {
|
|
190
189
|
const optimizedRoutes = optimizeRoute(finalRoute);
|
|
191
190
|
return optimizedRoutes;
|
|
@@ -14,6 +14,22 @@ export class RouterPlugin {
|
|
|
14
14
|
}
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
+
getEntryChunks(compilation, chunks) {
|
|
18
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
19
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
20
|
+
const entryChunks = [
|
|
21
|
+
...chunks
|
|
22
|
+
].filter((chunk) => {
|
|
23
|
+
var _chunk_names;
|
|
24
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
25
|
+
});
|
|
26
|
+
return entryChunks;
|
|
27
|
+
}
|
|
28
|
+
getEntryChunkFiles(entryChunks) {
|
|
29
|
+
return entryChunks.map((chunk) => [
|
|
30
|
+
...chunk.files || []
|
|
31
|
+
].find((fname) => fname.includes(".js")));
|
|
32
|
+
}
|
|
17
33
|
apply(compiler) {
|
|
18
34
|
const { target } = compiler.options;
|
|
19
35
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
@@ -28,7 +44,9 @@ export class RouterPlugin {
|
|
|
28
44
|
}
|
|
29
45
|
return path2;
|
|
30
46
|
};
|
|
31
|
-
const
|
|
47
|
+
const chunkToSource = /* @__PURE__ */ new Map();
|
|
48
|
+
const chunkToMap = /* @__PURE__ */ new Map();
|
|
49
|
+
const { minimize } = compiler.options.optimization;
|
|
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({
|
|
@@ -115,31 +153,31 @@ export class RouterPlugin {
|
|
|
115
153
|
const manifest = {
|
|
116
154
|
routeAssets
|
|
117
155
|
};
|
|
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")));
|
|
156
|
+
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
157
|
+
const entryChunkFiles = this.getEntryChunkFiles(entryChunks);
|
|
129
158
|
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
130
|
-
for (let i = 0; i
|
|
159
|
+
for (let i = 0; i < entryChunkFiles.length; i++) {
|
|
160
|
+
var _source, _source1;
|
|
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
|
+
var _chunkNames;
|
|
172
|
+
const segments = routeId.split("_");
|
|
173
|
+
const chunkName = segments[0];
|
|
174
|
+
if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
|
|
175
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
relatedAssets = routeAssets;
|
|
180
|
+
}
|
|
143
181
|
const manifest2 = {
|
|
144
182
|
routeAssets: relatedAssets
|
|
145
183
|
};
|
|
@@ -155,14 +193,15 @@ export class RouterPlugin {
|
|
|
155
193
|
})};
|
|
156
194
|
})();
|
|
157
195
|
`;
|
|
158
|
-
const
|
|
159
|
-
const
|
|
196
|
+
const source = chunkToSource.get(chunkId);
|
|
197
|
+
const map = chunkToMap.get(chunkId);
|
|
198
|
+
const newContent = `${injectedContent}${(_source = source) === null || _source === void 0 ? void 0 : _source.toString()}`;
|
|
160
199
|
const result = await transform(newContent, {
|
|
161
200
|
loader: path.extname(file).slice(1),
|
|
162
201
|
sourcemap: true,
|
|
163
|
-
minify:
|
|
202
|
+
minify: minimize
|
|
164
203
|
});
|
|
165
|
-
const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
204
|
+
const newSource = new SourceMapSource(result.code, file, result.map, (_source1 = source) === null || _source1 === void 0 ? void 0 : _source1.toString(), map);
|
|
166
205
|
compilation.updateAsset(
|
|
167
206
|
file,
|
|
168
207
|
newSource,
|
|
@@ -56,9 +56,21 @@ export function createDefaultConfig(appContext, bundler) {
|
|
|
56
56
|
baseUrl: "/",
|
|
57
57
|
port: 8080
|
|
58
58
|
};
|
|
59
|
+
const defaultTsCheckerConfig = {
|
|
60
|
+
tsChecker: {
|
|
61
|
+
issue: {
|
|
62
|
+
include: [
|
|
63
|
+
{
|
|
64
|
+
file: "**/src/**/*"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
59
70
|
const tools = bundler === "webpack" ? {
|
|
60
|
-
...defaultBuilderConfig.tools
|
|
61
|
-
|
|
71
|
+
...defaultBuilderConfig.tools,
|
|
72
|
+
...defaultTsCheckerConfig
|
|
73
|
+
} : defaultTsCheckerConfig;
|
|
62
74
|
return {
|
|
63
75
|
source,
|
|
64
76
|
output,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { initHtmlConfig, initSourceConfig
|
|
1
|
+
import { initHtmlConfig, initSourceConfig } from "./inits";
|
|
2
2
|
export function initialNormalizedConfig(config, appContext, bundler) {
|
|
3
3
|
initHtmlConfig(config, appContext);
|
|
4
4
|
initSourceConfig(config, appContext, bundler);
|
|
5
|
-
if (bundler === "webpack") {
|
|
6
|
-
initToolsConfig(config);
|
|
7
|
-
}
|
|
8
5
|
return config;
|
|
9
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path, { dirname, isAbsolute, posix, sep } from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { findExists, findMonorepoRoot, globby, isModernjsMonorepo } from "@modern-js/utils";
|
|
3
3
|
export function initHtmlConfig(config, appContext) {
|
|
4
4
|
const ICON_EXTENSIONS = [
|
|
5
5
|
"png",
|
|
@@ -93,31 +93,3 @@ export function initSourceConfig(config, appContext, bundler) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
export function initToolsConfig(config) {
|
|
97
|
-
const defaultTsChecker = {
|
|
98
|
-
issue: {
|
|
99
|
-
include: [
|
|
100
|
-
{
|
|
101
|
-
file: "**/src/**/*"
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
exclude: [
|
|
105
|
-
{
|
|
106
|
-
file: "**/*.(spec|test).ts"
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
file: "**/node_modules/**/*"
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const { tsChecker, tsLoader } = config.tools;
|
|
115
|
-
config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
|
|
116
|
-
tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
|
|
117
|
-
applyOptionsChain({
|
|
118
|
-
...tsLoaderConfig,
|
|
119
|
-
transpileOnly: false,
|
|
120
|
-
allowTsInNodeModules: true
|
|
121
|
-
}, tsLoader || {}, utils);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
@@ -10,6 +10,8 @@ export interface RouteAssets {
|
|
|
10
10
|
type Compiler = webpack.Compiler | Rspack.Compiler;
|
|
11
11
|
export declare class RouterPlugin {
|
|
12
12
|
private isTargetNodeOrWebWorker;
|
|
13
|
+
private getEntryChunks;
|
|
14
|
+
private getEntryChunkFiles;
|
|
13
15
|
apply(compiler: Compiler): void;
|
|
14
16
|
}
|
|
15
17
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { AppNormalizedConfig, IAppContext } from '../../types';
|
|
2
2
|
export declare function initHtmlConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext): import("@modern-js/builder-shared").SharedHtmlConfig;
|
|
3
|
-
export declare function initSourceConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext, bundler: 'webpack' | 'rspack'): void;
|
|
4
|
-
export declare function initToolsConfig(config: AppNormalizedConfig<'webpack'>): void;
|
|
3
|
+
export declare function initSourceConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext, bundler: 'webpack' | 'rspack'): void;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.28.1-alpha.
|
|
18
|
+
"version": "2.28.1-alpha.3",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -74,22 +74,22 @@
|
|
|
74
74
|
"rspack-plugin-virtual-module": "0.1.0",
|
|
75
75
|
"@swc/helpers": "0.5.1",
|
|
76
76
|
"@modern-js/builder": "2.28.0",
|
|
77
|
+
"@modern-js/builder-plugin-node-polyfill": "2.28.0",
|
|
77
78
|
"@modern-js/builder-shared": "2.28.0",
|
|
78
|
-
"@modern-js/
|
|
79
|
+
"@modern-js/new-action": "2.28.0",
|
|
79
80
|
"@modern-js/core": "2.28.0",
|
|
80
|
-
"@modern-js/node-bundle-require": "2.28.0",
|
|
81
81
|
"@modern-js/plugin": "2.28.0",
|
|
82
|
-
"@modern-js/builder-plugin-
|
|
83
|
-
"@modern-js/new-action": "2.28.0",
|
|
84
|
-
"@modern-js/plugin-i18n": "2.28.0",
|
|
82
|
+
"@modern-js/builder-plugin-esbuild": "2.28.0",
|
|
85
83
|
"@modern-js/prod-server": "2.28.0",
|
|
86
|
-
"@modern-js/
|
|
84
|
+
"@modern-js/builder-webpack-provider": "2.28.0",
|
|
87
85
|
"@modern-js/server": "2.28.0",
|
|
88
|
-
"@modern-js/types": "2.28.0",
|
|
89
86
|
"@modern-js/upgrade": "2.28.0",
|
|
87
|
+
"@modern-js/node-bundle-require": "2.28.0",
|
|
88
|
+
"@modern-js/plugin-i18n": "2.28.0",
|
|
89
|
+
"@modern-js/types": "2.28.0",
|
|
90
90
|
"@modern-js/utils": "2.28.0",
|
|
91
|
+
"@modern-js/plugin-lint": "2.28.0",
|
|
91
92
|
"@modern-js/server-core": "2.28.0",
|
|
92
|
-
"@modern-js/builder-plugin-esbuild": "2.28.0",
|
|
93
93
|
"@modern-js/plugin-data-loader": "2.28.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"jest": "^29",
|
|
100
100
|
"typescript": "^5",
|
|
101
101
|
"webpack": "^5.88.1",
|
|
102
|
-
"@
|
|
102
|
+
"@modern-js/builder-plugin-swc": "2.28.0",
|
|
103
103
|
"@scripts/jest-config": "2.28.0",
|
|
104
104
|
"@modern-js/builder-rspack-provider": "2.28.0",
|
|
105
|
-
"@
|
|
105
|
+
"@scripts/build": "2.28.0"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"@modern-js/builder-rspack-provider": "^2.28.0"
|