@modern-js/app-tools 2.40.0 → 2.42.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/getHtmlTemplate.js +5 -5
- package/dist/cjs/analyze/templates.js +7 -6
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +3 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/cjs/config/default.js +2 -1
- package/dist/cjs/defineConfig.js +8 -6
- package/dist/esm/analyze/getHtmlTemplate.js +5 -5
- package/dist/esm/analyze/templates.js +6 -6
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -4
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/esm/config/default.js +2 -1
- package/dist/esm/config/initialize/inits.js +19 -19
- package/dist/esm/defineConfig.js +1 -1
- package/dist/esm-node/analyze/getHtmlTemplate.js +5 -5
- package/dist/esm-node/analyze/templates.js +7 -6
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +3 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/esm-node/config/default.js +2 -1
- package/dist/esm-node/defineConfig.js +8 -6
- package/dist/types/analyze/constants.d.ts +19 -19
- package/dist/types/analyze/generateCode.d.ts +9 -16
- package/dist/types/analyze/getBundleEntry.d.ts +1 -1
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +7 -13
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +7 -13
- package/dist/types/analyze/getClientRoutes/index.d.ts +1 -1
- package/dist/types/analyze/getClientRoutes/utils.d.ts +1 -1
- package/dist/types/analyze/getFileSystemEntry.d.ts +1 -1
- package/dist/types/analyze/getHtmlTemplate.d.ts +4 -7
- package/dist/types/analyze/getServerRoutes.d.ts +4 -7
- package/dist/types/analyze/index.d.ts +3 -5
- package/dist/types/analyze/isDefaultExportFunction.d.ts +1 -1
- package/dist/types/analyze/makeLegalIdentifier.d.ts +1 -1
- package/dist/types/analyze/nestedRoutes.d.ts +3 -3
- package/dist/types/analyze/templates.d.ts +22 -40
- package/dist/types/analyze/utils.d.ts +10 -19
- package/dist/types/builder/builder-rspack/adapterCopy.d.ts +1 -1
- package/dist/types/builder/builder-rspack/index.d.ts +1 -1
- package/dist/types/builder/builder-webpack/adapterModern.d.ts +1 -1
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +20 -20
- package/dist/types/builder/builder-webpack/index.d.ts +1 -1
- package/dist/types/builder/generator/createBuilderOptions.d.ts +1 -1
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
- package/dist/types/builder/generator/getBuilderTargets.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +2 -2
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +5 -5
- package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +7 -7
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +24 -31
- package/dist/types/builder/shared/bundlerPlugins/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +4 -4
- package/dist/types/builder/shared/index.d.ts +1 -1
- package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +3 -3
- package/dist/types/commands/build.d.ts +1 -1
- package/dist/types/commands/deploy.d.ts +1 -1
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +7 -7
- package/dist/types/commands/serve.d.ts +1 -1
- package/dist/types/config/default.d.ts +1 -1
- package/dist/types/config/index.d.ts +1 -1
- package/dist/types/config/initialize/index.d.ts +1 -1
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/config/legacy/createHtmlConfig.d.ts +1 -1
- package/dist/types/config/legacy/createOutputConfig.d.ts +1 -1
- package/dist/types/config/legacy/createSourceConfig.d.ts +1 -1
- package/dist/types/config/legacy/createToolsConfig.d.ts +1 -1
- package/dist/types/config/legacy/index.d.ts +1 -1
- package/dist/types/defineConfig.d.ts +1 -1
- package/dist/types/exports/server.d.ts +1 -1
- package/dist/types/hooks.d.ts +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/initialize/index.d.ts +3 -5
- package/dist/types/locale/en.d.ts +38 -38
- package/dist/types/locale/index.d.ts +75 -75
- package/dist/types/locale/zh.d.ts +38 -38
- package/dist/types/types/config/deploy.d.ts +21 -21
- package/dist/types/types/config/dev.d.ts +10 -10
- package/dist/types/types/config/experiments.d.ts +1 -1
- package/dist/types/types/config/html.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +38 -38
- package/dist/types/types/config/output.d.ts +35 -28
- package/dist/types/types/config/performance.d.ts +1 -1
- package/dist/types/types/config/security.d.ts +1 -1
- package/dist/types/types/config/source.d.ts +52 -52
- package/dist/types/types/config/testing.d.ts +6 -6
- package/dist/types/types/config/tools.d.ts +26 -24
- package/dist/types/types/hooks.d.ts +75 -75
- package/dist/types/types/index.d.ts +17 -17
- package/dist/types/types/legacyConfig/deploy.d.ts +5 -5
- package/dist/types/types/legacyConfig/dev.d.ts +9 -9
- package/dist/types/types/legacyConfig/index.d.ts +16 -16
- package/dist/types/types/legacyConfig/output.d.ts +45 -45
- package/dist/types/types/legacyConfig/source.d.ts +22 -22
- package/dist/types/types/legacyConfig/testing.d.ts +6 -6
- package/dist/types/types/legacyConfig/tools.d.ts +10 -10
- package/dist/types/types/utils.d.ts +4 -4
- package/dist/types/utils/config.d.ts +7 -13
- package/dist/types/utils/createServer.d.ts +5 -5
- package/dist/types/utils/env.d.ts +1 -1
- package/dist/types/utils/generateWatchFiles.d.ts +1 -1
- package/dist/types/utils/getSelectedEntries.d.ts +1 -1
- package/dist/types/utils/getServerInternalPlugins.d.ts +1 -1
- package/dist/types/utils/printInstructions.d.ts +1 -1
- package/dist/types/utils/restart.d.ts +1 -1
- package/dist/types/utils/routes.d.ts +1 -1
- package/dist/types/utils/types.d.ts +13 -13
- package/package.json +26 -26
@@ -63,7 +63,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
63
63
|
for (const entrypoint of entrypoints) {
|
64
64
|
const { entryName, isMainEntry } = entrypoint;
|
65
65
|
const name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
|
66
|
-
const customIndexTemplate = findPartials(htmlDir, name,
|
66
|
+
const customIndexTemplate = findPartials(htmlDir, name, "index");
|
67
67
|
if (customIndexTemplate) {
|
68
68
|
htmlTemplates[entryName] = customIndexTemplate.file;
|
69
69
|
} else {
|
@@ -71,9 +71,9 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
71
71
|
const { partials } = await hookRunners.htmlPartials({
|
72
72
|
entrypoint,
|
73
73
|
partials: [
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
"top",
|
75
|
+
"head",
|
76
|
+
"body"
|
77
77
|
].reduce((previous, position) => {
|
78
78
|
const found = findPartials(htmlDir, name, position);
|
79
79
|
previous[position] = found ? [
|
@@ -90,7 +90,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
90
90
|
import_utils.fs.outputFileSync(templatePath, templates.html(partials), "utf8");
|
91
91
|
htmlTemplates[entryName] = templatePath;
|
92
92
|
partialsByEntrypoint[entryName] = partials;
|
93
|
-
const bottomTemplate = findPartials(htmlDir, name,
|
93
|
+
const bottomTemplate = findPartials(htmlDir, name, "bottom");
|
94
94
|
if (bottomTemplate) {
|
95
95
|
htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
|
96
96
|
}
|
@@ -190,7 +190,8 @@ const routesForServer = ({ routes }) => {
|
|
190
190
|
${routesCode}
|
191
191
|
`;
|
192
192
|
};
|
193
|
-
const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([
|
193
|
+
const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^
|
194
|
+
]+)"`, "g");
|
194
195
|
const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true }) => {
|
195
196
|
const components = [];
|
196
197
|
const loadings = [];
|
@@ -264,18 +265,18 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
|
|
264
265
|
if (route._component) {
|
265
266
|
if (splitRouteChunks) {
|
266
267
|
if (route.isRoot) {
|
267
|
-
lazyImport = `() => import('${route._component}').then(routeModule =>
|
268
|
+
lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
268
269
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
269
270
|
component = `RootLayout`;
|
270
271
|
} else if (ssrMode === "string") {
|
271
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule =>
|
272
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
272
273
|
component = `loadable(${lazyImport})`;
|
273
274
|
} else {
|
274
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule =>
|
275
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
275
276
|
component = `lazy(${lazyImport})`;
|
276
277
|
}
|
277
278
|
} else {
|
278
|
-
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule =>
|
279
|
+
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
279
280
|
if (ssrMode === "string") {
|
280
281
|
component = `loadable(${lazyImport})`;
|
281
282
|
} else {
|
@@ -402,7 +403,7 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
|
|
402
403
|
await import_utils.fs.ensureFile(loadersMapFile);
|
403
404
|
await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
404
405
|
const importRuntimeRouterCode = `
|
405
|
-
import { createShouldRevalidate } from '@modern-js/runtime/router';
|
406
|
+
import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';
|
406
407
|
`;
|
407
408
|
const routeModulesCode = `
|
408
409
|
if(typeof document !== 'undefined'){
|
@@ -109,12 +109,14 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
|
109
109
|
const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
110
110
|
const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
111
111
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
112
|
+
const { enableInlineRouteManifests, disableInlineRouteManifests } = normalizedConfig.output;
|
113
|
+
const inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
|
112
114
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
113
115
|
var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
|
114
116
|
chain.plugin(pluginName).use(import_bundlerPlugins.RouterPlugin, [
|
115
117
|
{
|
116
118
|
HtmlBundlerPlugin,
|
117
|
-
enableInlineRouteManifests:
|
119
|
+
enableInlineRouteManifests: inlineRouteManifests,
|
118
120
|
staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
|
119
121
|
disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
|
120
122
|
scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
|
@@ -62,7 +62,7 @@ class RouterPlugin {
|
|
62
62
|
return;
|
63
63
|
}
|
64
64
|
const { webpack } = compiler;
|
65
|
-
const isRspack = webpack
|
65
|
+
const isRspack = "rspackVersion" in webpack;
|
66
66
|
const { Compilation, sources } = webpack;
|
67
67
|
const { RawSource } = sources;
|
68
68
|
const normalizePath = (path) => {
|
@@ -36,7 +36,8 @@ function createDefaultConfig(appContext, bundler) {
|
|
36
36
|
const output = {
|
37
37
|
...defaultBuilderConfig.output,
|
38
38
|
disableNodePolyfill: true,
|
39
|
-
enableInlineRouteManifests: true
|
39
|
+
enableInlineRouteManifests: true,
|
40
|
+
disableInlineRouteManifests: false
|
40
41
|
};
|
41
42
|
const source = {
|
42
43
|
...defaultBuilderConfig.source,
|
package/dist/cjs/defineConfig.js
CHANGED
@@ -23,12 +23,14 @@ __export(defineConfig_exports, {
|
|
23
23
|
});
|
24
24
|
module.exports = __toCommonJS(defineConfig_exports);
|
25
25
|
const defineConfig = (config) => config;
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
const defineLegacyConfig = (config) => {
|
27
|
+
var _config_autoLoadPlugins;
|
28
|
+
return {
|
29
|
+
...config,
|
30
|
+
legacy: true,
|
31
|
+
autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
|
32
|
+
};
|
33
|
+
};
|
32
34
|
// Annotate the CommonJS export names for ESM import in node:
|
33
35
|
0 && (module.exports = {
|
34
36
|
defineConfig,
|
@@ -59,7 +59,7 @@ var getHtmlTemplate = function() {
|
|
59
59
|
entrypoint = _step.value;
|
60
60
|
entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
|
61
61
|
name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
|
62
|
-
customIndexTemplate = findPartials(htmlDir, name,
|
62
|
+
customIndexTemplate = findPartials(htmlDir, name, "index");
|
63
63
|
if (!customIndexTemplate)
|
64
64
|
return [
|
65
65
|
3,
|
@@ -77,9 +77,9 @@ var getHtmlTemplate = function() {
|
|
77
77
|
hookRunners.htmlPartials({
|
78
78
|
entrypoint,
|
79
79
|
partials: [
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
"top",
|
81
|
+
"head",
|
82
|
+
"body"
|
83
83
|
].reduce(function(previous, position) {
|
84
84
|
var found = findPartials(htmlDir, name, position);
|
85
85
|
previous[position] = found ? [
|
@@ -99,7 +99,7 @@ var getHtmlTemplate = function() {
|
|
99
99
|
fs.outputFileSync(templatePath, templates.html(partials), "utf8");
|
100
100
|
htmlTemplates[entryName] = templatePath;
|
101
101
|
partialsByEntrypoint[entryName] = partials;
|
102
|
-
bottomTemplate = findPartials(htmlDir, name,
|
102
|
+
bottomTemplate = findPartials(htmlDir, name, "bottom");
|
103
103
|
if (bottomTemplate) {
|
104
104
|
htmlTemplates["__".concat(entryName, "-bottom__")] = bottomTemplate.content;
|
105
105
|
}
|
@@ -131,7 +131,7 @@ var routesForServer = function(param) {
|
|
131
131
|
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
132
132
|
};
|
133
133
|
var createMatchReg = function(keyword) {
|
134
|
-
return new RegExp('("'.concat(keyword, '":\\s)"([
|
134
|
+
return new RegExp('("'.concat(keyword, '":\\s)"([^\n]+)"'), "g");
|
135
135
|
};
|
136
136
|
var fileSystemRoutes = function() {
|
137
137
|
var _ref = _async_to_generator(function(param) {
|
@@ -210,18 +210,18 @@ var fileSystemRoutes = function() {
|
|
210
210
|
if (route2._component) {
|
211
211
|
if (splitRouteChunks) {
|
212
212
|
if (route2.isRoot) {
|
213
|
-
lazyImport = "() => import('".concat(route2._component, `').then(routeModule =>
|
213
|
+
lazyImport = "() => import('".concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
|
214
214
|
rootLayoutCode = "import RootLayout from '".concat(route2._component, "'");
|
215
215
|
component2 = "RootLayout";
|
216
216
|
} else if (ssrMode === "string") {
|
217
|
-
lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule =>
|
217
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
|
218
218
|
component2 = "loadable(".concat(lazyImport, ")");
|
219
219
|
} else {
|
220
|
-
lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule =>
|
220
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
|
221
221
|
component2 = "lazy(".concat(lazyImport, ")");
|
222
222
|
}
|
223
223
|
} else {
|
224
|
-
lazyImport = `() => import(/* webpackMode: "eager" */ '`.concat(route2._component, `').then(routeModule =>
|
224
|
+
lazyImport = `() => import(/* webpackMode: "eager" */ '`.concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
|
225
225
|
if (ssrMode === "string") {
|
226
226
|
component2 = "loadable(".concat(lazyImport, ")");
|
227
227
|
} else {
|
@@ -400,7 +400,7 @@ var fileSystemRoutes = function() {
|
|
400
400
|
];
|
401
401
|
case 2:
|
402
402
|
_state.sent();
|
403
|
-
importRuntimeRouterCode = "\n import { createShouldRevalidate } from '@modern-js/runtime/router';\n ";
|
403
|
+
importRuntimeRouterCode = "\n import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';\n ";
|
404
404
|
routeModulesCode = "\n if(typeof document !== 'undefined'){\n window.".concat(ROUTE_MODULES, " = {}\n }\n ");
|
405
405
|
return [
|
406
406
|
2,
|
@@ -127,14 +127,16 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
|
127
127
|
var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
128
128
|
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
129
129
|
var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
130
|
+
var _normalizedConfig_output = normalizedConfig.output, enableInlineRouteManifests = _normalizedConfig_output.enableInlineRouteManifests, disableInlineRouteManifests = _normalizedConfig_output.disableInlineRouteManifests;
|
131
|
+
var inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
|
130
132
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
131
|
-
var _normalizedConfig_output_distPath,
|
133
|
+
var _normalizedConfig_output_distPath, _normalizedConfig_output1, _normalizedConfig_output2, _normalizedConfig_html, _normalizedConfig_security;
|
132
134
|
chain.plugin(pluginName).use(RouterPlugin, [
|
133
135
|
{
|
134
136
|
HtmlBundlerPlugin,
|
135
|
-
enableInlineRouteManifests:
|
136
|
-
staticJsDir: (
|
137
|
-
disableFilenameHash: (
|
137
|
+
enableInlineRouteManifests: inlineRouteManifests,
|
138
|
+
staticJsDir: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output1.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
|
139
|
+
disableFilenameHash: (_normalizedConfig_output2 = normalizedConfig.output) === null || _normalizedConfig_output2 === void 0 ? void 0 : _normalizedConfig_output2.disableFilenameHash,
|
138
140
|
scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
|
139
141
|
nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
|
140
142
|
}
|
@@ -80,7 +80,7 @@ var RouterPlugin = /* @__PURE__ */ function() {
|
|
80
80
|
return;
|
81
81
|
}
|
82
82
|
var webpack = compiler.webpack;
|
83
|
-
var isRspack = webpack
|
83
|
+
var isRspack = "rspackVersion" in webpack;
|
84
84
|
var Compilation = webpack.Compilation, sources = webpack.sources;
|
85
85
|
var RawSource = sources.RawSource;
|
86
86
|
var normalizePath = function(path) {
|
@@ -13,7 +13,8 @@ function createDefaultConfig(appContext, bundler) {
|
|
13
13
|
});
|
14
14
|
var output = _object_spread_props(_object_spread({}, defaultBuilderConfig.output), {
|
15
15
|
disableNodePolyfill: true,
|
16
|
-
enableInlineRouteManifests: true
|
16
|
+
enableInlineRouteManifests: true,
|
17
|
+
disableInlineRouteManifests: false
|
17
18
|
});
|
18
19
|
var _obj;
|
19
20
|
var source = _object_spread_props(_object_spread({}, defaultBuilderConfig.source), {
|
@@ -1,31 +1,31 @@
|
|
1
1
|
import path, { isAbsolute } from "path";
|
2
2
|
import { findExists } from "@modern-js/utils";
|
3
3
|
function initHtmlConfig(config, appContext) {
|
4
|
-
var
|
4
|
+
var ICON_EXTENSIONS = [
|
5
|
+
"png",
|
6
|
+
"jpg",
|
7
|
+
"jpeg",
|
8
|
+
"svg",
|
9
|
+
"ico"
|
10
|
+
];
|
11
|
+
config.html.appIcon = createBuilderAppIcon(config, appContext);
|
12
|
+
config.html.favicon = createBuilderFavicon(config, appContext);
|
13
|
+
return config.html;
|
14
|
+
function createBuilderAppIcon(config2, appContext2) {
|
5
15
|
var configDir = config2.source.configDir;
|
6
16
|
var appIcon = findExists(ICON_EXTENSIONS.map(function(ext) {
|
7
17
|
return path.resolve(appContext2.appDirectory, configDir || "./config", "icon.".concat(ext));
|
8
18
|
}));
|
9
19
|
return typeof appIcon === "string" ? appIcon : void 0;
|
10
|
-
}
|
11
|
-
|
20
|
+
}
|
21
|
+
function createBuilderFavicon(config2, appContext2) {
|
12
22
|
var configDir = config2.source.configDir;
|
13
23
|
var favicon = config2.html.favicon;
|
14
24
|
var defaultFavicon = findExists(ICON_EXTENSIONS.map(function(ext) {
|
15
25
|
return path.resolve(appContext2.appDirectory, configDir || "./config", "favicon.".concat(ext));
|
16
26
|
}));
|
17
27
|
return favicon || defaultFavicon || void 0;
|
18
|
-
}
|
19
|
-
var ICON_EXTENSIONS = [
|
20
|
-
"png",
|
21
|
-
"jpg",
|
22
|
-
"jpeg",
|
23
|
-
"svg",
|
24
|
-
"ico"
|
25
|
-
];
|
26
|
-
config.html.appIcon = createBuilderAppIcon(config, appContext);
|
27
|
-
config.html.favicon = createBuilderFavicon(config, appContext);
|
28
|
-
return config.html;
|
28
|
+
}
|
29
29
|
}
|
30
30
|
function initSourceConfig(config, appContext, bundler) {
|
31
31
|
config.source.include = createBuilderInclude(config, appContext);
|
@@ -50,11 +50,6 @@ function createBuilderInclude(config, appContext) {
|
|
50
50
|
return transformInclude;
|
51
51
|
}
|
52
52
|
function createBuilderModuleScope(config) {
|
53
|
-
var isPrimitiveScope = function isPrimitiveScope2(items) {
|
54
|
-
return items.every(function(item) {
|
55
|
-
return typeof item === "string" || Object.prototype.toString.call(item) === "[object RegExp]";
|
56
|
-
});
|
57
|
-
};
|
58
53
|
var moduleScopes = config.source.moduleScopes;
|
59
54
|
if (moduleScopes) {
|
60
55
|
var DEFAULT_SCOPES = [
|
@@ -67,6 +62,11 @@ function createBuilderModuleScope(config) {
|
|
67
62
|
} else {
|
68
63
|
return void 0;
|
69
64
|
}
|
65
|
+
function isPrimitiveScope(items) {
|
66
|
+
return items.every(function(item) {
|
67
|
+
return typeof item === "string" || Object.prototype.toString.call(item) === "[object RegExp]";
|
68
|
+
});
|
69
|
+
}
|
70
70
|
function applyScopeOptions(defaults, options) {
|
71
71
|
if (Array.isArray(options)) {
|
72
72
|
if (isPrimitiveScope(options)) {
|
package/dist/esm/defineConfig.js
CHANGED
@@ -3,8 +3,8 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
var defineConfig = function(config) {
|
4
4
|
return config;
|
5
5
|
};
|
6
|
-
var _config_autoLoadPlugins;
|
7
6
|
var defineLegacyConfig = function(config) {
|
7
|
+
var _config_autoLoadPlugins;
|
8
8
|
return _object_spread_props(_object_spread({}, config), {
|
9
9
|
legacy: true,
|
10
10
|
autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
|
@@ -30,7 +30,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
30
30
|
for (const entrypoint of entrypoints) {
|
31
31
|
const { entryName, isMainEntry } = entrypoint;
|
32
32
|
const name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
|
33
|
-
const customIndexTemplate = findPartials(htmlDir, name,
|
33
|
+
const customIndexTemplate = findPartials(htmlDir, name, "index");
|
34
34
|
if (customIndexTemplate) {
|
35
35
|
htmlTemplates[entryName] = customIndexTemplate.file;
|
36
36
|
} else {
|
@@ -38,9 +38,9 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
38
38
|
const { partials } = await hookRunners.htmlPartials({
|
39
39
|
entrypoint,
|
40
40
|
partials: [
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
"top",
|
42
|
+
"head",
|
43
|
+
"body"
|
44
44
|
].reduce((previous, position) => {
|
45
45
|
const found = findPartials(htmlDir, name, position);
|
46
46
|
previous[position] = found ? [
|
@@ -57,7 +57,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
57
57
|
fs.outputFileSync(templatePath, templates.html(partials), "utf8");
|
58
58
|
htmlTemplates[entryName] = templatePath;
|
59
59
|
partialsByEntrypoint[entryName] = partials;
|
60
|
-
const bottomTemplate = findPartials(htmlDir, name,
|
60
|
+
const bottomTemplate = findPartials(htmlDir, name, "bottom");
|
61
61
|
if (bottomTemplate) {
|
62
62
|
htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
|
63
63
|
}
|
@@ -152,7 +152,8 @@ const routesForServer = ({ routes }) => {
|
|
152
152
|
${routesCode}
|
153
153
|
`;
|
154
154
|
};
|
155
|
-
const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([
|
155
|
+
const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^
|
156
|
+
]+)"`, "g");
|
156
157
|
const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true }) => {
|
157
158
|
const components = [];
|
158
159
|
const loadings = [];
|
@@ -226,18 +227,18 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
|
|
226
227
|
if (route._component) {
|
227
228
|
if (splitRouteChunks) {
|
228
229
|
if (route.isRoot) {
|
229
|
-
lazyImport = `() => import('${route._component}').then(routeModule =>
|
230
|
+
lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
230
231
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
231
232
|
component = `RootLayout`;
|
232
233
|
} else if (ssrMode === "string") {
|
233
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule =>
|
234
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
234
235
|
component = `loadable(${lazyImport})`;
|
235
236
|
} else {
|
236
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule =>
|
237
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
237
238
|
component = `lazy(${lazyImport})`;
|
238
239
|
}
|
239
240
|
} else {
|
240
|
-
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule =>
|
241
|
+
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
241
242
|
if (ssrMode === "string") {
|
242
243
|
component = `loadable(${lazyImport})`;
|
243
244
|
} else {
|
@@ -364,7 +365,7 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
|
|
364
365
|
await fs.ensureFile(loadersMapFile);
|
365
366
|
await fs.writeJSON(loadersMapFile, loadersMap);
|
366
367
|
const importRuntimeRouterCode = `
|
367
|
-
import { createShouldRevalidate } from '@modern-js/runtime/router';
|
368
|
+
import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';
|
368
369
|
`;
|
369
370
|
const routeModulesCode = `
|
370
371
|
if(typeof document !== 'undefined'){
|
@@ -76,12 +76,14 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
|
76
76
|
const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
77
77
|
const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
78
78
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
79
|
+
const { enableInlineRouteManifests, disableInlineRouteManifests } = normalizedConfig.output;
|
80
|
+
const inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
|
79
81
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
80
82
|
var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
|
81
83
|
chain.plugin(pluginName).use(RouterPlugin, [
|
82
84
|
{
|
83
85
|
HtmlBundlerPlugin,
|
84
|
-
enableInlineRouteManifests:
|
86
|
+
enableInlineRouteManifests: inlineRouteManifests,
|
85
87
|
staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
|
86
88
|
disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
|
87
89
|
scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
|
@@ -39,7 +39,7 @@ class RouterPlugin {
|
|
39
39
|
return;
|
40
40
|
}
|
41
41
|
const { webpack } = compiler;
|
42
|
-
const isRspack = webpack
|
42
|
+
const isRspack = "rspackVersion" in webpack;
|
43
43
|
const { Compilation, sources } = webpack;
|
44
44
|
const { RawSource } = sources;
|
45
45
|
const normalizePath = (path) => {
|
@@ -12,7 +12,8 @@ function createDefaultConfig(appContext, bundler) {
|
|
12
12
|
const output = {
|
13
13
|
...defaultBuilderConfig.output,
|
14
14
|
disableNodePolyfill: true,
|
15
|
-
enableInlineRouteManifests: true
|
15
|
+
enableInlineRouteManifests: true,
|
16
|
+
disableInlineRouteManifests: false
|
16
17
|
};
|
17
18
|
const source = {
|
18
19
|
...defaultBuilderConfig.source,
|
@@ -1,10 +1,12 @@
|
|
1
1
|
const defineConfig = (config) => config;
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
const defineLegacyConfig = (config) => {
|
3
|
+
var _config_autoLoadPlugins;
|
4
|
+
return {
|
5
|
+
...config,
|
6
|
+
legacy: true,
|
7
|
+
autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
|
8
|
+
};
|
9
|
+
};
|
8
10
|
export {
|
9
11
|
defineConfig,
|
10
12
|
defineLegacyConfig
|
@@ -18,25 +18,25 @@ export declare const HTML_PARTIALS_FOLDER = "html";
|
|
18
18
|
export declare const HTML_PARTIALS_EXTENSIONS: string[];
|
19
19
|
export declare const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
20
20
|
export declare const NESTED_ROUTE: {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
LAYOUT_FILE: string;
|
22
|
+
LAYOUT_CONFIG_FILE: string;
|
23
|
+
LAYOUT_LOADER_FILE: string;
|
24
|
+
LAYOUT_DATA_FILE: string;
|
25
|
+
LAYOUT_CLIENT_LOADER: string;
|
26
|
+
PAGE_FILE: string;
|
27
|
+
PAGE_CONFIG_FILE: string;
|
28
|
+
PAGE_LOADER_FILE: string;
|
29
|
+
PAGE_DATA_FILE: string;
|
30
|
+
PAGE_CLIENT_LOADER: string;
|
31
|
+
SPLATE_FILE: string;
|
32
|
+
SPLATE_CONFIG_FILE: string;
|
33
|
+
SPLATE_LOADER_FILE: string;
|
34
|
+
SPLATE_DATA_FILE: string;
|
35
|
+
SPLATE_CLIENT_DATA: string;
|
36
|
+
LOADING_FILE: string;
|
37
|
+
ERROR_FILE: string;
|
38
|
+
LOADER_FILE: string;
|
39
39
|
};
|
40
40
|
export declare const APP_CONFIG_NAME = "config";
|
41
41
|
export declare const APP_INIT_EXPORTED = "init";
|
42
|
-
export declare const APP_INIT_IMPORTED = "appInit";
|
42
|
+
export declare const APP_INIT_IMPORTED = "appInit";
|
@@ -4,20 +4,13 @@ import { BundlerConfig } from '@modern-js/builder-shared';
|
|
4
4
|
import { AppNormalizedConfig, AppTools, ImportStatement } from '../types';
|
5
5
|
export declare const createImportStatements: (statements: ImportStatement[]) => string;
|
6
6
|
export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<{
|
7
|
-
|
7
|
+
importsStatemets: Map<string, ImportStatement[]>;
|
8
8
|
}>;
|
9
|
-
export declare const generateIndexCode: ({
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
appContext: IAppContext;
|
18
|
-
api: PluginAPI<AppTools<'shared'>>;
|
19
|
-
entrypoints: Entrypoint[];
|
20
|
-
config: AppNormalizedConfig<'shared'>;
|
21
|
-
importsStatemets: Map<string, ImportStatement[]>;
|
22
|
-
bundlerConfigs?: BundlerConfig[] | undefined;
|
23
|
-
}) => Promise<void>;
|
9
|
+
export declare const generateIndexCode: ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, }: {
|
10
|
+
appContext: IAppContext;
|
11
|
+
api: PluginAPI<AppTools<'shared'>>;
|
12
|
+
entrypoints: Entrypoint[];
|
13
|
+
config: AppNormalizedConfig<'shared'>;
|
14
|
+
importsStatemets: Map<string, ImportStatement[]>;
|
15
|
+
bundlerConfigs?: BundlerConfig[] | undefined;
|
16
|
+
}) => Promise<void>;
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import type { Entrypoint } from '@modern-js/types';
|
2
2
|
import type { AppNormalizedConfig, IAppContext } from '../types';
|
3
|
-
export declare const getBundleEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
|
3
|
+
export declare const getBundleEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
|
@@ -1,14 +1,8 @@
|
|
1
1
|
import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
|
2
|
-
export declare const getClientRoutes: ({
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
}
|
9
|
-
entrypoint: Entrypoint;
|
10
|
-
srcDirectory: string;
|
11
|
-
srcAlias: string;
|
12
|
-
internalDirectory: string;
|
13
|
-
internalDirAlias: string;
|
14
|
-
}) => (NestedRouteForCli | PageRoute)[];
|
2
|
+
export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
|
3
|
+
entrypoint: Entrypoint;
|
4
|
+
srcDirectory: string;
|
5
|
+
srcAlias: string;
|
6
|
+
internalDirectory: string;
|
7
|
+
internalDirAlias: string;
|
8
|
+
}) => (NestedRouteForCli | PageRoute)[];
|
@@ -1,15 +1,9 @@
|
|
1
1
|
import type { Entrypoint, RouteLegacy } from '@modern-js/types';
|
2
2
|
export type { RouteLegacy as Route };
|
3
|
-
export declare const getClientRoutes: ({
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
entrypoint: Entrypoint;
|
11
|
-
srcDirectory: string;
|
12
|
-
srcAlias: string;
|
13
|
-
internalDirectory: string;
|
14
|
-
internalDirAlias: string;
|
15
|
-
}) => RouteLegacy[];
|
3
|
+
export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
|
4
|
+
entrypoint: Entrypoint;
|
5
|
+
srcDirectory: string;
|
6
|
+
srcAlias: string;
|
7
|
+
internalDirectory: string;
|
8
|
+
internalDirAlias: string;
|
9
|
+
}) => RouteLegacy[];
|
@@ -1,2 +1,2 @@
|
|
1
1
|
export { getClientRoutes } from './getRoutes';
|
2
|
-
export { getClientRoutes as getClientRoutesLegacy } from './getRoutesLegacy';
|
2
|
+
export { getClientRoutes as getClientRoutesLegacy } from './getRoutesLegacy';
|
@@ -2,4 +2,4 @@ declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
|
|
2
2
|
export { debug };
|
3
3
|
export declare const findLayout: (dir: string) => string | false;
|
4
4
|
export declare const getRouteWeight: (route: string) => number;
|
5
|
-
export declare const shouldSkip: (file: string) => boolean;
|
5
|
+
export declare const shouldSkip: (file: string) => boolean;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { Entrypoint } from '@modern-js/types';
|
2
2
|
import type { AppNormalizedConfig, IAppContext } from '../types';
|
3
3
|
export type { Entrypoint };
|
4
|
-
export declare const getFileSystemEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
|
4
|
+
export declare const getFileSystemEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
|