@modern-js/app-tools 2.7.1-alpha.0 → 2.8.1-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 +53 -2
- package/dist/cjs/analyze/generateCode.js +13 -0
- package/dist/cjs/analyze/index.js +0 -37
- package/dist/cjs/analyze/templates.js +56 -15
- package/dist/cjs/analyze/utils.js +14 -1
- package/dist/cjs/builder/index.js +1 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +25 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm/analyze/generateCode.js +30 -16
- package/dist/esm/analyze/index.js +2 -26
- package/dist/esm/analyze/templates.js +44 -17
- package/dist/esm/analyze/utils.js +9 -2
- package/dist/esm/builder/index.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +241 -22
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm-node/analyze/generateCode.js +18 -1
- package/dist/esm-node/analyze/index.js +2 -46
- package/dist/esm-node/analyze/templates.js +55 -15
- package/dist/esm-node/analyze/utils.js +13 -1
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +25 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/types/analyze/templates.d.ts +3 -2
- package/dist/types/analyze/utils.d.ts +2 -1
- package/package.json +26 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ab1e8065cb: feat: support router-plugin in Rspack bundler.
|
|
8
|
+
feat: 在 Rspack bundler 里支持 router-plugin
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- a12b5b4ec8: fix: the adapterSSR builder plugin modifyChain Hooks is not async function
|
|
13
|
+
fix: adapterSSR builder 插件的 adapterSSR Hooks 不是异步函数
|
|
14
|
+
- 1104a9f18b: feat: support start web service only
|
|
15
|
+
feat: 支持只启动 web 服务
|
|
16
|
+
- 1f6ca2c7fb: fix: nested routes in ssg
|
|
17
|
+
fix: 修复嵌套路由在 SSG 中的问题
|
|
18
|
+
- 2b6b1a014c: refactor: app-tools builder
|
|
19
|
+
refactor: 重构 app-tools builder
|
|
20
|
+
- 250f794c40: fix: move the analyze webpackChain config to app-tools builder shared
|
|
21
|
+
fix: 将 anylyze 的 `webpackChain` 配置项移植进 app-tools builder shared
|
|
22
|
+
- Updated dependencies [ea7bb41e30]
|
|
23
|
+
- Updated dependencies [65c56f43b9]
|
|
24
|
+
- Updated dependencies [0cf8540ffe]
|
|
25
|
+
- Updated dependencies [bd369a89a4]
|
|
26
|
+
- Updated dependencies [bc943c9b04]
|
|
27
|
+
- Updated dependencies [40f5039b17]
|
|
28
|
+
- Updated dependencies [1104a9f18b]
|
|
29
|
+
- Updated dependencies [70d82e1408]
|
|
30
|
+
- Updated dependencies [2c1151271d]
|
|
31
|
+
- Updated dependencies [481461a61d]
|
|
32
|
+
- Updated dependencies [1242f5d8d6]
|
|
33
|
+
- Updated dependencies [1f6ca2c7fb]
|
|
34
|
+
- Updated dependencies [457ee832b9]
|
|
35
|
+
- @modern-js/server@2.8.0
|
|
36
|
+
- @modern-js/builder-webpack-provider@2.8.0
|
|
37
|
+
- @modern-js/plugin-data-loader@2.8.0
|
|
38
|
+
- @modern-js/builder@2.8.0
|
|
39
|
+
- @modern-js/builder-shared@2.8.0
|
|
40
|
+
- @modern-js/builder-rspack-provider@2.8.0
|
|
41
|
+
- @modern-js/prod-server@2.8.0
|
|
42
|
+
- @modern-js/utils@2.8.0
|
|
43
|
+
- @modern-js/types@2.8.0
|
|
44
|
+
- @modern-js/builder-plugin-esbuild@2.8.0
|
|
45
|
+
- @modern-js/builder-plugin-node-polyfill@2.8.0
|
|
46
|
+
- @modern-js/core@2.8.0
|
|
47
|
+
- @modern-js/plugin-i18n@2.8.0
|
|
48
|
+
- @modern-js/plugin-lint@2.8.0
|
|
49
|
+
- @modern-js/new-action@2.8.0
|
|
50
|
+
- @modern-js/node-bundle-require@2.8.0
|
|
51
|
+
- @modern-js/upgrade@2.8.0
|
|
52
|
+
- @modern-js/plugin@2.8.0
|
|
53
|
+
|
|
3
54
|
## 2.7.0
|
|
4
55
|
|
|
5
56
|
### Minor Changes
|
|
@@ -167,8 +218,8 @@
|
|
|
167
218
|
|
|
168
219
|
- e84d16b: feat: support catch-all routing
|
|
169
220
|
feat: 支持通配路由
|
|
170
|
-
- a914be8: feat: modern-js support
|
|
171
|
-
feat: modern-js 支持
|
|
221
|
+
- a914be8: feat: modern-js support Rspack bundler
|
|
222
|
+
feat: modern-js 支持 Rspack 构建工具
|
|
172
223
|
|
|
173
224
|
### Patch Changes
|
|
174
225
|
|
|
@@ -177,6 +177,19 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
177
177
|
await import_utils.fs.ensureFile(routesServerFile);
|
|
178
178
|
await import_utils.fs.writeFile(routesServerFile, code3);
|
|
179
179
|
}
|
|
180
|
+
const serverLoaderCombined = templates.ssrLoaderCombinedModule(
|
|
181
|
+
entrypoints,
|
|
182
|
+
entrypoint,
|
|
183
|
+
config2,
|
|
184
|
+
appContext
|
|
185
|
+
);
|
|
186
|
+
if (serverLoaderCombined) {
|
|
187
|
+
const serverLoaderFile = (0, import_utils2.getServerCombinedModueFile)(
|
|
188
|
+
internalDirectory,
|
|
189
|
+
entryName
|
|
190
|
+
);
|
|
191
|
+
await import_utils.fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
192
|
+
}
|
|
180
193
|
import_utils.fs.outputFileSync(
|
|
181
194
|
import_path.default.resolve(
|
|
182
195
|
internalDirectory,
|
|
@@ -33,7 +33,6 @@ module.exports = __toCommonJS(analyze_exports);
|
|
|
33
33
|
var path = __toESM(require("path"));
|
|
34
34
|
var import_utils = require("@modern-js/utils");
|
|
35
35
|
var import_lodash = require("@modern-js/utils/lodash");
|
|
36
|
-
var import_builder_shared = require("@modern-js/builder-shared");
|
|
37
36
|
var import_printInstructions = require("../utils/printInstructions");
|
|
38
37
|
var import_routes = require("../utils/routes");
|
|
39
38
|
var import_config = require("../utils/config");
|
|
@@ -190,42 +189,6 @@ var analyze_default = ({
|
|
|
190
189
|
watchFiles() {
|
|
191
190
|
return pagesDir;
|
|
192
191
|
},
|
|
193
|
-
config() {
|
|
194
|
-
return {
|
|
195
|
-
tools: {
|
|
196
|
-
webpackChain: (chain, { name }) => {
|
|
197
|
-
const appContext = api.useAppContext();
|
|
198
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
|
199
|
-
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
200
|
-
entrypoints.forEach((entrypoint) => {
|
|
201
|
-
const { entryName } = entrypoint;
|
|
202
|
-
const ssr = (0, import_utils.getEntryOptions)(
|
|
203
|
-
entryName,
|
|
204
|
-
resolvedConfig.server.ssr,
|
|
205
|
-
resolvedConfig.server.ssrByEntries,
|
|
206
|
-
packageName
|
|
207
|
-
);
|
|
208
|
-
const useSSG = (0, import_utils.isSSGEntry)(
|
|
209
|
-
resolvedConfig,
|
|
210
|
-
entryName,
|
|
211
|
-
entrypoints
|
|
212
|
-
);
|
|
213
|
-
if (entrypoint.nestedRoutesEntry && (ssr || useSSG) && name === "server") {
|
|
214
|
-
const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
215
|
-
const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
|
|
216
|
-
internalDirectory,
|
|
217
|
-
entryName
|
|
218
|
-
);
|
|
219
|
-
const combinedModule = (0, import_builder_shared.createVirtualModule)(
|
|
220
|
-
`export * from "${serverLoaderRuntime}"; export * from "${serverLoadersFile}"`
|
|
221
|
-
);
|
|
222
|
-
chain.entry(`${entryName}-server-loaders`).add(combinedModule);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
},
|
|
229
192
|
resolvedConfig({ resolved }) {
|
|
230
193
|
const appContext = api.useAppContext();
|
|
231
194
|
const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext, bundler);
|
|
@@ -31,12 +31,14 @@ __export(templates_exports, {
|
|
|
31
31
|
html: () => html,
|
|
32
32
|
index: () => index,
|
|
33
33
|
renderFunction: () => renderFunction,
|
|
34
|
-
routesForServer: () => routesForServer
|
|
34
|
+
routesForServer: () => routesForServer,
|
|
35
|
+
ssrLoaderCombinedModule: () => ssrLoaderCombinedModule
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(templates_exports);
|
|
37
38
|
var import_path = __toESM(require("path"));
|
|
38
39
|
var import_utils = require("@modern-js/utils");
|
|
39
40
|
var import_constants = require("./constants");
|
|
41
|
+
var import_utils2 = require("./utils");
|
|
40
42
|
const index = ({
|
|
41
43
|
mountId,
|
|
42
44
|
imports,
|
|
@@ -183,11 +185,11 @@ const fileSystemRoutes = async ({
|
|
|
183
185
|
internalDirectory,
|
|
184
186
|
splitRoutesChunks = true
|
|
185
187
|
}) => {
|
|
188
|
+
const components = [];
|
|
186
189
|
const loadings = [];
|
|
187
190
|
const errors = [];
|
|
188
191
|
const loaders = [];
|
|
189
192
|
const loadersMap = {};
|
|
190
|
-
const webpackMode = splitRoutesChunks ? "lazy" : "eager";
|
|
191
193
|
const loadersMapFile = import_path.default.join(
|
|
192
194
|
internalDirectory,
|
|
193
195
|
entryName,
|
|
@@ -242,20 +244,30 @@ const fileSystemRoutes = async ({
|
|
|
242
244
|
};
|
|
243
245
|
}
|
|
244
246
|
if (route._component) {
|
|
245
|
-
if (
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
if (splitRoutesChunks) {
|
|
248
|
+
if (route.isRoot) {
|
|
249
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
250
|
+
component = `RootLayout`;
|
|
251
|
+
} else if (ssrMode === "string") {
|
|
252
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
253
|
+
component = `loadable(${lazyImport})`;
|
|
254
|
+
} else {
|
|
255
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
256
|
+
component = `lazy(${lazyImport})`;
|
|
257
|
+
}
|
|
251
258
|
} else {
|
|
252
|
-
|
|
253
|
-
component = `
|
|
259
|
+
components.push(route._component);
|
|
260
|
+
component = `component_${components.length - 1}`;
|
|
254
261
|
}
|
|
255
262
|
}
|
|
256
263
|
} else if (route._component) {
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
if (splitRoutesChunks) {
|
|
265
|
+
lazyImport = `() => import('${route._component}')`;
|
|
266
|
+
component = `loadable(${lazyImport})`;
|
|
267
|
+
} else {
|
|
268
|
+
components.push(route._component);
|
|
269
|
+
component = `component_${components.length - 1}`;
|
|
270
|
+
}
|
|
259
271
|
}
|
|
260
272
|
const finalRoute = {
|
|
261
273
|
...route,
|
|
@@ -276,20 +288,24 @@ const fileSystemRoutes = async ({
|
|
|
276
288
|
for (const route of routes) {
|
|
277
289
|
if ("type" in route) {
|
|
278
290
|
const newRoute = traverseRouteTree(route);
|
|
279
|
-
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, '"')},`;
|
|
291
|
+
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/("component":\s)"([^"]+)"/g, "$1$2").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
280
292
|
} else {
|
|
281
293
|
const component = `loadable(() => import('${route._component}'))`;
|
|
282
294
|
const finalRoute = {
|
|
283
295
|
...route,
|
|
284
296
|
component
|
|
285
297
|
};
|
|
286
|
-
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$
|
|
298
|
+
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2")},`;
|
|
287
299
|
}
|
|
288
300
|
}
|
|
289
301
|
routeComponentsCode += `
|
|
290
302
|
];`;
|
|
291
303
|
const importLoadingCode = loadings.map((loading, index2) => {
|
|
292
304
|
return `import loading_${index2} from '${loading}';
|
|
305
|
+
`;
|
|
306
|
+
}).join("");
|
|
307
|
+
const importComponentsCode = components.map((component, index2) => {
|
|
308
|
+
return `import component_${index2} from '${component}';
|
|
293
309
|
`;
|
|
294
310
|
}).join("");
|
|
295
311
|
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
@@ -314,6 +330,7 @@ const fileSystemRoutes = async ({
|
|
|
314
330
|
await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
|
315
331
|
return `
|
|
316
332
|
${importLazyCode}
|
|
333
|
+
${importComponentsCode}
|
|
317
334
|
${rootLayoutCode}
|
|
318
335
|
${importLoadingCode}
|
|
319
336
|
${importErrorComponentsCode}
|
|
@@ -321,11 +338,35 @@ const fileSystemRoutes = async ({
|
|
|
321
338
|
${routeComponentsCode}
|
|
322
339
|
`;
|
|
323
340
|
};
|
|
341
|
+
function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
342
|
+
const { entryName } = entrypoint;
|
|
343
|
+
const { packageName, internalDirectory } = appContext;
|
|
344
|
+
const ssr = (0, import_utils.getEntryOptions)(
|
|
345
|
+
entryName,
|
|
346
|
+
config.server.ssr,
|
|
347
|
+
config.server.ssrByEntries,
|
|
348
|
+
packageName
|
|
349
|
+
);
|
|
350
|
+
const ssg = (0, import_utils.isSSGEntry)(config, entryName, entrypoints);
|
|
351
|
+
if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
|
|
352
|
+
const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
353
|
+
const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
|
|
354
|
+
internalDirectory,
|
|
355
|
+
entryName
|
|
356
|
+
);
|
|
357
|
+
const combinedModule = `export * from "${(0, import_utils.slash)(
|
|
358
|
+
serverLoaderRuntime
|
|
359
|
+
)}"; export * from "${(0, import_utils.slash)(serverLoadersFile)}"`;
|
|
360
|
+
return combinedModule;
|
|
361
|
+
}
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
324
364
|
// Annotate the CommonJS export names for ESM import in node:
|
|
325
365
|
0 && (module.exports = {
|
|
326
366
|
fileSystemRoutes,
|
|
327
367
|
html,
|
|
328
368
|
index,
|
|
329
369
|
renderFunction,
|
|
330
|
-
routesForServer
|
|
370
|
+
routesForServer,
|
|
371
|
+
ssrLoaderCombinedModule
|
|
331
372
|
});
|
|
@@ -28,6 +28,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
28
28
|
var utils_exports = {};
|
|
29
29
|
__export(utils_exports, {
|
|
30
30
|
getDefaultImports: () => getDefaultImports,
|
|
31
|
+
getServerCombinedModueFile: () => getServerCombinedModueFile,
|
|
31
32
|
getServerLoadersFile: () => getServerLoadersFile,
|
|
32
33
|
hasLoader: () => hasLoader,
|
|
33
34
|
isPageComponentFile: () => isPageComponentFile,
|
|
@@ -118,7 +119,15 @@ const isPageComponentFile = (filePath) => {
|
|
|
118
119
|
}
|
|
119
120
|
return false;
|
|
120
121
|
};
|
|
121
|
-
const replaceWithAlias = (base, filePath, alias) =>
|
|
122
|
+
const replaceWithAlias = (base, filePath, alias) => {
|
|
123
|
+
if (filePath.includes(base)) {
|
|
124
|
+
return (0, import_utils.normalizeToPosixPath)(
|
|
125
|
+
import_path.default.join(alias, import_path.default.relative(base, filePath))
|
|
126
|
+
);
|
|
127
|
+
} else {
|
|
128
|
+
return filePath;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
122
131
|
const parseModule = async ({
|
|
123
132
|
source,
|
|
124
133
|
filename
|
|
@@ -144,9 +153,13 @@ const hasLoader = async (filename) => {
|
|
|
144
153
|
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
145
154
|
return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
146
155
|
};
|
|
156
|
+
const getServerCombinedModueFile = (internalDirectory, entryName) => {
|
|
157
|
+
return import_path.default.join(internalDirectory, entryName, "server-loader-combined.js");
|
|
158
|
+
};
|
|
147
159
|
// Annotate the CommonJS export names for ESM import in node:
|
|
148
160
|
0 && (module.exports = {
|
|
149
161
|
getDefaultImports,
|
|
162
|
+
getServerCombinedModueFile,
|
|
150
163
|
getServerLoadersFile,
|
|
151
164
|
hasLoader,
|
|
152
165
|
isPageComponentFile,
|
|
@@ -37,7 +37,7 @@ async function createBuilderGenerator(bundler) {
|
|
|
37
37
|
return createRspackBuilderForModern;
|
|
38
38
|
} catch (_) {
|
|
39
39
|
throw new Error(
|
|
40
|
-
"Failed to use
|
|
40
|
+
"Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -21,7 +21,9 @@ __export(adapterSSR_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(adapterSSR_exports);
|
|
23
23
|
var import_builder_shared = require("@modern-js/builder-shared");
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
24
25
|
var import_bundlerPlugins = require("../bundlerPlugins");
|
|
26
|
+
var import_utils2 = require("../../../analyze/utils");
|
|
25
27
|
var import_adapterHtml = require("./adapterHtml");
|
|
26
28
|
const builderPluginAdapterSSR = (options) => ({
|
|
27
29
|
name: "builder-plugin-adapter-modern-ssr",
|
|
@@ -38,9 +40,10 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
38
40
|
return config;
|
|
39
41
|
});
|
|
40
42
|
api.modifyBundlerChain(
|
|
41
|
-
(chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin }) => {
|
|
43
|
+
async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
|
42
44
|
const builderConfig = api.getNormalizedConfig();
|
|
43
45
|
applyRouterPlugin(chain, options);
|
|
46
|
+
await applySSRLoaderEntry(chain, options, isServer);
|
|
44
47
|
if (["node", "service-worker"].includes(target)) {
|
|
45
48
|
applyFilterEntriesBySSRConfig({
|
|
46
49
|
isProd,
|
|
@@ -134,6 +137,27 @@ function applyFilterEntriesBySSRConfig({
|
|
|
134
137
|
}
|
|
135
138
|
});
|
|
136
139
|
}
|
|
140
|
+
async function applySSRLoaderEntry(chain, optinos, isServer) {
|
|
141
|
+
const { appContext } = optinos;
|
|
142
|
+
const { internalDirectory } = appContext;
|
|
143
|
+
const { entrypoints } = appContext;
|
|
144
|
+
await Promise.all(
|
|
145
|
+
entrypoints.map(async (entrypoint) => {
|
|
146
|
+
const { entryName } = entrypoint;
|
|
147
|
+
const serverLoadersFile = (0, import_utils2.getServerCombinedModueFile)(
|
|
148
|
+
internalDirectory,
|
|
149
|
+
entryName
|
|
150
|
+
);
|
|
151
|
+
if (isServer) {
|
|
152
|
+
try {
|
|
153
|
+
await import_utils.fs.access(serverLoadersFile, import_utils.fs.constants.F_OK);
|
|
154
|
+
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
}
|
|
137
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
138
162
|
0 && (module.exports = {
|
|
139
163
|
builderPluginAdapterSSR
|
|
@@ -107,6 +107,9 @@ class RouterPlugin {
|
|
|
107
107
|
);
|
|
108
108
|
for (const file of entryChunkFiles) {
|
|
109
109
|
const asset = compilation.assets[file];
|
|
110
|
+
if (!asset) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
110
113
|
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
111
114
|
newAssetsMap.set(import_path.default.join(outputPath, file), newContent);
|
|
112
115
|
compilation.updateAsset(
|
|
@@ -152,7 +152,7 @@ import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } f
|
|
|
152
152
|
import * as templates from "./templates";
|
|
153
153
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
154
154
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
155
|
-
import { getDefaultImports, getServerLoadersFile } from "./utils";
|
|
155
|
+
import { getDefaultImports, getServerLoadersFile, getServerCombinedModueFile } from "./utils";
|
|
156
156
|
import { walk } from "./nestedRoutes";
|
|
157
157
|
var createImportSpecifier = function(specifiers) {
|
|
158
158
|
var defaults = "";
|
|
@@ -245,18 +245,18 @@ var generateCode = function() {
|
|
|
245
245
|
}
|
|
246
246
|
function _generateEntryCode() {
|
|
247
247
|
_generateEntryCode = _asyncToGenerator(function(entrypoint) {
|
|
248
|
-
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config2_output, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
|
|
248
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config2_output, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, serverLoaderCombined, serverLoaderFile, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
|
|
249
249
|
return __generator(this, function(_state) {
|
|
250
250
|
switch(_state.label){
|
|
251
251
|
case 0:
|
|
252
252
|
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
253
253
|
if (!isAutoMount) return [
|
|
254
254
|
3,
|
|
255
|
-
|
|
255
|
+
18
|
|
256
256
|
];
|
|
257
257
|
if (!fileSystemRoutes) return [
|
|
258
258
|
3,
|
|
259
|
-
|
|
259
|
+
11
|
|
260
260
|
];
|
|
261
261
|
initialRoutes = [];
|
|
262
262
|
nestedRoute = null;
|
|
@@ -357,9 +357,23 @@ var generateCode = function() {
|
|
|
357
357
|
_state.sent();
|
|
358
358
|
_state.label = 8;
|
|
359
359
|
case 8:
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
361
|
+
if (!serverLoaderCombined) return [
|
|
362
|
+
3,
|
|
363
|
+
10
|
|
364
|
+
];
|
|
365
|
+
serverLoaderFile = getServerCombinedModueFile(internalDirectory, entryName);
|
|
366
|
+
return [
|
|
367
|
+
4,
|
|
368
|
+
fs.outputFile(serverLoaderFile, serverLoaderCombined)
|
|
369
|
+
];
|
|
362
370
|
case 9:
|
|
371
|
+
_state.sent();
|
|
372
|
+
_state.label = 10;
|
|
373
|
+
case 10:
|
|
374
|
+
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
|
|
375
|
+
_state.label = 11;
|
|
376
|
+
case 11:
|
|
363
377
|
return [
|
|
364
378
|
4,
|
|
365
379
|
hookRunners.modifyEntryImports({
|
|
@@ -373,7 +387,7 @@ var generateCode = function() {
|
|
|
373
387
|
})
|
|
374
388
|
})
|
|
375
389
|
];
|
|
376
|
-
case
|
|
390
|
+
case 12:
|
|
377
391
|
_ref1 = _state.sent(), importStatements = _ref1.imports;
|
|
378
392
|
return [
|
|
379
393
|
4,
|
|
@@ -382,7 +396,7 @@ var generateCode = function() {
|
|
|
382
396
|
plugins: []
|
|
383
397
|
})
|
|
384
398
|
];
|
|
385
|
-
case
|
|
399
|
+
case 13:
|
|
386
400
|
plugins = _state.sent().plugins;
|
|
387
401
|
return [
|
|
388
402
|
4,
|
|
@@ -395,7 +409,7 @@ var generateCode = function() {
|
|
|
395
409
|
})
|
|
396
410
|
})
|
|
397
411
|
];
|
|
398
|
-
case
|
|
412
|
+
case 14:
|
|
399
413
|
_ref2 = _state.sent(), renderFunction = _ref2.code;
|
|
400
414
|
return [
|
|
401
415
|
4,
|
|
@@ -404,7 +418,7 @@ var generateCode = function() {
|
|
|
404
418
|
exportStatement: "export default AppWrapper;"
|
|
405
419
|
})
|
|
406
420
|
];
|
|
407
|
-
case
|
|
421
|
+
case 15:
|
|
408
422
|
exportStatement = _state.sent().exportStatement;
|
|
409
423
|
code = templates.index({
|
|
410
424
|
mountId: mountId,
|
|
@@ -416,7 +430,7 @@ var generateCode = function() {
|
|
|
416
430
|
entrypoint.entry = entryFile;
|
|
417
431
|
if (!config.source.enableAsyncEntry) return [
|
|
418
432
|
3,
|
|
419
|
-
|
|
433
|
+
17
|
|
420
434
|
];
|
|
421
435
|
return [
|
|
422
436
|
4,
|
|
@@ -425,19 +439,19 @@ var generateCode = function() {
|
|
|
425
439
|
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
426
440
|
})
|
|
427
441
|
];
|
|
428
|
-
case
|
|
442
|
+
case 16:
|
|
429
443
|
_ref3 = _state.sent(), asyncEntryCode = _ref3.code;
|
|
430
444
|
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
431
445
|
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
432
446
|
fs.outputFileSync(bootstrapFile, code, "utf8");
|
|
433
447
|
return [
|
|
434
448
|
3,
|
|
435
|
-
|
|
449
|
+
18
|
|
436
450
|
];
|
|
437
|
-
case
|
|
451
|
+
case 17:
|
|
438
452
|
fs.outputFileSync(entryFile, code, "utf8");
|
|
439
|
-
_state.label =
|
|
440
|
-
case
|
|
453
|
+
_state.label = 18;
|
|
454
|
+
case 18:
|
|
441
455
|
return [
|
|
442
456
|
2
|
|
443
457
|
];
|
|
@@ -221,16 +221,15 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import * as path from "path";
|
|
224
|
-
import { createDebugger, findExists, fs,
|
|
224
|
+
import { createDebugger, findExists, fs, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
|
-
import { createVirtualModule } from "@modern-js/builder-shared";
|
|
227
226
|
import { printInstructions } from "../utils/printInstructions";
|
|
228
227
|
import { generateRoutes } from "../utils/routes";
|
|
229
228
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
229
|
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
231
230
|
import { initialNormalizedConfig } from "../config";
|
|
232
231
|
import { createBuilderGenerator } from "../builder";
|
|
233
|
-
import {
|
|
232
|
+
import { isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
234
233
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
235
234
|
var debug = createDebugger("plugin-analyze");
|
|
236
235
|
var analyze_default = function(param) {
|
|
@@ -543,29 +542,6 @@ var analyze_default = function(param) {
|
|
|
543
542
|
watchFiles: function watchFiles() {
|
|
544
543
|
return pagesDir;
|
|
545
544
|
},
|
|
546
|
-
config: function config() {
|
|
547
|
-
return {
|
|
548
|
-
tools: {
|
|
549
|
-
webpackChain: function(chain, param) {
|
|
550
|
-
var name = param.name;
|
|
551
|
-
var appContext = api.useAppContext();
|
|
552
|
-
var resolvedConfig = api.useResolvedConfigContext();
|
|
553
|
-
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory, packageName = appContext.packageName;
|
|
554
|
-
entrypoints.forEach(function(entrypoint) {
|
|
555
|
-
var entryName = entrypoint.entryName;
|
|
556
|
-
var ssr = getEntryOptions(entryName, resolvedConfig.server.ssr, resolvedConfig.server.ssrByEntries, packageName);
|
|
557
|
-
var useSSG = isSSGEntry(resolvedConfig, entryName, entrypoints);
|
|
558
|
-
if (entrypoint.nestedRoutesEntry && (ssr || useSSG) && name === "server") {
|
|
559
|
-
var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
560
|
-
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
561
|
-
var combinedModule = createVirtualModule('export * from "'.concat(serverLoaderRuntime, '"; export * from "').concat(serverLoadersFile, '"'));
|
|
562
|
-
chain.entry("".concat(entryName, "-server-loaders")).add(combinedModule);
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
},
|
|
569
545
|
resolvedConfig: function resolvedConfig(param) {
|
|
570
546
|
var resolved = param.resolved;
|
|
571
547
|
var appContext = api.useAppContext();
|