@modern-js/app-tools 2.0.1 → 2.0.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/js/modern/analyze/generateCode.js +4 -81
- package/dist/js/modern/analyze/index.js +26 -12
- package/dist/js/modern/analyze/nestedRoutes.js +2 -15
- package/dist/js/modern/analyze/templates.js +35 -60
- package/dist/js/modern/analyze/utils.js +9 -1
- package/dist/js/modern/config/initial/inits.js +1 -9
- package/dist/js/modern/index.js +6 -7
- package/dist/js/modern/locale/en.js +2 -1
- package/dist/js/modern/locale/zh.js +2 -1
- package/dist/js/node/analyze/generateCode.js +2 -77
- package/dist/js/node/analyze/index.js +24 -10
- package/dist/js/node/analyze/nestedRoutes.js +1 -14
- package/dist/js/node/analyze/templates.js +35 -60
- package/dist/js/node/analyze/utils.js +10 -1
- package/dist/js/node/config/initial/inits.js +1 -9
- package/dist/js/node/index.js +2 -3
- package/dist/js/node/locale/en.js +2 -1
- package/dist/js/node/locale/zh.js +2 -1
- package/dist/js/treeshaking/analyze/generateCode.js +21 -148
- package/dist/js/treeshaking/analyze/index.js +25 -18
- package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
- package/dist/js/treeshaking/analyze/templates.js +97 -76
- package/dist/js/treeshaking/analyze/utils.js +5 -2
- package/dist/js/treeshaking/config/initial/inits.js +1 -12
- package/dist/js/treeshaking/index.js +8 -9
- package/dist/js/treeshaking/locale/en.js +2 -1
- package/dist/js/treeshaking/locale/zh.js +2 -1
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/package.json +24 -24
- package/dist/js/modern/analyze/Builder.js +0 -39
- package/dist/js/node/analyze/Builder.js +0 -64
- package/dist/js/treeshaking/analyze/Builder.js +0 -199
- package/dist/types/analyze/Builder.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 39988b2: feat: advance the timing of static resource loading
|
|
8
|
+
feat: 将嵌套路由下静态资源加载时机提前
|
|
9
|
+
- Updated dependencies [39988b2]
|
|
10
|
+
- @modern-js/types@2.0.2
|
|
11
|
+
- @modern-js/new-action@2.0.2
|
|
12
|
+
- @modern-js/builder-shared@2.0.2
|
|
13
|
+
- @modern-js/builder-webpack-provider@2.0.2
|
|
14
|
+
- @modern-js/core@2.0.2
|
|
15
|
+
- @modern-js/plugin-data-loader@2.0.2
|
|
16
|
+
- @modern-js/prod-server@2.0.2
|
|
17
|
+
- @modern-js/server@2.0.2
|
|
18
|
+
- @modern-js/utils@2.0.2
|
|
19
|
+
- @modern-js/builder@2.0.2
|
|
20
|
+
- @modern-js/builder-plugin-esbuild@2.0.2
|
|
21
|
+
- @modern-js/builder-plugin-node-polyfill@2.0.2
|
|
22
|
+
- @modern-js/plugin-i18n@2.0.2
|
|
23
|
+
- @modern-js/plugin-lint@2.0.2
|
|
24
|
+
- @modern-js/node-bundle-require@2.0.2
|
|
25
|
+
- @modern-js/plugin@2.0.2
|
|
26
|
+
- @modern-js/upgrade@2.0.2
|
|
27
|
+
|
|
3
28
|
## 2.0.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -22,29 +22,20 @@ import path from "path";
|
|
|
22
22
|
import {
|
|
23
23
|
fs,
|
|
24
24
|
getEntryOptions,
|
|
25
|
-
LOADER_ROUTES_DIR,
|
|
26
25
|
logger
|
|
27
26
|
} from "@modern-js/utils";
|
|
28
27
|
import {
|
|
29
28
|
useResolvedConfigContext
|
|
30
29
|
} from "@modern-js/core";
|
|
31
|
-
import { isDevCommand } from "../utils/commands";
|
|
32
30
|
import * as templates from "./templates";
|
|
33
31
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
34
32
|
import {
|
|
35
33
|
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
36
34
|
ENTRY_POINT_FILE_NAME,
|
|
37
|
-
ENTRY_BOOTSTRAP_FILE_NAME
|
|
38
|
-
TEMP_LOADERS_DIR
|
|
35
|
+
ENTRY_BOOTSTRAP_FILE_NAME
|
|
39
36
|
} from "./constants";
|
|
40
|
-
import { getDefaultImports } from "./utils";
|
|
37
|
+
import { getDefaultImports, getServerLoadersFile } from "./utils";
|
|
41
38
|
import { walk } from "./nestedRoutes";
|
|
42
|
-
import { loaderBuilder, serverLoaderBuilder } from "./Builder";
|
|
43
|
-
const loader = {
|
|
44
|
-
".js": "jsx",
|
|
45
|
-
".ts": "tsx"
|
|
46
|
-
};
|
|
47
|
-
const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
48
39
|
const createImportSpecifier = (specifiers) => {
|
|
49
40
|
let defaults = "";
|
|
50
41
|
const named = [];
|
|
@@ -92,49 +83,6 @@ ${initialize || ""}`
|
|
|
92
83
|
${initialize || ""}`
|
|
93
84
|
).join("\n");
|
|
94
85
|
};
|
|
95
|
-
const buildLoader = (entry, outfile) => __async(void 0, null, function* () {
|
|
96
|
-
yield loaderBuilder.build({
|
|
97
|
-
format: "esm",
|
|
98
|
-
platform: "browser",
|
|
99
|
-
target: "esnext",
|
|
100
|
-
loader,
|
|
101
|
-
watch: isDevCommand() && {},
|
|
102
|
-
bundle: true,
|
|
103
|
-
logLevel: "error",
|
|
104
|
-
entryPoints: [entry],
|
|
105
|
-
outfile,
|
|
106
|
-
plugins: [
|
|
107
|
-
{
|
|
108
|
-
name: "make-all-packages-external",
|
|
109
|
-
setup(build) {
|
|
110
|
-
build.onResolve({ filter: EXTERNAL_REGEXP }, (args) => {
|
|
111
|
-
let external = true;
|
|
112
|
-
if (args.kind === "entry-point") {
|
|
113
|
-
external = false;
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
path: args.path,
|
|
117
|
-
external
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
|
|
126
|
-
yield serverLoaderBuilder.build({
|
|
127
|
-
format: "cjs",
|
|
128
|
-
platform: "node",
|
|
129
|
-
target: "esnext",
|
|
130
|
-
loader,
|
|
131
|
-
watch: isDevCommand() && {},
|
|
132
|
-
bundle: true,
|
|
133
|
-
logLevel: "error",
|
|
134
|
-
entryPoints: [entry],
|
|
135
|
-
outfile
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
86
|
const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
|
|
139
87
|
var _a, _b, _c;
|
|
140
88
|
const {
|
|
@@ -225,16 +173,9 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
225
173
|
})
|
|
226
174
|
});
|
|
227
175
|
if (entrypoint.nestedRoutesEntry) {
|
|
228
|
-
const routesServerFile =
|
|
176
|
+
const routesServerFile = getServerLoadersFile(
|
|
229
177
|
internalDirectory,
|
|
230
|
-
entryName
|
|
231
|
-
"route-server-loaders.js"
|
|
232
|
-
);
|
|
233
|
-
const outputRoutesServerFile = path.join(
|
|
234
|
-
distDirectory,
|
|
235
|
-
LOADER_ROUTES_DIR,
|
|
236
|
-
entryName,
|
|
237
|
-
"index.js"
|
|
178
|
+
entryName
|
|
238
179
|
);
|
|
239
180
|
const code3 = templates.routesForServer({
|
|
240
181
|
routes,
|
|
@@ -243,24 +184,6 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
243
184
|
});
|
|
244
185
|
yield fs.ensureFile(routesServerFile);
|
|
245
186
|
yield fs.writeFile(routesServerFile, code3);
|
|
246
|
-
const loaderEntryFile = path.join(
|
|
247
|
-
internalDirectory,
|
|
248
|
-
entryName,
|
|
249
|
-
TEMP_LOADERS_DIR,
|
|
250
|
-
"entry.js"
|
|
251
|
-
);
|
|
252
|
-
const loaderIndexFile = path.join(
|
|
253
|
-
internalDirectory,
|
|
254
|
-
entryName,
|
|
255
|
-
TEMP_LOADERS_DIR,
|
|
256
|
-
"index.js"
|
|
257
|
-
);
|
|
258
|
-
if (yield fs.pathExists(loaderEntryFile)) {
|
|
259
|
-
yield buildLoader(loaderEntryFile, loaderIndexFile);
|
|
260
|
-
}
|
|
261
|
-
if (yield fs.pathExists(routesServerFile)) {
|
|
262
|
-
yield buildServerLoader(routesServerFile, outputRoutesServerFile);
|
|
263
|
-
}
|
|
264
187
|
}
|
|
265
188
|
fs.outputFileSync(
|
|
266
189
|
path.resolve(
|
|
@@ -38,7 +38,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import * as path from "path";
|
|
41
|
-
import { createDebugger, findExists, fs, isApiOnly } from "@modern-js/utils";
|
|
41
|
+
import { createDebugger, findExists, fs, isApiOnly, isUseSSRBundle } from "@modern-js/utils";
|
|
42
42
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
43
43
|
import { createBuilderForModern } from "../builder";
|
|
44
44
|
import { printInstructions } from "../utils/printInstructions";
|
|
@@ -47,12 +47,11 @@ import { emitResolvedConfig } from "../utils/config";
|
|
|
47
47
|
import { getCommand } from "../utils/commands";
|
|
48
48
|
import { initialNormalizedConfig } from "../config";
|
|
49
49
|
import {
|
|
50
|
-
|
|
50
|
+
getServerLoadersFile,
|
|
51
51
|
isPageComponentFile,
|
|
52
52
|
parseModule,
|
|
53
53
|
replaceWithAlias
|
|
54
54
|
} from "./utils";
|
|
55
|
-
import { loaderBuilder, serverLoaderBuilder } from "./Builder";
|
|
56
55
|
import {
|
|
57
56
|
APP_CONFIG_NAME,
|
|
58
57
|
APP_INIT_EXPORTED,
|
|
@@ -207,6 +206,27 @@ var analyze_default = () => ({
|
|
|
207
206
|
watchFiles() {
|
|
208
207
|
return pagesDir;
|
|
209
208
|
},
|
|
209
|
+
config() {
|
|
210
|
+
return {
|
|
211
|
+
tools: {
|
|
212
|
+
webpackChain: (chain, { name, CHAIN_ID }) => {
|
|
213
|
+
const appContext = api.useAppContext();
|
|
214
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
215
|
+
const { entrypoints, internalDirectory } = appContext;
|
|
216
|
+
entrypoints.forEach((entrypoint) => {
|
|
217
|
+
const { entryName } = entrypoint;
|
|
218
|
+
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(resolvedConfig)) {
|
|
219
|
+
const serverLoadersFile = getServerLoadersFile(
|
|
220
|
+
internalDirectory,
|
|
221
|
+
entryName
|
|
222
|
+
);
|
|
223
|
+
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
},
|
|
210
230
|
resolvedConfig({ resolved }) {
|
|
211
231
|
const appContext = api.useAppContext();
|
|
212
232
|
const config = initialNormalizedConfig(resolved, appContext);
|
|
@@ -217,7 +237,7 @@ var analyze_default = () => ({
|
|
|
217
237
|
modifyEntryImports(_0) {
|
|
218
238
|
return __async(this, arguments, function* ({ entrypoint, imports }) {
|
|
219
239
|
const appContext = api.useAppContext();
|
|
220
|
-
const { srcDirectory } = appContext;
|
|
240
|
+
const { srcDirectory, internalSrcAlias } = appContext;
|
|
221
241
|
const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
|
|
222
242
|
if (fileSystemRoutes && nestedRoutesEntry) {
|
|
223
243
|
const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
|
|
@@ -239,7 +259,7 @@ var analyze_default = () => ({
|
|
|
239
259
|
const generateLayoutPath = replaceWithAlias(
|
|
240
260
|
srcDirectory,
|
|
241
261
|
rootLayoutFile,
|
|
242
|
-
|
|
262
|
+
internalSrcAlias
|
|
243
263
|
);
|
|
244
264
|
if (hasAppConfig) {
|
|
245
265
|
imports.push({
|
|
@@ -266,12 +286,6 @@ var analyze_default = () => ({
|
|
|
266
286
|
};
|
|
267
287
|
});
|
|
268
288
|
},
|
|
269
|
-
beforeRestart() {
|
|
270
|
-
return __async(this, null, function* () {
|
|
271
|
-
serverLoaderBuilder.stop();
|
|
272
|
-
loaderBuilder.stop();
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
289
|
fileChange(e) {
|
|
276
290
|
return __async(this, null, function* () {
|
|
277
291
|
const appContext = api.useAppContext();
|
|
@@ -280,7 +294,7 @@ var analyze_default = () => ({
|
|
|
280
294
|
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
281
295
|
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
282
296
|
const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
|
283
|
-
if (isRouteComponent && (eventType === "add" || eventType === "unlink")
|
|
297
|
+
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
284
298
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
285
299
|
const { generateCode } = yield import("./generateCode");
|
|
286
300
|
const entrypoints = cloneDeep(originEntrypoints);
|
|
@@ -40,14 +40,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
40
40
|
import * as path from "path";
|
|
41
41
|
import { fs, getRouteId } from "@modern-js/utils";
|
|
42
42
|
import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
|
|
43
|
-
import {
|
|
43
|
+
import { replaceWithAlias } from "./utils";
|
|
44
44
|
const conventionNames = Object.values(NESTED_ROUTE);
|
|
45
|
-
const getLoaderPath = (filename) => __async(void 0, null, function* () {
|
|
46
|
-
if (yield hasLoader(filename)) {
|
|
47
|
-
return filename;
|
|
48
|
-
}
|
|
49
|
-
return void 0;
|
|
50
|
-
});
|
|
51
45
|
const replaceDynamicPath = (routePath) => {
|
|
52
46
|
return routePath.replace(/\[(.*?)\]/g, ":$1");
|
|
53
47
|
};
|
|
@@ -118,10 +112,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
118
112
|
}
|
|
119
113
|
if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
|
|
120
114
|
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
121
|
-
const loaderPath = yield getLoaderPath(itemPath);
|
|
122
|
-
if (loaderPath) {
|
|
123
|
-
route.loader = loaderPath;
|
|
124
|
-
}
|
|
125
115
|
}
|
|
126
116
|
if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
|
|
127
117
|
pageLoaderFile = itemPath;
|
|
@@ -135,10 +125,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
135
125
|
itemPath,
|
|
136
126
|
entryName
|
|
137
127
|
);
|
|
138
|
-
|
|
139
|
-
if (loaderPath) {
|
|
140
|
-
pageRoute.loader = loaderPath;
|
|
141
|
-
} else if (pageLoaderFile) {
|
|
128
|
+
if (pageLoaderFile) {
|
|
142
129
|
pageRoute.loader = pageLoaderFile;
|
|
143
130
|
}
|
|
144
131
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
@@ -175,10 +175,9 @@ const routesForServer = ({
|
|
|
175
175
|
];`;
|
|
176
176
|
let importLoadersCode = "";
|
|
177
177
|
if (loaders.length > 0) {
|
|
178
|
-
importLoadersCode =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
)} } from "${slash(loaderIndexFile)}"`;
|
|
178
|
+
importLoadersCode = loaders.map((loader, index2) => {
|
|
179
|
+
return `import loader_${index2} from "${loader}"`;
|
|
180
|
+
}).join("\n");
|
|
182
181
|
}
|
|
183
182
|
return `
|
|
184
183
|
${importLoadersCode}
|
|
@@ -197,12 +196,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
197
196
|
const errors = [];
|
|
198
197
|
const loaders = [];
|
|
199
198
|
const loadersMap = {};
|
|
200
|
-
const loadersIndexFile = path.join(
|
|
201
|
-
internalDirAlias,
|
|
202
|
-
entryName,
|
|
203
|
-
TEMP_LOADERS_DIR,
|
|
204
|
-
"index.js"
|
|
205
|
-
);
|
|
206
199
|
const loadersMapFile = path.join(
|
|
207
200
|
internalDirectory,
|
|
208
201
|
entryName,
|
|
@@ -214,13 +207,17 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
214
207
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
215
208
|
`;
|
|
216
209
|
let rootLayoutCode = ``;
|
|
217
|
-
let dataLoaderPath = "";
|
|
218
210
|
let componentLoaderPath = "";
|
|
219
|
-
|
|
220
|
-
|
|
211
|
+
const getDataLoaderPath = (loaderId) => {
|
|
212
|
+
if (!ssrMode)
|
|
213
|
+
return "";
|
|
214
|
+
let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
221
215
|
if (nestedRoutesEntry) {
|
|
222
|
-
dataLoaderPath = `${dataLoaderPath}?
|
|
216
|
+
dataLoaderPath = `${slash(dataLoaderPath)}?mapFile=${slash(loadersMapFile)}&loaderId=${loaderId}!`;
|
|
223
217
|
}
|
|
218
|
+
return dataLoaderPath;
|
|
219
|
+
};
|
|
220
|
+
if (ssrMode) {
|
|
224
221
|
componentLoaderPath = `${path.join(
|
|
225
222
|
__dirname,
|
|
226
223
|
"../builder/loaders/routerLoader"
|
|
@@ -236,6 +233,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
236
233
|
let error;
|
|
237
234
|
let loader;
|
|
238
235
|
let component = "";
|
|
236
|
+
let lazyImport = null;
|
|
239
237
|
if (route.type === "nested") {
|
|
240
238
|
if (route.loading) {
|
|
241
239
|
loadings.push(route.loading);
|
|
@@ -249,22 +247,30 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
249
247
|
loaders.push(route.loader);
|
|
250
248
|
const loaderId = loaders.length - 1;
|
|
251
249
|
loader = `loader_${loaderId}`;
|
|
252
|
-
loadersMap[loader] =
|
|
250
|
+
loadersMap[loader] = {
|
|
251
|
+
routeId: route.id,
|
|
252
|
+
filePath: route.loader,
|
|
253
|
+
inline: false
|
|
254
|
+
};
|
|
253
255
|
}
|
|
254
256
|
if (route._component) {
|
|
255
257
|
if (route.isRoot) {
|
|
256
258
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
257
259
|
component = `RootLayout`;
|
|
258
260
|
} else if (ssrMode === "string") {
|
|
259
|
-
|
|
261
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
|
|
262
|
+
component = `loadable(${lazyImport})`;
|
|
260
263
|
} else {
|
|
261
|
-
|
|
264
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
|
|
265
|
+
component = `lazy(${lazyImport})`;
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
} else if (route._component) {
|
|
265
|
-
|
|
269
|
+
lazyImport = `() => import('${route._component}')`;
|
|
270
|
+
component = `loadable(${lazyImport})`;
|
|
266
271
|
}
|
|
267
272
|
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
273
|
+
lazyImport,
|
|
268
274
|
loading,
|
|
269
275
|
loader,
|
|
270
276
|
error,
|
|
@@ -281,7 +287,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
281
287
|
for (const route of routes) {
|
|
282
288
|
if ("type" in route) {
|
|
283
289
|
const newRoute = traverseRouteTree(route);
|
|
284
|
-
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(lazy.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
290
|
+
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
285
291
|
} else {
|
|
286
292
|
const component = `loadable(() => import('${route._component}'))`;
|
|
287
293
|
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
@@ -301,48 +307,17 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
301
307
|
`;
|
|
302
308
|
}).join("");
|
|
303
309
|
let importLoadersCode = "";
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}).join("\n");
|
|
313
|
-
const loaderEntryFile = path.join(
|
|
314
|
-
internalDirectory,
|
|
315
|
-
entryName,
|
|
316
|
-
TEMP_LOADERS_DIR,
|
|
317
|
-
"entry.js"
|
|
318
|
-
);
|
|
319
|
-
yield fs.ensureFile(loaderEntryFile);
|
|
320
|
-
yield fs.writeFile(loaderEntryFile, loaderEntryCode);
|
|
321
|
-
yield fs.writeJSON(loadersMapFile, loadersMap);
|
|
322
|
-
yield Promise.all(
|
|
323
|
-
loaders.map((loader, index2) => __async(void 0, null, function* () {
|
|
324
|
-
const name = `loader_${index2}`;
|
|
325
|
-
const filename = path.join(
|
|
326
|
-
internalDirectory,
|
|
327
|
-
entryName,
|
|
328
|
-
TEMP_LOADERS_DIR,
|
|
329
|
-
`${name}.js`
|
|
330
|
-
);
|
|
331
|
-
let code = "";
|
|
332
|
-
if (loader.includes(".loader.")) {
|
|
333
|
-
code = `
|
|
334
|
-
export { default as ${name} } from '${slash(loader)}'
|
|
335
|
-
`;
|
|
336
|
-
} else {
|
|
337
|
-
code = `
|
|
338
|
-
export { loader as ${name} } from '${slash(loader)}'
|
|
339
|
-
`;
|
|
340
|
-
}
|
|
341
|
-
yield fs.ensureFile(filename);
|
|
342
|
-
yield fs.writeFile(filename, code);
|
|
343
|
-
}))
|
|
344
|
-
);
|
|
310
|
+
for (const [key, loaderInfo] of Object.entries(loadersMap)) {
|
|
311
|
+
if (loaderInfo.inline) {
|
|
312
|
+
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
|
|
313
|
+
`;
|
|
314
|
+
} else {
|
|
315
|
+
importLoadersCode += `import ${key} from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
|
|
316
|
+
`;
|
|
317
|
+
}
|
|
345
318
|
}
|
|
319
|
+
yield fs.ensureFile(loadersMapFile);
|
|
320
|
+
yield fs.writeJSON(loadersMapFile, loadersMap);
|
|
346
321
|
return `
|
|
347
322
|
${importLazyCode}
|
|
348
323
|
${rootLayoutCode}
|
|
@@ -107,7 +107,7 @@ const isPageComponentFile = (filePath) => {
|
|
|
107
107
|
};
|
|
108
108
|
const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
|
|
109
109
|
const reg = new RegExp(
|
|
110
|
-
`(${NESTED_ROUTE.LAYOUT_FILE}|${NESTED_ROUTE.PAGE_FILE}
|
|
110
|
+
`(${NESTED_ROUTE.LAYOUT_FILE}|${NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
|
|
111
111
|
);
|
|
112
112
|
return nestedRouteEntries.some((nestedRoutesEntry) => {
|
|
113
113
|
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
@@ -139,8 +139,16 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
|
|
|
139
139
|
});
|
|
140
140
|
return moduleExports.some((e) => e.n === LOADER_EXPORT_NAME);
|
|
141
141
|
});
|
|
142
|
+
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
143
|
+
return path.join(
|
|
144
|
+
internalDirectory,
|
|
145
|
+
entryName,
|
|
146
|
+
"route-server-loaders.js"
|
|
147
|
+
);
|
|
148
|
+
};
|
|
142
149
|
export {
|
|
143
150
|
getDefaultImports,
|
|
151
|
+
getServerLoadersFile,
|
|
144
152
|
hasLoader,
|
|
145
153
|
isNestedRouteComponent,
|
|
146
154
|
isPageComponentFile,
|
|
@@ -132,7 +132,7 @@ function initToolsConfig(config) {
|
|
|
132
132
|
]
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
const { tsChecker, tsLoader
|
|
135
|
+
const { tsChecker, tsLoader } = config.tools;
|
|
136
136
|
config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
|
|
137
137
|
tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
|
|
138
138
|
applyOptionsChain(
|
|
@@ -144,14 +144,6 @@ function initToolsConfig(config) {
|
|
|
144
144
|
utils
|
|
145
145
|
);
|
|
146
146
|
});
|
|
147
|
-
config.tools.htmlPlugin = [
|
|
148
|
-
(config2) => __spreadProps(__spreadValues({}, config2), {
|
|
149
|
-
minify: typeof config2.minify === "object" ? __spreadProps(__spreadValues({}, config2.minify), {
|
|
150
|
-
removeComments: false
|
|
151
|
-
}) : config2.minify
|
|
152
|
-
}),
|
|
153
|
-
...Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : []
|
|
154
|
-
];
|
|
155
147
|
}
|
|
156
148
|
export {
|
|
157
149
|
initHtmlConfig,
|
package/dist/js/modern/index.js
CHANGED
|
@@ -38,11 +38,11 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import path from "path";
|
|
41
|
-
import
|
|
41
|
+
import lintPlugin from "@modern-js/plugin-lint";
|
|
42
42
|
import { cleanRequireCache, emptyDir, Import } from "@modern-js/utils";
|
|
43
43
|
import { castArray } from "@modern-js/utils/lodash";
|
|
44
|
-
import
|
|
45
|
-
import
|
|
44
|
+
import analyzePlugin from "./analyze";
|
|
45
|
+
import initializePlugin from "./initialize";
|
|
46
46
|
import { hooks } from "./hooks";
|
|
47
47
|
import { i18n, localeKeys } from "./locale";
|
|
48
48
|
import { getLocaleLanguage } from "./utils/language";
|
|
@@ -83,7 +83,6 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
|
|
|
83
83
|
const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action((options) => __async(void 0, null, function* () {
|
|
84
84
|
const { build } = yield import("./commands/build");
|
|
85
85
|
yield build(api, options);
|
|
86
|
-
process.exit(0);
|
|
87
86
|
}));
|
|
88
87
|
for (const platformBuilder of platformBuilders) {
|
|
89
88
|
const platforms = castArray(platformBuilder.platform);
|
|
@@ -112,7 +111,7 @@ var src_default = () => ({
|
|
|
112
111
|
"@modern-js/plugin-polyfill"
|
|
113
112
|
],
|
|
114
113
|
registerHook: hooks,
|
|
115
|
-
usePlugins: [
|
|
114
|
+
usePlugins: [initializePlugin(), analyzePlugin(), lintPlugin()],
|
|
116
115
|
setup: (api) => {
|
|
117
116
|
const locale = getLocaleLanguage();
|
|
118
117
|
i18n.changeLanguage({ locale });
|
|
@@ -138,12 +137,12 @@ var src_default = () => ({
|
|
|
138
137
|
yield deploy(api, options);
|
|
139
138
|
process.exit(0);
|
|
140
139
|
}));
|
|
141
|
-
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option(
|
|
140
|
+
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option(
|
|
142
141
|
"-c, --config <config>",
|
|
143
142
|
i18n.t(localeKeys.command.new.config)
|
|
144
143
|
).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
|
|
145
144
|
const { MWANewAction } = yield import("@modern-js/new-action");
|
|
146
|
-
yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale }));
|
|
145
|
+
yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
|
|
147
146
|
}));
|
|
148
147
|
program.command("inspect").description("inspect internal webpack config").option(
|
|
149
148
|
`--env <env>`,
|
|
@@ -19,7 +19,8 @@ const EN_LOCALE = {
|
|
|
19
19
|
debug: "using debug mode to log something",
|
|
20
20
|
config: "set default generator config(json string)",
|
|
21
21
|
distTag: `use specified tag version for it's generator`,
|
|
22
|
-
registry: "set npm registry url to run npm command"
|
|
22
|
+
registry: "set npm registry url to run npm command",
|
|
23
|
+
lang: "set new command language(en or zh)"
|
|
23
24
|
},
|
|
24
25
|
inspect: {
|
|
25
26
|
env: "specify env mode",
|
|
@@ -19,7 +19,8 @@ const ZH_LOCALE = {
|
|
|
19
19
|
debug: "开启 Debug 模式,打印调试日志信息",
|
|
20
20
|
config: "生成器运行默认配置(JSON 字符串)",
|
|
21
21
|
distTag: "生成器使用特殊的 npm Tag 版本",
|
|
22
|
-
registry: "生成器运行过程中定制 npm Registry"
|
|
22
|
+
registry: "生成器运行过程中定制 npm Registry",
|
|
23
|
+
lang: "设置 new 命令执行语言(zh 或者 en)"
|
|
23
24
|
},
|
|
24
25
|
inspect: {
|
|
25
26
|
env: "查看指定环境下的配置",
|
|
@@ -50,18 +50,11 @@ module.exports = __toCommonJS(generateCode_exports);
|
|
|
50
50
|
var import_path = __toESM(require("path"));
|
|
51
51
|
var import_utils = require("@modern-js/utils");
|
|
52
52
|
var import_core = require("@modern-js/core");
|
|
53
|
-
var import_commands = require("../utils/commands");
|
|
54
53
|
var templates = __toESM(require("./templates"));
|
|
55
54
|
var import_getClientRoutes = require("./getClientRoutes");
|
|
56
55
|
var import_constants = require("./constants");
|
|
57
56
|
var import_utils2 = require("./utils");
|
|
58
57
|
var import_nestedRoutes = require("./nestedRoutes");
|
|
59
|
-
var import_Builder = require("./Builder");
|
|
60
|
-
const loader = {
|
|
61
|
-
".js": "jsx",
|
|
62
|
-
".ts": "tsx"
|
|
63
|
-
};
|
|
64
|
-
const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
65
58
|
const createImportSpecifier = (specifiers) => {
|
|
66
59
|
let defaults = "";
|
|
67
60
|
const named = [];
|
|
@@ -109,49 +102,6 @@ ${initialize || ""}`
|
|
|
109
102
|
${initialize || ""}`
|
|
110
103
|
).join("\n");
|
|
111
104
|
};
|
|
112
|
-
const buildLoader = (entry, outfile) => __async(void 0, null, function* () {
|
|
113
|
-
yield import_Builder.loaderBuilder.build({
|
|
114
|
-
format: "esm",
|
|
115
|
-
platform: "browser",
|
|
116
|
-
target: "esnext",
|
|
117
|
-
loader,
|
|
118
|
-
watch: (0, import_commands.isDevCommand)() && {},
|
|
119
|
-
bundle: true,
|
|
120
|
-
logLevel: "error",
|
|
121
|
-
entryPoints: [entry],
|
|
122
|
-
outfile,
|
|
123
|
-
plugins: [
|
|
124
|
-
{
|
|
125
|
-
name: "make-all-packages-external",
|
|
126
|
-
setup(build) {
|
|
127
|
-
build.onResolve({ filter: EXTERNAL_REGEXP }, (args) => {
|
|
128
|
-
let external = true;
|
|
129
|
-
if (args.kind === "entry-point") {
|
|
130
|
-
external = false;
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
path: args.path,
|
|
134
|
-
external
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
|
|
143
|
-
yield import_Builder.serverLoaderBuilder.build({
|
|
144
|
-
format: "cjs",
|
|
145
|
-
platform: "node",
|
|
146
|
-
target: "esnext",
|
|
147
|
-
loader,
|
|
148
|
-
watch: (0, import_commands.isDevCommand)() && {},
|
|
149
|
-
bundle: true,
|
|
150
|
-
logLevel: "error",
|
|
151
|
-
entryPoints: [entry],
|
|
152
|
-
outfile
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
105
|
const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
|
|
156
106
|
var _a, _b, _c;
|
|
157
107
|
const {
|
|
@@ -242,16 +192,9 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
242
192
|
})
|
|
243
193
|
});
|
|
244
194
|
if (entrypoint.nestedRoutesEntry) {
|
|
245
|
-
const routesServerFile =
|
|
195
|
+
const routesServerFile = (0, import_utils2.getServerLoadersFile)(
|
|
246
196
|
internalDirectory,
|
|
247
|
-
entryName
|
|
248
|
-
"route-server-loaders.js"
|
|
249
|
-
);
|
|
250
|
-
const outputRoutesServerFile = import_path.default.join(
|
|
251
|
-
distDirectory,
|
|
252
|
-
import_utils.LOADER_ROUTES_DIR,
|
|
253
|
-
entryName,
|
|
254
|
-
"index.js"
|
|
197
|
+
entryName
|
|
255
198
|
);
|
|
256
199
|
const code3 = templates.routesForServer({
|
|
257
200
|
routes,
|
|
@@ -260,24 +203,6 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
260
203
|
});
|
|
261
204
|
yield import_utils.fs.ensureFile(routesServerFile);
|
|
262
205
|
yield import_utils.fs.writeFile(routesServerFile, code3);
|
|
263
|
-
const loaderEntryFile = import_path.default.join(
|
|
264
|
-
internalDirectory,
|
|
265
|
-
entryName,
|
|
266
|
-
import_constants.TEMP_LOADERS_DIR,
|
|
267
|
-
"entry.js"
|
|
268
|
-
);
|
|
269
|
-
const loaderIndexFile = import_path.default.join(
|
|
270
|
-
internalDirectory,
|
|
271
|
-
entryName,
|
|
272
|
-
import_constants.TEMP_LOADERS_DIR,
|
|
273
|
-
"index.js"
|
|
274
|
-
);
|
|
275
|
-
if (yield import_utils.fs.pathExists(loaderEntryFile)) {
|
|
276
|
-
yield buildLoader(loaderEntryFile, loaderIndexFile);
|
|
277
|
-
}
|
|
278
|
-
if (yield import_utils.fs.pathExists(routesServerFile)) {
|
|
279
|
-
yield buildServerLoader(routesServerFile, outputRoutesServerFile);
|
|
280
|
-
}
|
|
281
206
|
}
|
|
282
207
|
import_utils.fs.outputFileSync(
|
|
283
208
|
import_path.default.resolve(
|