@modern-js/app-tools 2.0.2 → 2.1.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 +60 -0
- package/dist/js/modern/analyze/constants.js +1 -1
- package/dist/js/modern/analyze/generateCode.js +8 -93
- package/dist/js/modern/analyze/index.js +36 -10
- package/dist/js/modern/analyze/nestedRoutes.js +2 -15
- package/dist/js/modern/analyze/templates.js +36 -68
- package/dist/js/modern/analyze/utils.js +5 -14
- package/dist/js/modern/builder/index.js +1 -2
- package/dist/js/modern/config/default.js +3 -1
- package/dist/js/modern/config/initial/inits.js +1 -9
- package/dist/js/modern/index.js +6 -7
- package/dist/js/modern/initialize/index.js +7 -7
- package/dist/js/modern/locale/en.js +2 -1
- package/dist/js/modern/locale/zh.js +2 -1
- package/dist/js/node/analyze/constants.js +1 -1
- package/dist/js/node/analyze/generateCode.js +5 -84
- package/dist/js/node/analyze/index.js +28 -8
- package/dist/js/node/analyze/nestedRoutes.js +1 -14
- package/dist/js/node/analyze/templates.js +36 -68
- package/dist/js/node/analyze/utils.js +5 -13
- package/dist/js/node/builder/index.js +1 -2
- package/dist/js/node/config/default.js +3 -1
- package/dist/js/node/config/initial/inits.js +1 -9
- package/dist/js/node/index.js +2 -3
- package/dist/js/node/initialize/index.js +7 -7
- package/dist/js/node/locale/en.js +2 -1
- package/dist/js/node/locale/zh.js +2 -1
- package/dist/js/treeshaking/analyze/constants.js +1 -1
- package/dist/js/treeshaking/analyze/generateCode.js +26 -156
- package/dist/js/treeshaking/analyze/index.js +23 -15
- package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
- package/dist/js/treeshaking/analyze/templates.js +93 -76
- package/dist/js/treeshaking/analyze/utils.js +5 -11
- package/dist/js/treeshaking/builder/index.js +1 -2
- package/dist/js/treeshaking/config/default.js +3 -1
- package/dist/js/treeshaking/config/initial/inits.js +1 -12
- package/dist/js/treeshaking/index.js +8 -9
- package/dist/js/treeshaking/initialize/index.js +19 -42
- package/dist/js/treeshaking/locale/en.js +2 -1
- package/dist/js/treeshaking/locale/zh.js +2 -1
- package/dist/types/analyze/constants.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +2 -8
- package/dist/types/analyze/utils.d.ts +2 -2
- 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/dist/types/types/config/dev.d.ts +1 -1
- package/lib/types.d.ts +6 -2
- package/package.json +22 -22
- 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,65 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2ad9642: feat: new command support --lang params
|
|
8
|
+
|
|
9
|
+
feat: new 命令支持 --lang 参数
|
|
10
|
+
|
|
11
|
+
- bf38bda: feat(app-tools): allow to use dev.port config
|
|
12
|
+
|
|
13
|
+
feat(app-tools): 支持使用 dev.port 配置
|
|
14
|
+
|
|
15
|
+
- 29fbc66: fix(app-tools): SVG default export type
|
|
16
|
+
|
|
17
|
+
fix(app-tools): 修复 SVG 默认导出的类型错误
|
|
18
|
+
|
|
19
|
+
- 3a7da8c: fix(app-tools): server.port not work in development
|
|
20
|
+
|
|
21
|
+
fix(app-tools): 修复开发环境下 server.port 不生效的问题
|
|
22
|
+
|
|
23
|
+
- 3d0fb38: fix: remove the prebundle for data loader
|
|
24
|
+
fix: 移除 data loader 的预打包
|
|
25
|
+
- 6562578: chore: optimize the capitalization of plugin names
|
|
26
|
+
|
|
27
|
+
chore: 规范引用插件时的命名格式,统一使用 camelCase 代替 PascalCase
|
|
28
|
+
|
|
29
|
+
- 0d2af52: docs: add docs for config and init
|
|
30
|
+
docs: 添加 config 和 init 在嵌套路由下的文档
|
|
31
|
+
- 84ee9e9: fix: can't exit process after build
|
|
32
|
+
fix: 在 build 后不退出程序
|
|
33
|
+
- 5b54418: fix(builder): no longer remove comments of HTML
|
|
34
|
+
|
|
35
|
+
fix(builder): 不再默认移除 HTML 中的注释
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [837620c]
|
|
38
|
+
- Updated dependencies [3d0fb38]
|
|
39
|
+
- Updated dependencies [3ad26c2]
|
|
40
|
+
- Updated dependencies [5b54418]
|
|
41
|
+
- Updated dependencies [bafa52e]
|
|
42
|
+
- Updated dependencies [ccbac43]
|
|
43
|
+
- Updated dependencies [8a9482c]
|
|
44
|
+
- Updated dependencies [679296d]
|
|
45
|
+
- @modern-js/utils@2.1.0
|
|
46
|
+
- @modern-js/plugin-data-loader@2.1.0
|
|
47
|
+
- @modern-js/server@2.1.0
|
|
48
|
+
- @modern-js/builder-shared@2.1.0
|
|
49
|
+
- @modern-js/builder-webpack-provider@2.1.0
|
|
50
|
+
- @modern-js/core@2.1.0
|
|
51
|
+
- @modern-js/builder@2.1.0
|
|
52
|
+
- @modern-js/builder-plugin-esbuild@2.1.0
|
|
53
|
+
- @modern-js/builder-plugin-node-polyfill@2.1.0
|
|
54
|
+
- @modern-js/plugin-i18n@2.1.0
|
|
55
|
+
- @modern-js/plugin-lint@2.1.0
|
|
56
|
+
- @modern-js/new-action@2.1.0
|
|
57
|
+
- @modern-js/prod-server@2.1.0
|
|
58
|
+
- @modern-js/node-bundle-require@2.1.0
|
|
59
|
+
- @modern-js/upgrade@2.1.0
|
|
60
|
+
- @modern-js/plugin@2.1.0
|
|
61
|
+
- @modern-js/types@2.1.0
|
|
62
|
+
|
|
3
63
|
## 2.0.2
|
|
4
64
|
|
|
5
65
|
### Patch Changes
|
|
@@ -19,32 +19,19 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
import path from "path";
|
|
22
|
-
import {
|
|
23
|
-
fs,
|
|
24
|
-
getEntryOptions,
|
|
25
|
-
LOADER_ROUTES_DIR,
|
|
26
|
-
logger
|
|
27
|
-
} from "@modern-js/utils";
|
|
22
|
+
import { fs, getEntryOptions, logger } from "@modern-js/utils";
|
|
28
23
|
import {
|
|
29
24
|
useResolvedConfigContext
|
|
30
25
|
} from "@modern-js/core";
|
|
31
|
-
import { isDevCommand } from "../utils/commands";
|
|
32
26
|
import * as templates from "./templates";
|
|
33
27
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
34
28
|
import {
|
|
35
29
|
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
36
30
|
ENTRY_POINT_FILE_NAME,
|
|
37
|
-
ENTRY_BOOTSTRAP_FILE_NAME
|
|
38
|
-
TEMP_LOADERS_DIR
|
|
31
|
+
ENTRY_BOOTSTRAP_FILE_NAME
|
|
39
32
|
} from "./constants";
|
|
40
|
-
import { getDefaultImports } from "./utils";
|
|
33
|
+
import { getDefaultImports, getServerLoadersFile } from "./utils";
|
|
41
34
|
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
35
|
const createImportSpecifier = (specifiers) => {
|
|
49
36
|
let defaults = "";
|
|
50
37
|
const named = [];
|
|
@@ -92,54 +79,10 @@ ${initialize || ""}`
|
|
|
92
79
|
${initialize || ""}`
|
|
93
80
|
).join("\n");
|
|
94
81
|
};
|
|
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
82
|
const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
|
|
139
83
|
var _a, _b, _c;
|
|
140
84
|
const {
|
|
141
85
|
internalDirectory,
|
|
142
|
-
distDirectory,
|
|
143
86
|
srcDirectory,
|
|
144
87
|
internalDirAlias,
|
|
145
88
|
internalSrcAlias,
|
|
@@ -220,47 +163,19 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
220
163
|
ssrMode: mode,
|
|
221
164
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
222
165
|
entryName: entrypoint.entryName,
|
|
223
|
-
internalDirectory
|
|
224
|
-
internalDirAlias
|
|
166
|
+
internalDirectory
|
|
225
167
|
})
|
|
226
168
|
});
|
|
227
|
-
if (entrypoint.nestedRoutesEntry) {
|
|
228
|
-
const routesServerFile =
|
|
169
|
+
if (entrypoint.nestedRoutesEntry && mode) {
|
|
170
|
+
const routesServerFile = getServerLoadersFile(
|
|
229
171
|
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"
|
|
172
|
+
entryName
|
|
238
173
|
);
|
|
239
174
|
const code3 = templates.routesForServer({
|
|
240
|
-
routes
|
|
241
|
-
internalDirectory,
|
|
242
|
-
entryName
|
|
175
|
+
routes
|
|
243
176
|
});
|
|
244
177
|
yield fs.ensureFile(routesServerFile);
|
|
245
178
|
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
179
|
}
|
|
265
180
|
fs.outputFileSync(
|
|
266
181
|
path.resolve(
|
|
@@ -38,7 +38,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import * as path from "path";
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
createDebugger,
|
|
43
|
+
findExists,
|
|
44
|
+
fs,
|
|
45
|
+
getEntryOptions,
|
|
46
|
+
isApiOnly
|
|
47
|
+
} from "@modern-js/utils";
|
|
42
48
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
43
49
|
import { createBuilderForModern } from "../builder";
|
|
44
50
|
import { printInstructions } from "../utils/printInstructions";
|
|
@@ -47,12 +53,11 @@ import { emitResolvedConfig } from "../utils/config";
|
|
|
47
53
|
import { getCommand } from "../utils/commands";
|
|
48
54
|
import { initialNormalizedConfig } from "../config";
|
|
49
55
|
import {
|
|
50
|
-
|
|
56
|
+
getServerLoadersFile,
|
|
51
57
|
isPageComponentFile,
|
|
52
58
|
parseModule,
|
|
53
59
|
replaceWithAlias
|
|
54
60
|
} from "./utils";
|
|
55
|
-
import { loaderBuilder, serverLoaderBuilder } from "./Builder";
|
|
56
61
|
import {
|
|
57
62
|
APP_CONFIG_NAME,
|
|
58
63
|
APP_INIT_EXPORTED,
|
|
@@ -207,6 +212,33 @@ var analyze_default = () => ({
|
|
|
207
212
|
watchFiles() {
|
|
208
213
|
return pagesDir;
|
|
209
214
|
},
|
|
215
|
+
config() {
|
|
216
|
+
return {
|
|
217
|
+
tools: {
|
|
218
|
+
webpackChain: (chain, { name }) => {
|
|
219
|
+
const appContext = api.useAppContext();
|
|
220
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
221
|
+
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
222
|
+
entrypoints.forEach((entrypoint) => {
|
|
223
|
+
const { entryName } = entrypoint;
|
|
224
|
+
const ssr = getEntryOptions(
|
|
225
|
+
entryName,
|
|
226
|
+
resolvedConfig.server.ssr,
|
|
227
|
+
resolvedConfig.server.ssrByEntries,
|
|
228
|
+
packageName
|
|
229
|
+
);
|
|
230
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
231
|
+
const serverLoadersFile = getServerLoadersFile(
|
|
232
|
+
internalDirectory,
|
|
233
|
+
entryName
|
|
234
|
+
);
|
|
235
|
+
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
},
|
|
210
242
|
resolvedConfig({ resolved }) {
|
|
211
243
|
const appContext = api.useAppContext();
|
|
212
244
|
const config = initialNormalizedConfig(resolved, appContext);
|
|
@@ -266,12 +298,6 @@ var analyze_default = () => ({
|
|
|
266
298
|
};
|
|
267
299
|
});
|
|
268
300
|
},
|
|
269
|
-
beforeRestart() {
|
|
270
|
-
return __async(this, null, function* () {
|
|
271
|
-
serverLoaderBuilder.stop();
|
|
272
|
-
loaderBuilder.stop();
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
301
|
fileChange(e) {
|
|
276
302
|
return __async(this, null, function* () {
|
|
277
303
|
const appContext = api.useAppContext();
|
|
@@ -280,7 +306,7 @@ var analyze_default = () => ({
|
|
|
280
306
|
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
281
307
|
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
282
308
|
const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
|
283
|
-
if (isRouteComponent && (eventType === "add" || eventType === "unlink")
|
|
309
|
+
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
284
310
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
285
311
|
const { generateCode } = yield import("./generateCode");
|
|
286
312
|
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);
|
|
@@ -72,7 +72,7 @@ const renderFunction = ({
|
|
|
72
72
|
return `
|
|
73
73
|
const finalAppConfig = {
|
|
74
74
|
...App.config,
|
|
75
|
-
...typeof ${APP_CONFIG_NAME} === '
|
|
75
|
+
...typeof ${APP_CONFIG_NAME} === 'function' ? ${APP_CONFIG_NAME}() : {},
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
AppWrapper = createApp({
|
|
@@ -127,17 +127,9 @@ const html = (partials) => `
|
|
|
127
127
|
</html>
|
|
128
128
|
`;
|
|
129
129
|
const routesForServer = ({
|
|
130
|
-
routes
|
|
131
|
-
internalDirectory,
|
|
132
|
-
entryName
|
|
130
|
+
routes
|
|
133
131
|
}) => {
|
|
134
132
|
const loaders = [];
|
|
135
|
-
const loaderIndexFile = path.join(
|
|
136
|
-
internalDirectory,
|
|
137
|
-
entryName,
|
|
138
|
-
TEMP_LOADERS_DIR,
|
|
139
|
-
"index.js"
|
|
140
|
-
);
|
|
141
133
|
const traverseRouteTree = (route) => {
|
|
142
134
|
var _a;
|
|
143
135
|
let children;
|
|
@@ -175,10 +167,9 @@ const routesForServer = ({
|
|
|
175
167
|
];`;
|
|
176
168
|
let importLoadersCode = "";
|
|
177
169
|
if (loaders.length > 0) {
|
|
178
|
-
importLoadersCode =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
)} } from "${slash(loaderIndexFile)}"`;
|
|
170
|
+
importLoadersCode = loaders.map((loader, index2) => {
|
|
171
|
+
return `import loader_${index2} from "${slash(loader)}"`;
|
|
172
|
+
}).join("\n");
|
|
182
173
|
}
|
|
183
174
|
return `
|
|
184
175
|
${importLoadersCode}
|
|
@@ -190,19 +181,12 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
190
181
|
ssrMode,
|
|
191
182
|
nestedRoutesEntry,
|
|
192
183
|
entryName,
|
|
193
|
-
internalDirectory
|
|
194
|
-
internalDirAlias
|
|
184
|
+
internalDirectory
|
|
195
185
|
}) {
|
|
196
186
|
const loadings = [];
|
|
197
187
|
const errors = [];
|
|
198
188
|
const loaders = [];
|
|
199
189
|
const loadersMap = {};
|
|
200
|
-
const loadersIndexFile = path.join(
|
|
201
|
-
internalDirAlias,
|
|
202
|
-
entryName,
|
|
203
|
-
TEMP_LOADERS_DIR,
|
|
204
|
-
"index.js"
|
|
205
|
-
);
|
|
206
190
|
const loadersMapFile = path.join(
|
|
207
191
|
internalDirectory,
|
|
208
192
|
entryName,
|
|
@@ -214,13 +198,20 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
214
198
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
215
199
|
`;
|
|
216
200
|
let rootLayoutCode = ``;
|
|
217
|
-
let dataLoaderPath = "";
|
|
218
201
|
let componentLoaderPath = "";
|
|
219
|
-
|
|
220
|
-
|
|
202
|
+
const getDataLoaderPath = (loaderId) => {
|
|
203
|
+
if (!ssrMode) {
|
|
204
|
+
return "";
|
|
205
|
+
}
|
|
206
|
+
let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
221
207
|
if (nestedRoutesEntry) {
|
|
222
|
-
dataLoaderPath = `${dataLoaderPath}?
|
|
208
|
+
dataLoaderPath = `${slash(dataLoaderPath)}?mapFile=${slash(
|
|
209
|
+
loadersMapFile
|
|
210
|
+
)}&loaderId=${loaderId}!`;
|
|
223
211
|
}
|
|
212
|
+
return dataLoaderPath;
|
|
213
|
+
};
|
|
214
|
+
if (ssrMode) {
|
|
224
215
|
componentLoaderPath = `${path.join(
|
|
225
216
|
__dirname,
|
|
226
217
|
"../builder/loaders/routerLoader"
|
|
@@ -250,7 +241,11 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
250
241
|
loaders.push(route.loader);
|
|
251
242
|
const loaderId = loaders.length - 1;
|
|
252
243
|
loader = `loader_${loaderId}`;
|
|
253
|
-
loadersMap[loader] =
|
|
244
|
+
loadersMap[loader] = {
|
|
245
|
+
routeId: route.id,
|
|
246
|
+
filePath: route.loader,
|
|
247
|
+
inline: false
|
|
248
|
+
};
|
|
254
249
|
}
|
|
255
250
|
if (route._component) {
|
|
256
251
|
if (route.isRoot) {
|
|
@@ -306,48 +301,21 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
306
301
|
`;
|
|
307
302
|
}).join("");
|
|
308
303
|
let importLoadersCode = "";
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
TEMP_LOADERS_DIR,
|
|
322
|
-
"entry.js"
|
|
323
|
-
);
|
|
324
|
-
yield fs.ensureFile(loaderEntryFile);
|
|
325
|
-
yield fs.writeFile(loaderEntryFile, loaderEntryCode);
|
|
326
|
-
yield fs.writeJSON(loadersMapFile, loadersMap);
|
|
327
|
-
yield Promise.all(
|
|
328
|
-
loaders.map((loader, index2) => __async(void 0, null, function* () {
|
|
329
|
-
const name = `loader_${index2}`;
|
|
330
|
-
const filename = path.join(
|
|
331
|
-
internalDirectory,
|
|
332
|
-
entryName,
|
|
333
|
-
TEMP_LOADERS_DIR,
|
|
334
|
-
`${name}.js`
|
|
335
|
-
);
|
|
336
|
-
let code = "";
|
|
337
|
-
if (loader.includes(".loader.")) {
|
|
338
|
-
code = `
|
|
339
|
-
export { default as ${name} } from '${slash(loader)}'
|
|
340
|
-
`;
|
|
341
|
-
} else {
|
|
342
|
-
code = `
|
|
343
|
-
export { loader as ${name} } from '${slash(loader)}'
|
|
344
|
-
`;
|
|
345
|
-
}
|
|
346
|
-
yield fs.ensureFile(filename);
|
|
347
|
-
yield fs.writeFile(filename, code);
|
|
348
|
-
}))
|
|
349
|
-
);
|
|
304
|
+
for (const [key, loaderInfo] of Object.entries(loadersMap)) {
|
|
305
|
+
if (loaderInfo.inline) {
|
|
306
|
+
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
307
|
+
key
|
|
308
|
+
)}${slash(loaderInfo.filePath)}";
|
|
309
|
+
`;
|
|
310
|
+
} else {
|
|
311
|
+
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
312
|
+
key
|
|
313
|
+
)}${slash(loaderInfo.filePath)}";
|
|
314
|
+
`;
|
|
315
|
+
}
|
|
350
316
|
}
|
|
317
|
+
yield fs.ensureFile(loadersMapFile);
|
|
318
|
+
yield fs.writeJSON(loadersMapFile, loadersMap);
|
|
351
319
|
return `
|
|
352
320
|
${importLazyCode}
|
|
353
321
|
${rootLayoutCode}
|
|
@@ -26,8 +26,7 @@ import { parse } from "es-module-lexer";
|
|
|
26
26
|
import {
|
|
27
27
|
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
28
28
|
JS_EXTENSIONS,
|
|
29
|
-
LOADER_EXPORT_NAME
|
|
30
|
-
NESTED_ROUTE
|
|
29
|
+
LOADER_EXPORT_NAME
|
|
31
30
|
} from "./constants";
|
|
32
31
|
const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
|
|
33
32
|
const filePath = path.join(dir, filename);
|
|
@@ -105,17 +104,6 @@ const isPageComponentFile = (filePath) => {
|
|
|
105
104
|
}
|
|
106
105
|
return false;
|
|
107
106
|
};
|
|
108
|
-
const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
|
|
109
|
-
const reg = new RegExp(
|
|
110
|
-
`(${NESTED_ROUTE.LAYOUT_FILE}|${NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
|
|
111
|
-
);
|
|
112
|
-
return nestedRouteEntries.some((nestedRoutesEntry) => {
|
|
113
|
-
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
107
|
const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
120
108
|
const parseModule = (_0) => __async(void 0, [_0], function* ({
|
|
121
109
|
source,
|
|
@@ -139,10 +127,13 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
|
|
|
139
127
|
});
|
|
140
128
|
return moduleExports.some((e) => e.n === LOADER_EXPORT_NAME);
|
|
141
129
|
});
|
|
130
|
+
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
131
|
+
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
132
|
+
};
|
|
142
133
|
export {
|
|
143
134
|
getDefaultImports,
|
|
135
|
+
getServerLoadersFile,
|
|
144
136
|
hasLoader,
|
|
145
|
-
isNestedRouteComponent,
|
|
146
137
|
isPageComponentFile,
|
|
147
138
|
parseModule,
|
|
148
139
|
replaceWithAlias,
|
|
@@ -87,7 +87,6 @@ function createBuilderForModern(_0) {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
90
|
-
var _a;
|
|
91
90
|
const output = createOutputConfig(normalizedConfig, appContext);
|
|
92
91
|
const htmlConfig = __spreadValues({}, normalizedConfig.html);
|
|
93
92
|
if (!htmlConfig.template) {
|
|
@@ -96,7 +95,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
96
95
|
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
97
96
|
output,
|
|
98
97
|
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
99
|
-
port:
|
|
98
|
+
port: appContext.port
|
|
100
99
|
}),
|
|
101
100
|
html: htmlConfig
|
|
102
101
|
});
|
|
@@ -20,7 +20,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
21
21
|
function createDefaultConfig(appContext) {
|
|
22
22
|
const defaultBuilderConfig = createDefaultBuilderConfig();
|
|
23
|
-
const dev = __spreadValues({}, defaultBuilderConfig.dev)
|
|
23
|
+
const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
|
|
24
|
+
port: void 0
|
|
25
|
+
});
|
|
24
26
|
const tools = __spreadValues({}, defaultBuilderConfig.tools);
|
|
25
27
|
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
26
28
|
disableNodePolyfill: true
|
|
@@ -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>`,
|