@modern-js/app-tools 2.8.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/dist/cjs/analyze/generateCode.js +3 -1
- package/dist/cjs/analyze/index.js +8 -0
- package/dist/cjs/analyze/templates.js +33 -14
- package/dist/cjs/analyze/utils.js +9 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm/analyze/generateCode.js +3 -2
- package/dist/esm/analyze/index.js +8 -0
- package/dist/esm/analyze/templates.js +30 -16
- package/dist/esm/analyze/utils.js +5 -1
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm-node/analyze/generateCode.js +3 -1
- package/dist/esm-node/analyze/index.js +8 -0
- package/dist/esm-node/analyze/templates.js +33 -14
- package/dist/esm-node/analyze/utils.js +9 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/js/modern/analyze/constants.js +54 -0
- package/dist/js/modern/analyze/generateCode.js +247 -0
- package/dist/js/modern/analyze/getBundleEntry.js +71 -0
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
- package/dist/js/modern/analyze/getServerRoutes.js +175 -0
- package/dist/js/modern/analyze/index.js +332 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
- package/dist/js/modern/analyze/nestedRoutes.js +157 -0
- package/dist/js/modern/analyze/templates.js +334 -0
- package/dist/js/modern/analyze/utils.js +141 -0
- package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
- package/dist/js/modern/builder/index.js +159 -0
- package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
- package/dist/js/modern/builder/share.js +46 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
- package/dist/js/modern/commands/build.js +91 -0
- package/dist/js/modern/commands/deploy.js +28 -0
- package/dist/js/modern/commands/dev.js +109 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +38 -0
- package/dist/js/modern/commands/serve.js +54 -0
- package/dist/js/modern/config/default.js +175 -0
- package/dist/js/modern/config/index.js +8 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
- package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
- package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
- package/dist/js/modern/config/initial/index.js +16 -0
- package/dist/js/modern/config/initial/inits.js +152 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
- package/dist/js/modern/defineConfig.js +27 -0
- package/dist/js/modern/exports/server.js +4 -0
- package/dist/js/modern/hooks.js +35 -0
- package/dist/js/modern/index.js +211 -0
- package/dist/js/modern/initialize/index.js +124 -0
- package/dist/js/modern/locale/en.js +36 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +36 -0
- package/dist/js/modern/schema/Schema.js +40 -0
- package/dist/js/modern/schema/index.js +88 -0
- package/dist/js/modern/schema/legacy.js +148 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +1 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +3 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +0 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +128 -0
- package/dist/js/modern/utils/createServer.js +75 -0
- package/dist/js/modern/utils/env.js +15 -0
- package/dist/js/modern/utils/generateWatchFiles.js +55 -0
- package/dist/js/modern/utils/getSelectedEntries.js +58 -0
- package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
- package/dist/js/modern/utils/language.js +8 -0
- package/dist/js/modern/utils/printInstructions.js +31 -0
- package/dist/js/modern/utils/restart.js +44 -0
- package/dist/js/modern/utils/routes.js +30 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +98 -0
- package/dist/js/node/analyze/generateCode.js +271 -0
- package/dist/js/node/analyze/getBundleEntry.js +95 -0
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
- package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
- package/dist/js/node/analyze/getServerRoutes.js +194 -0
- package/dist/js/node/analyze/index.js +339 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
- package/dist/js/node/analyze/nestedRoutes.js +184 -0
- package/dist/js/node/analyze/templates.js +365 -0
- package/dist/js/node/analyze/utils.js +172 -0
- package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
- package/dist/js/node/builder/index.js +177 -0
- package/dist/js/node/builder/loaders/routerLoader.js +38 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
- package/dist/js/node/builder/share.js +75 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
- package/dist/js/node/commands/build.js +112 -0
- package/dist/js/node/commands/deploy.js +51 -0
- package/dist/js/node/commands/dev.js +126 -0
- package/dist/js/node/commands/index.js +19 -0
- package/dist/js/node/commands/inspect.js +61 -0
- package/dist/js/node/commands/serve.js +83 -0
- package/dist/js/node/config/default.js +197 -0
- package/dist/js/node/config/index.js +34 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
- package/dist/js/node/config/initial/createOutputConfig.js +91 -0
- package/dist/js/node/config/initial/createSourceConfig.js +62 -0
- package/dist/js/node/config/initial/createToolsConfig.js +65 -0
- package/dist/js/node/config/initial/index.js +41 -0
- package/dist/js/node/config/initial/inits.js +175 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
- package/dist/js/node/defineConfig.js +49 -0
- package/dist/js/node/exports/server.js +27 -0
- package/dist/js/node/hooks.js +54 -0
- package/dist/js/node/index.js +235 -0
- package/dist/js/node/initialize/index.js +134 -0
- package/dist/js/node/locale/en.js +59 -0
- package/dist/js/node/locale/index.js +33 -0
- package/dist/js/node/locale/zh.js +59 -0
- package/dist/js/node/schema/Schema.js +63 -0
- package/dist/js/node/schema/index.js +118 -0
- package/dist/js/node/schema/legacy.js +169 -0
- package/dist/js/node/types/config/deploy.js +15 -0
- package/dist/js/node/types/config/dev.js +15 -0
- package/dist/js/node/types/config/experiments.js +15 -0
- package/dist/js/node/types/config/html.js +15 -0
- package/dist/js/node/types/config/index.js +17 -0
- package/dist/js/node/types/config/output.js +15 -0
- package/dist/js/node/types/config/performance.js +15 -0
- package/dist/js/node/types/config/security.js +15 -0
- package/dist/js/node/types/config/source.js +15 -0
- package/dist/js/node/types/config/tools.js +15 -0
- package/dist/js/node/types/hooks.js +15 -0
- package/dist/js/node/types/index.js +19 -0
- package/dist/js/node/types/legacyConfig/deploy.js +15 -0
- package/dist/js/node/types/legacyConfig/dev.js +15 -0
- package/dist/js/node/types/legacyConfig/index.js +15 -0
- package/dist/js/node/types/legacyConfig/output.js +15 -0
- package/dist/js/node/types/legacyConfig/source.js +15 -0
- package/dist/js/node/types/legacyConfig/tools.js +15 -0
- package/dist/js/node/utils/config.js +153 -0
- package/dist/js/node/utils/createServer.js +106 -0
- package/dist/js/node/utils/env.js +38 -0
- package/dist/js/node/utils/generateWatchFiles.js +85 -0
- package/dist/js/node/utils/getSelectedEntries.js +81 -0
- package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
- package/dist/js/node/utils/language.js +31 -0
- package/dist/js/node/utils/printInstructions.js +54 -0
- package/dist/js/node/utils/restart.js +67 -0
- package/dist/js/node/utils/routes.js +59 -0
- package/dist/js/node/utils/types.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +40 -0
- package/dist/js/treeshaking/analyze/generateCode.js +485 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
- package/dist/js/treeshaking/analyze/index.js +697 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
- package/dist/js/treeshaking/analyze/templates.js +468 -0
- package/dist/js/treeshaking/analyze/utils.js +374 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
- package/dist/js/treeshaking/builder/index.js +374 -0
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
- package/dist/js/treeshaking/builder/share.js +40 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
- package/dist/js/treeshaking/commands/build.js +291 -0
- package/dist/js/treeshaking/commands/deploy.js +154 -0
- package/dist/js/treeshaking/commands/dev.js +301 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +149 -0
- package/dist/js/treeshaking/commands/serve.js +199 -0
- package/dist/js/treeshaking/config/default.js +210 -0
- package/dist/js/treeshaking/config/index.js +3 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
- package/dist/js/treeshaking/config/initial/index.js +12 -0
- package/dist/js/treeshaking/config/initial/inits.js +209 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
- package/dist/js/treeshaking/defineConfig.js +61 -0
- package/dist/js/treeshaking/exports/server.js +2 -0
- package/dist/js/treeshaking/hooks.js +29 -0
- package/dist/js/treeshaking/index.js +706 -0
- package/dist/js/treeshaking/initialize/index.js +276 -0
- package/dist/js/treeshaking/locale/en.js +38 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +38 -0
- package/dist/js/treeshaking/schema/Schema.js +273 -0
- package/dist/js/treeshaking/schema/index.js +181 -0
- package/dist/js/treeshaking/schema/legacy.js +337 -0
- package/dist/js/treeshaking/types/config/deploy.js +1 -0
- package/dist/js/treeshaking/types/config/dev.js +1 -0
- package/dist/js/treeshaking/types/config/experiments.js +1 -0
- package/dist/js/treeshaking/types/config/html.js +1 -0
- package/dist/js/treeshaking/types/config/index.js +1 -0
- package/dist/js/treeshaking/types/config/output.js +1 -0
- package/dist/js/treeshaking/types/config/performance.js +1 -0
- package/dist/js/treeshaking/types/config/security.js +1 -0
- package/dist/js/treeshaking/types/config/source.js +1 -0
- package/dist/js/treeshaking/types/config/tools.js +1 -0
- package/dist/js/treeshaking/types/hooks.js +1 -0
- package/dist/js/treeshaking/types/index.js +3 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
- package/dist/js/treeshaking/utils/config.js +302 -0
- package/dist/js/treeshaking/utils/createServer.js +258 -0
- package/dist/js/treeshaking/utils/env.js +13 -0
- package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
- package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
- package/dist/js/treeshaking/utils/language.js +6 -0
- package/dist/js/treeshaking/utils/printInstructions.js +152 -0
- package/dist/js/treeshaking/utils/restart.js +187 -0
- package/dist/js/treeshaking/utils/routes.js +153 -0
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/types/config/output.d.ts +1 -0
- package/package.json +10 -10
|
@@ -99,6 +99,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
99
99
|
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
|
100
100
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
101
101
|
async function generateEntryCode(entrypoint) {
|
|
102
|
+
var _a;
|
|
102
103
|
const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
|
103
104
|
if (isAutoMount) {
|
|
104
105
|
if (fileSystemRoutes) {
|
|
@@ -161,7 +162,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
161
162
|
ssrMode: useSSG ? "string" : mode,
|
|
162
163
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
163
164
|
entryName: entrypoint.entryName,
|
|
164
|
-
internalDirectory
|
|
165
|
+
internalDirectory,
|
|
166
|
+
splitRoutesChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRoutesChunks
|
|
165
167
|
})
|
|
166
168
|
});
|
|
167
169
|
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
|
@@ -247,6 +247,14 @@ var analyze_default = ({
|
|
|
247
247
|
imports
|
|
248
248
|
};
|
|
249
249
|
},
|
|
250
|
+
validateSchema() {
|
|
251
|
+
return {
|
|
252
|
+
target: "output.splitRoutesChunks",
|
|
253
|
+
schema: {
|
|
254
|
+
type: "boolean"
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
},
|
|
250
258
|
async fileChange(e) {
|
|
251
259
|
const appContext = api.useAppContext();
|
|
252
260
|
const { appDirectory } = appContext;
|
|
@@ -182,8 +182,10 @@ const fileSystemRoutes = async ({
|
|
|
182
182
|
ssrMode,
|
|
183
183
|
nestedRoutesEntry,
|
|
184
184
|
entryName,
|
|
185
|
-
internalDirectory
|
|
185
|
+
internalDirectory,
|
|
186
|
+
splitRoutesChunks = true
|
|
186
187
|
}) => {
|
|
188
|
+
const components = [];
|
|
187
189
|
const loadings = [];
|
|
188
190
|
const errors = [];
|
|
189
191
|
const loaders = [];
|
|
@@ -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}
|
|
@@ -337,7 +354,9 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
337
354
|
internalDirectory,
|
|
338
355
|
entryName
|
|
339
356
|
);
|
|
340
|
-
const combinedModule = `export * from "${
|
|
357
|
+
const combinedModule = `export * from "${(0, import_utils.slash)(
|
|
358
|
+
serverLoaderRuntime
|
|
359
|
+
)}"; export * from "${(0, import_utils.slash)(serverLoadersFile)}"`;
|
|
341
360
|
return combinedModule;
|
|
342
361
|
}
|
|
343
362
|
return null;
|
|
@@ -119,7 +119,15 @@ const isPageComponentFile = (filePath) => {
|
|
|
119
119
|
}
|
|
120
120
|
return false;
|
|
121
121
|
};
|
|
122
|
-
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
|
+
};
|
|
123
131
|
const parseModule = async ({
|
|
124
132
|
source,
|
|
125
133
|
filename
|
|
@@ -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(
|
|
@@ -245,7 +245,7 @@ var generateCode = function() {
|
|
|
245
245
|
}
|
|
246
246
|
function _generateEntryCode() {
|
|
247
247
|
_generateEntryCode = _asyncToGenerator(function(entrypoint) {
|
|
248
|
-
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, 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;
|
|
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:
|
|
@@ -322,7 +322,8 @@ var generateCode = function() {
|
|
|
322
322
|
ssrMode: useSSG ? "string" : mode,
|
|
323
323
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
324
324
|
entryName: entrypoint.entryName,
|
|
325
|
-
internalDirectory: internalDirectory
|
|
325
|
+
internalDirectory: internalDirectory,
|
|
326
|
+
splitRoutesChunks: config2 === null || config2 === void 0 ? void 0 : (_config2_output = config2.output) === null || _config2_output === void 0 ? void 0 : _config2_output.splitRoutesChunks
|
|
326
327
|
})
|
|
327
328
|
];
|
|
328
329
|
case 4:
|
|
@@ -638,6 +638,14 @@ var analyze_default = function(param) {
|
|
|
638
638
|
});
|
|
639
639
|
})();
|
|
640
640
|
},
|
|
641
|
+
validateSchema: function validateSchema() {
|
|
642
|
+
return {
|
|
643
|
+
target: "output.splitRoutesChunks",
|
|
644
|
+
schema: {
|
|
645
|
+
type: "boolean"
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
},
|
|
641
649
|
fileChange: function fileChange(e) {
|
|
642
650
|
return _asyncToGenerator(function() {
|
|
643
651
|
var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
|
|
@@ -298,11 +298,12 @@ var routesForServer = function(param) {
|
|
|
298
298
|
};
|
|
299
299
|
var fileSystemRoutes = function() {
|
|
300
300
|
var _ref = _asyncToGenerator(function(param) {
|
|
301
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
|
301
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRoutesChunks, splitRoutesChunks, components, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importComponentsCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
|
302
302
|
return __generator(this, function(_state) {
|
|
303
303
|
switch(_state.label){
|
|
304
304
|
case 0:
|
|
305
|
-
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
|
|
305
|
+
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory, _param_splitRoutesChunks = param.splitRoutesChunks, splitRoutesChunks = _param_splitRoutesChunks === void 0 ? true : _param_splitRoutesChunks;
|
|
306
|
+
components = [];
|
|
306
307
|
loadings = [];
|
|
307
308
|
errors = [];
|
|
308
309
|
loaders = [];
|
|
@@ -351,20 +352,30 @@ var fileSystemRoutes = function() {
|
|
|
351
352
|
};
|
|
352
353
|
}
|
|
353
354
|
if (route._component) {
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
if (splitRoutesChunks) {
|
|
356
|
+
if (route.isRoot) {
|
|
357
|
+
rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
|
|
358
|
+
component = "RootLayout";
|
|
359
|
+
} else if (ssrMode === "string") {
|
|
360
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
361
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
362
|
+
} else {
|
|
363
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
364
|
+
component = "lazy(".concat(lazyImport, ")");
|
|
365
|
+
}
|
|
360
366
|
} else {
|
|
361
|
-
|
|
362
|
-
component = "
|
|
367
|
+
components.push(route._component);
|
|
368
|
+
component = "component_".concat(components.length - 1);
|
|
363
369
|
}
|
|
364
370
|
}
|
|
365
371
|
} else if (route._component) {
|
|
366
|
-
|
|
367
|
-
|
|
372
|
+
if (splitRoutesChunks) {
|
|
373
|
+
lazyImport = "() => import('".concat(route._component, "')");
|
|
374
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
375
|
+
} else {
|
|
376
|
+
components.push(route._component);
|
|
377
|
+
component = "component_".concat(components.length - 1);
|
|
378
|
+
}
|
|
368
379
|
}
|
|
369
380
|
var finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
370
381
|
lazyImport: lazyImport,
|
|
@@ -385,13 +396,13 @@ var fileSystemRoutes = function() {
|
|
|
385
396
|
route = _step.value;
|
|
386
397
|
if ("type" in route) {
|
|
387
398
|
newRoute = traverseRouteTree(route);
|
|
388
|
-
routeComponentsCode += "".concat(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, '"'), ",");
|
|
399
|
+
routeComponentsCode += "".concat(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, '"'), ",");
|
|
389
400
|
} else {
|
|
390
401
|
component = "loadable(() => import('".concat(route._component, "'))");
|
|
391
402
|
finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
392
403
|
component: component
|
|
393
404
|
});
|
|
394
|
-
routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$
|
|
405
|
+
routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2"), ",");
|
|
395
406
|
}
|
|
396
407
|
}
|
|
397
408
|
} catch (err) {
|
|
@@ -412,6 +423,9 @@ var fileSystemRoutes = function() {
|
|
|
412
423
|
importLoadingCode = loadings.map(function(loading, index2) {
|
|
413
424
|
return "import loading_".concat(index2, " from '").concat(loading, "';\n");
|
|
414
425
|
}).join("");
|
|
426
|
+
importComponentsCode = components.map(function(component, index2) {
|
|
427
|
+
return "import component_".concat(index2, " from '").concat(component, "';\n");
|
|
428
|
+
}).join("");
|
|
415
429
|
importErrorComponentsCode = errors.map(function(error, index2) {
|
|
416
430
|
return "import error_".concat(index2, " from '").concat(error, "';\n");
|
|
417
431
|
}).join("");
|
|
@@ -454,7 +468,7 @@ var fileSystemRoutes = function() {
|
|
|
454
468
|
_state.sent();
|
|
455
469
|
return [
|
|
456
470
|
2,
|
|
457
|
-
"\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
471
|
+
"\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
458
472
|
];
|
|
459
473
|
}
|
|
460
474
|
});
|
|
@@ -471,7 +485,7 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
471
485
|
if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
|
|
472
486
|
var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
473
487
|
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
474
|
-
var combinedModule = 'export * from "'.concat(serverLoaderRuntime, '"; export * from "').concat(serverLoadersFile, '"');
|
|
488
|
+
var combinedModule = 'export * from "'.concat(slash(serverLoaderRuntime), '"; export * from "').concat(slash(serverLoadersFile), '"');
|
|
475
489
|
return combinedModule;
|
|
476
490
|
}
|
|
477
491
|
return null;
|
|
@@ -287,7 +287,11 @@ var isPageComponentFile = function(filePath) {
|
|
|
287
287
|
return false;
|
|
288
288
|
};
|
|
289
289
|
var replaceWithAlias = function(base, filePath, alias) {
|
|
290
|
-
|
|
290
|
+
if (filePath.includes(base)) {
|
|
291
|
+
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
292
|
+
} else {
|
|
293
|
+
return filePath;
|
|
294
|
+
}
|
|
291
295
|
};
|
|
292
296
|
var parseModule = function() {
|
|
293
297
|
var _ref = _asyncToGenerator(function(param) {
|
|
@@ -303,6 +303,9 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
303
303
|
for(_iterator1 = entryChunkFiles[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
304
304
|
file = _step1.value;
|
|
305
305
|
asset = compilation.assets[file];
|
|
306
|
+
if (!asset) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
306
309
|
newContent = "".concat(injectedContent).concat(asset.source().toString());
|
|
307
310
|
newAssetsMap.set(path.join(outputPath, file), newContent);
|
|
308
311
|
compilation.updateAsset(file, new RawSource(newContent), // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
|
@@ -81,6 +81,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
81
81
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
82
82
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
83
83
|
async function generateEntryCode(entrypoint) {
|
|
84
|
+
var _a;
|
|
84
85
|
const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
|
85
86
|
if (isAutoMount) {
|
|
86
87
|
if (fileSystemRoutes) {
|
|
@@ -143,7 +144,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
143
144
|
ssrMode: useSSG ? "string" : mode,
|
|
144
145
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
145
146
|
entryName: entrypoint.entryName,
|
|
146
|
-
internalDirectory
|
|
147
|
+
internalDirectory,
|
|
148
|
+
splitRoutesChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRoutesChunks
|
|
147
149
|
})
|
|
148
150
|
});
|
|
149
151
|
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
|
|
@@ -227,6 +227,14 @@ var analyze_default = ({
|
|
|
227
227
|
imports
|
|
228
228
|
};
|
|
229
229
|
},
|
|
230
|
+
validateSchema() {
|
|
231
|
+
return {
|
|
232
|
+
target: "output.splitRoutesChunks",
|
|
233
|
+
schema: {
|
|
234
|
+
type: "boolean"
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
},
|
|
230
238
|
async fileChange(e) {
|
|
231
239
|
const appContext = api.useAppContext();
|
|
232
240
|
const { appDirectory } = appContext;
|
|
@@ -145,8 +145,10 @@ const fileSystemRoutes = async ({
|
|
|
145
145
|
ssrMode,
|
|
146
146
|
nestedRoutesEntry,
|
|
147
147
|
entryName,
|
|
148
|
-
internalDirectory
|
|
148
|
+
internalDirectory,
|
|
149
|
+
splitRoutesChunks = true
|
|
149
150
|
}) => {
|
|
151
|
+
const components = [];
|
|
150
152
|
const loadings = [];
|
|
151
153
|
const errors = [];
|
|
152
154
|
const loaders = [];
|
|
@@ -205,20 +207,30 @@ const fileSystemRoutes = async ({
|
|
|
205
207
|
};
|
|
206
208
|
}
|
|
207
209
|
if (route._component) {
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
if (splitRoutesChunks) {
|
|
211
|
+
if (route.isRoot) {
|
|
212
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
213
|
+
component = `RootLayout`;
|
|
214
|
+
} else if (ssrMode === "string") {
|
|
215
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
216
|
+
component = `loadable(${lazyImport})`;
|
|
217
|
+
} else {
|
|
218
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
219
|
+
component = `lazy(${lazyImport})`;
|
|
220
|
+
}
|
|
214
221
|
} else {
|
|
215
|
-
|
|
216
|
-
component = `
|
|
222
|
+
components.push(route._component);
|
|
223
|
+
component = `component_${components.length - 1}`;
|
|
217
224
|
}
|
|
218
225
|
}
|
|
219
226
|
} else if (route._component) {
|
|
220
|
-
|
|
221
|
-
|
|
227
|
+
if (splitRoutesChunks) {
|
|
228
|
+
lazyImport = `() => import('${route._component}')`;
|
|
229
|
+
component = `loadable(${lazyImport})`;
|
|
230
|
+
} else {
|
|
231
|
+
components.push(route._component);
|
|
232
|
+
component = `component_${components.length - 1}`;
|
|
233
|
+
}
|
|
222
234
|
}
|
|
223
235
|
const finalRoute = {
|
|
224
236
|
...route,
|
|
@@ -239,20 +251,24 @@ const fileSystemRoutes = async ({
|
|
|
239
251
|
for (const route of routes) {
|
|
240
252
|
if ("type" in route) {
|
|
241
253
|
const newRoute = traverseRouteTree(route);
|
|
242
|
-
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, '"')},`;
|
|
254
|
+
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, '"')},`;
|
|
243
255
|
} else {
|
|
244
256
|
const component = `loadable(() => import('${route._component}'))`;
|
|
245
257
|
const finalRoute = {
|
|
246
258
|
...route,
|
|
247
259
|
component
|
|
248
260
|
};
|
|
249
|
-
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$
|
|
261
|
+
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2")},`;
|
|
250
262
|
}
|
|
251
263
|
}
|
|
252
264
|
routeComponentsCode += `
|
|
253
265
|
];`;
|
|
254
266
|
const importLoadingCode = loadings.map((loading, index2) => {
|
|
255
267
|
return `import loading_${index2} from '${loading}';
|
|
268
|
+
`;
|
|
269
|
+
}).join("");
|
|
270
|
+
const importComponentsCode = components.map((component, index2) => {
|
|
271
|
+
return `import component_${index2} from '${component}';
|
|
256
272
|
`;
|
|
257
273
|
}).join("");
|
|
258
274
|
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
@@ -277,6 +293,7 @@ const fileSystemRoutes = async ({
|
|
|
277
293
|
await fs.writeJSON(loadersMapFile, loadersMap);
|
|
278
294
|
return `
|
|
279
295
|
${importLazyCode}
|
|
296
|
+
${importComponentsCode}
|
|
280
297
|
${rootLayoutCode}
|
|
281
298
|
${importLoadingCode}
|
|
282
299
|
${importErrorComponentsCode}
|
|
@@ -300,7 +317,9 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
300
317
|
internalDirectory,
|
|
301
318
|
entryName
|
|
302
319
|
);
|
|
303
|
-
const combinedModule = `export * from "${
|
|
320
|
+
const combinedModule = `export * from "${slash(
|
|
321
|
+
serverLoaderRuntime
|
|
322
|
+
)}"; export * from "${slash(serverLoadersFile)}"`;
|
|
304
323
|
return combinedModule;
|
|
305
324
|
}
|
|
306
325
|
return null;
|
|
@@ -84,7 +84,15 @@ const isPageComponentFile = (filePath) => {
|
|
|
84
84
|
}
|
|
85
85
|
return false;
|
|
86
86
|
};
|
|
87
|
-
const replaceWithAlias = (base, filePath, alias) =>
|
|
87
|
+
const replaceWithAlias = (base, filePath, alias) => {
|
|
88
|
+
if (filePath.includes(base)) {
|
|
89
|
+
return normalizeToPosixPath(
|
|
90
|
+
path.join(alias, path.relative(base, filePath))
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
return filePath;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
88
96
|
const parseModule = async ({
|
|
89
97
|
source,
|
|
90
98
|
filename
|
|
@@ -80,6 +80,9 @@ class RouterPlugin {
|
|
|
80
80
|
);
|
|
81
81
|
for (const file of entryChunkFiles) {
|
|
82
82
|
const asset = compilation.assets[file];
|
|
83
|
+
if (!asset) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
83
86
|
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
84
87
|
newAssetsMap.set(path.join(outputPath, file), newContent);
|
|
85
88
|
compilation.updateAsset(
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const JS_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
|
|
2
|
+
const INDEX_FILE_NAME = "index";
|
|
3
|
+
const APP_FILE_NAME = "App";
|
|
4
|
+
const PAGES_DIR_NAME = "pages";
|
|
5
|
+
const NESTED_ROUTES_DIR = "routes";
|
|
6
|
+
const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
7
|
+
const LOADER_EXPORT_NAME = "loader";
|
|
8
|
+
const TEMP_LOADERS_DIR = "__loaders__";
|
|
9
|
+
const ENTRY_POINT_FILE_NAME = "index.js";
|
|
10
|
+
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
|
|
11
|
+
const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
|
12
|
+
const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
|
|
13
|
+
const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
|
|
14
|
+
const FILE_SYSTEM_ROUTES_INDEX = "index";
|
|
15
|
+
const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
|
|
16
|
+
const HTML_PARTIALS_FOLDER = "html";
|
|
17
|
+
const HTML_PARTIALS_EXTENSIONS = [".htm", ".html", ".ejs"];
|
|
18
|
+
const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
|
19
|
+
const NESTED_ROUTE = {
|
|
20
|
+
LAYOUT_FILE: "layout",
|
|
21
|
+
LAYOUT_LOADER_FILE: "layout.loader",
|
|
22
|
+
PAGE_FILE: "page",
|
|
23
|
+
PAGE_LOADER_FILE: "page.loader",
|
|
24
|
+
LOADING_FILE: "loading",
|
|
25
|
+
ERROR_FILE: "error",
|
|
26
|
+
LOADER_FILE: "loader"
|
|
27
|
+
};
|
|
28
|
+
const APP_CONFIG_NAME = "config";
|
|
29
|
+
const APP_INIT_EXPORTED = "init";
|
|
30
|
+
const APP_INIT_IMPORTED = "appInit";
|
|
31
|
+
export {
|
|
32
|
+
APP_CONFIG_NAME,
|
|
33
|
+
APP_FILE_NAME,
|
|
34
|
+
APP_INIT_EXPORTED,
|
|
35
|
+
APP_INIT_IMPORTED,
|
|
36
|
+
ENTRY_BOOTSTRAP_FILE_NAME,
|
|
37
|
+
ENTRY_POINT_FILE_NAME,
|
|
38
|
+
FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
|
|
39
|
+
FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
|
|
40
|
+
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
41
|
+
FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
|
|
42
|
+
FILE_SYSTEM_ROUTES_IGNORED_REGEX,
|
|
43
|
+
FILE_SYSTEM_ROUTES_INDEX,
|
|
44
|
+
FILE_SYSTEM_ROUTES_LAYOUT,
|
|
45
|
+
HTML_PARTIALS_EXTENSIONS,
|
|
46
|
+
HTML_PARTIALS_FOLDER,
|
|
47
|
+
INDEX_FILE_NAME,
|
|
48
|
+
JS_EXTENSIONS,
|
|
49
|
+
LOADER_EXPORT_NAME,
|
|
50
|
+
NESTED_ROUTE,
|
|
51
|
+
NESTED_ROUTES_DIR,
|
|
52
|
+
PAGES_DIR_NAME,
|
|
53
|
+
TEMP_LOADERS_DIR
|
|
54
|
+
};
|