@modern-js/app-tools 2.0.0-beta.3 → 2.0.0-beta.6
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 +619 -0
- package/bin/modern.js +3 -0
- package/dist/js/modern/analyze/Builder.js +39 -0
- package/dist/js/modern/analyze/constants.js +48 -18
- package/dist/js/modern/analyze/generateCode.js +264 -225
- package/dist/js/modern/analyze/getBundleEntry.js +34 -32
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +99 -52
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
- package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
- package/dist/js/modern/analyze/getFileSystemEntry.js +52 -23
- package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
- package/dist/js/modern/analyze/getServerRoutes.js +122 -126
- package/dist/js/modern/analyze/index.js +204 -161
- package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
- package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
- package/dist/js/modern/analyze/nestedRoutes.js +118 -65
- package/dist/js/modern/analyze/templates.js +170 -81
- package/dist/js/modern/analyze/utils.js +104 -67
- package/dist/js/modern/builder/builderPlugins/compatModern.js +128 -109
- package/dist/js/modern/builder/index.js +120 -89
- package/dist/js/modern/builder/loaders/routerLoader.js +9 -12
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -1
- package/dist/js/modern/builder/share.js +23 -21
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +100 -84
- package/dist/js/modern/commands/build.js +67 -42
- package/dist/js/modern/commands/deploy.js +27 -4
- package/dist/js/modern/commands/dev.js +81 -34
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/inspect.js +30 -5
- package/dist/js/modern/commands/serve.js +54 -0
- package/dist/js/modern/config/default.js +112 -145
- package/dist/js/modern/config/index.js +8 -2
- package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
- package/dist/js/modern/config/initial/createOutputConfig.js +10 -13
- package/dist/js/modern/config/initial/createSourceConfig.js +10 -3
- package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
- package/dist/js/modern/config/initial/index.js +9 -4
- package/dist/js/modern/config/initial/inits.js +109 -73
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +11 -4
- package/dist/js/modern/defineConfig.js +26 -11
- package/dist/js/modern/exports/server.js +4 -1
- package/dist/js/modern/hooks.js +16 -4
- package/dist/js/modern/index.js +178 -90
- package/dist/js/modern/initialize/index.js +100 -52
- package/dist/js/modern/locale/en.js +20 -21
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +21 -22
- package/dist/js/modern/schema/Schema.js +6 -5
- package/dist/js/modern/schema/index.js +53 -100
- package/dist/js/modern/schema/legacy.js +96 -231
- package/dist/js/modern/types/config/index.js +0 -1
- package/dist/js/modern/types/index.js +0 -1
- package/dist/js/modern/types/legacyConfig/output.js +0 -1
- package/dist/js/modern/utils/commands.js +10 -2
- package/dist/js/modern/utils/config.js +102 -41
- package/dist/js/modern/utils/createFileWatcher.js +84 -51
- package/dist/js/modern/utils/createServer.js +63 -17
- package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
- package/dist/js/modern/utils/language.js +6 -3
- package/dist/js/modern/utils/printInstructions.js +27 -8
- package/dist/js/modern/utils/restart.js +43 -16
- package/dist/js/modern/utils/routes.js +29 -12
- package/dist/js/node/analyze/Builder.js +64 -0
- package/dist/js/node/analyze/constants.js +86 -39
- package/dist/js/node/analyze/generateCode.js +285 -239
- package/dist/js/node/analyze/getBundleEntry.js +62 -44
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +138 -77
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +130 -74
- package/dist/js/node/analyze/getClientRoutes/index.js +27 -16
- package/dist/js/node/analyze/getClientRoutes/utils.js +51 -21
- package/dist/js/node/analyze/getFileSystemEntry.js +82 -39
- package/dist/js/node/analyze/getHtmlTemplate.js +120 -61
- package/dist/js/node/analyze/getServerRoutes.js +145 -137
- package/dist/js/node/analyze/index.js +233 -174
- package/dist/js/node/analyze/isDefaultExportFunction.js +59 -26
- package/dist/js/node/analyze/makeLegalIdentifier.js +31 -15
- package/dist/js/node/analyze/nestedRoutes.js +150 -79
- package/dist/js/node/analyze/templates.js +198 -90
- package/dist/js/node/analyze/utils.js +136 -81
- package/dist/js/node/builder/builderPlugins/compatModern.js +158 -122
- package/dist/js/node/builder/index.js +142 -98
- package/dist/js/node/builder/loaders/routerLoader.js +29 -18
- package/dist/js/node/builder/loaders/serverModuleLoader.js +24 -7
- package/dist/js/node/builder/share.js +50 -26
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +43 -26
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +51 -31
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +120 -90
- package/dist/js/node/commands/build.js +91 -52
- package/dist/js/node/commands/deploy.js +49 -10
- package/dist/js/node/commands/dev.js +105 -48
- package/dist/js/node/commands/index.js +19 -38
- package/dist/js/node/commands/inspect.js +52 -11
- package/dist/js/node/commands/serve.js +83 -0
- package/dist/js/node/config/default.js +131 -149
- package/dist/js/node/config/index.js +31 -28
- package/dist/js/node/config/initial/createHtmlConfig.js +26 -6
- package/dist/js/node/config/initial/createOutputConfig.js +31 -17
- package/dist/js/node/config/initial/createSourceConfig.js +31 -7
- package/dist/js/node/config/initial/createToolsConfig.js +28 -10
- package/dist/js/node/config/initial/index.js +34 -17
- package/dist/js/node/config/initial/inits.js +130 -81
- package/dist/js/node/config/initial/transformNormalizedConfig.js +40 -16
- package/dist/js/node/defineConfig.js +46 -17
- package/dist/js/node/exports/server.js +25 -10
- package/dist/js/node/hooks.js +53 -29
- package/dist/js/node/index.js +213 -129
- package/dist/js/node/initialize/index.js +117 -61
- package/dist/js/node/locale/en.js +40 -25
- package/dist/js/node/locale/index.js +31 -14
- package/dist/js/node/locale/zh.js +41 -26
- package/dist/js/node/schema/Schema.js +27 -10
- package/dist/js/node/schema/index.js +84 -114
- package/dist/js/node/schema/legacy.js +119 -240
- 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 -16
- 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 -38
- 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 -5
- 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/commands.js +31 -6
- package/dist/js/node/utils/config.js +125 -51
- package/dist/js/node/utils/createFileWatcher.js +109 -61
- package/dist/js/node/utils/createServer.js +92 -25
- package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +68 -25
- package/dist/js/node/utils/language.js +28 -8
- package/dist/js/node/utils/printInstructions.js +51 -16
- package/dist/js/node/utils/restart.js +65 -21
- package/dist/js/node/utils/routes.js +58 -19
- package/dist/js/node/utils/types.js +15 -0
- package/dist/js/treeshaking/analyze/Builder.js +199 -0
- package/dist/js/treeshaking/analyze/constants.js +37 -18
- package/dist/js/treeshaking/analyze/generateCode.js +597 -407
- package/dist/js/treeshaking/analyze/getBundleEntry.js +55 -63
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +217 -168
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +97 -86
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
- package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -147
- package/dist/js/treeshaking/analyze/index.js +575 -305
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
- package/dist/js/treeshaking/analyze/nestedRoutes.js +419 -201
- package/dist/js/treeshaking/analyze/templates.js +438 -236
- package/dist/js/treeshaking/analyze/utils.js +367 -153
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +285 -199
- package/dist/js/treeshaking/builder/index.js +365 -165
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +11 -12
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +3 -2
- package/dist/js/treeshaking/builder/share.js +38 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +334 -112
- package/dist/js/treeshaking/commands/build.js +286 -88
- package/dist/js/treeshaking/commands/deploy.js +153 -25
- package/dist/js/treeshaking/commands/dev.js +313 -131
- package/dist/js/treeshaking/commands/index.js +1 -1
- package/dist/js/treeshaking/commands/inspect.js +147 -32
- package/dist/js/treeshaking/commands/serve.js +199 -0
- package/dist/js/treeshaking/config/default.js +207 -198
- package/dist/js/treeshaking/config/index.js +3 -2
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -70
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -40
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
- package/dist/js/treeshaking/config/initial/index.js +10 -9
- package/dist/js/treeshaking/config/initial/inits.js +205 -106
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +31 -34
- package/dist/js/treeshaking/defineConfig.js +60 -13
- package/dist/js/treeshaking/exports/server.js +2 -1
- package/dist/js/treeshaking/hooks.js +31 -25
- package/dist/js/treeshaking/index.js +681 -256
- package/dist/js/treeshaking/initialize/index.js +292 -113
- package/dist/js/treeshaking/locale/en.js +34 -33
- package/dist/js/treeshaking/locale/index.js +5 -5
- package/dist/js/treeshaking/locale/zh.js +34 -33
- package/dist/js/treeshaking/schema/Schema.js +267 -69
- package/dist/js/treeshaking/schema/index.js +171 -121
- package/dist/js/treeshaking/schema/legacy.js +323 -256
- 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 +0 -1
- 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 +0 -1
- 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 -1
- 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/commands.js +10 -5
- package/dist/js/treeshaking/utils/config.js +295 -117
- package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
- package/dist/js/treeshaking/utils/createServer.js +252 -67
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
- package/dist/js/treeshaking/utils/language.js +6 -5
- package/dist/js/treeshaking/utils/printInstructions.js +151 -29
- package/dist/js/treeshaking/utils/restart.js +184 -42
- package/dist/js/treeshaking/utils/routes.js +151 -27
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/dist/types/analyze/Builder.d.ts +8 -0
- package/dist/types/analyze/constants.d.ts +10 -1
- package/dist/types/analyze/index.d.ts +2 -0
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
- package/dist/types/builder/index.d.ts +3 -3
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
- package/dist/types/defineConfig.d.ts +1 -0
- package/dist/types/index.d.ts +7 -1
- package/dist/types/initialize/index.d.ts +2 -0
- package/dist/types/locale/en.d.ts +1 -1
- package/dist/types/locale/index.d.ts +2 -2
- package/dist/types/locale/zh.d.ts +1 -1
- package/dist/types/types/config/dev.d.ts +2 -2
- package/dist/types/types/config/index.d.ts +4 -0
- package/dist/types/types/config/output.d.ts +0 -1
- package/dist/types/types/config/source.d.ts +2 -0
- package/dist/types/types/config/tools.d.ts +2 -0
- package/dist/types/types/hooks.d.ts +8 -0
- package/dist/types/types/legacyConfig/dev.d.ts +1 -0
- package/dist/types/types/legacyConfig/output.d.ts +1 -1
- package/dist/types/types/legacyConfig/source.d.ts +1 -0
- package/dist/types/types/legacyConfig/tools.d.ts +1 -0
- package/dist/types/utils/commands.d.ts +2 -1
- package/dist/types/utils/config.d.ts +1 -0
- package/dist/types/utils/createServer.d.ts +1 -0
- package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
- package/dist/types/utils/restart.d.ts +1 -1
- package/package.json +26 -22
- package/dist/js/modern/commands/start.js +0 -30
- package/dist/js/node/commands/start.js +0 -38
- package/dist/js/treeshaking/commands/start.js +0 -69
|
@@ -1,20 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __async = (__this, __arguments, generator) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
var fulfilled = (value) => {
|
|
44
|
+
try {
|
|
45
|
+
step(generator.next(value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var rejected = (value) => {
|
|
51
|
+
try {
|
|
52
|
+
step(generator.throw(value));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
reject(e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
58
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var templates_exports = {};
|
|
62
|
+
__export(templates_exports, {
|
|
63
|
+
fileSystemRoutes: () => fileSystemRoutes,
|
|
64
|
+
html: () => html,
|
|
65
|
+
index: () => index,
|
|
66
|
+
renderFunction: () => renderFunction,
|
|
67
|
+
routesForServer: () => routesForServer
|
|
5
68
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
69
|
+
module.exports = __toCommonJS(templates_exports);
|
|
70
|
+
var import_path = __toESM(require("path"));
|
|
71
|
+
var import_utils = require("@modern-js/utils");
|
|
72
|
+
var import_constants = require("./constants");
|
|
14
73
|
const index = ({
|
|
15
74
|
mountId,
|
|
16
75
|
imports,
|
|
17
|
-
renderFunction,
|
|
76
|
+
renderFunction: renderFunction2,
|
|
18
77
|
exportStatement
|
|
19
78
|
}) => `
|
|
20
79
|
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
@@ -28,28 +87,25 @@ let AppWrapper = null;
|
|
|
28
87
|
let root = null;
|
|
29
88
|
|
|
30
89
|
function render() {
|
|
31
|
-
${
|
|
90
|
+
${renderFunction2}
|
|
32
91
|
}
|
|
33
92
|
|
|
34
93
|
AppWrapper = render();
|
|
35
94
|
|
|
36
95
|
${exportStatement};
|
|
37
96
|
`;
|
|
38
|
-
exports.index = index;
|
|
39
97
|
const renderFunction = ({
|
|
40
98
|
plugins,
|
|
41
99
|
customBootstrap,
|
|
42
|
-
fileSystemRoutes
|
|
100
|
+
fileSystemRoutes: fileSystemRoutes2
|
|
43
101
|
}) => `
|
|
44
102
|
AppWrapper = createApp({
|
|
45
103
|
plugins: [
|
|
46
|
-
${plugins.map(
|
|
47
|
-
name,
|
|
48
|
-
|
|
49
|
-
args
|
|
50
|
-
}) => `${name}({...${options}, ...App?.config?.${args || name}}),`).join('\n')}
|
|
104
|
+
${plugins.map(
|
|
105
|
+
({ name, options, args }) => `${name}({...${options}, ...App?.config?.${args || name}}),`
|
|
106
|
+
).join("\n")}
|
|
51
107
|
]
|
|
52
|
-
})(${
|
|
108
|
+
})(${fileSystemRoutes2 ? "" : `App`})
|
|
53
109
|
|
|
54
110
|
if (IS_BROWSER) {
|
|
55
111
|
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
|
|
@@ -57,20 +113,19 @@ const renderFunction = ({
|
|
|
57
113
|
|
|
58
114
|
return AppWrapper
|
|
59
115
|
`;
|
|
60
|
-
|
|
61
|
-
const html = partials => `
|
|
116
|
+
const html = (partials) => `
|
|
62
117
|
<!DOCTYPE html>
|
|
63
118
|
<html>
|
|
64
119
|
<head>
|
|
65
120
|
<%= meta %>
|
|
66
121
|
<title><%= title %></title>
|
|
67
122
|
|
|
68
|
-
${partials.top.join(
|
|
123
|
+
${partials.top.join("\n")}
|
|
69
124
|
|
|
70
125
|
<script>
|
|
71
126
|
window.__assetPrefix__ = '<%= assetPrefix %>';
|
|
72
|
-
|
|
73
|
-
${partials.head.join(
|
|
127
|
+
<\/script>
|
|
128
|
+
${partials.head.join("\n")}
|
|
74
129
|
|
|
75
130
|
<!--<?- chunksMap.css ?>-->
|
|
76
131
|
</head>
|
|
@@ -80,7 +135,7 @@ const html = partials => `
|
|
|
80
135
|
We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
|
|
81
136
|
</noscript>
|
|
82
137
|
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
|
83
|
-
${partials.body.join(
|
|
138
|
+
${partials.body.join("\n")}
|
|
84
139
|
<!--<?- chunksMap.js ?>-->
|
|
85
140
|
<!--<?- SSRDataScript ?>-->
|
|
86
141
|
<!--<?- bottomTemplate ?>-->
|
|
@@ -88,28 +143,32 @@ const html = partials => `
|
|
|
88
143
|
|
|
89
144
|
</html>
|
|
90
145
|
`;
|
|
91
|
-
exports.html = html;
|
|
92
146
|
const routesForServer = ({
|
|
93
147
|
routes,
|
|
94
148
|
internalDirectory,
|
|
95
149
|
entryName
|
|
96
150
|
}) => {
|
|
97
151
|
const loaders = [];
|
|
98
|
-
const loaderIndexFile =
|
|
99
|
-
|
|
152
|
+
const loaderIndexFile = import_path.default.join(
|
|
153
|
+
internalDirectory,
|
|
154
|
+
entryName,
|
|
155
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
156
|
+
"index.js"
|
|
157
|
+
);
|
|
158
|
+
const traverseRouteTree = (route) => {
|
|
159
|
+
var _a;
|
|
100
160
|
let children;
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
children = route === null || route === void 0 ? void 0 : (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.map(traverseRouteTree);
|
|
161
|
+
if ("children" in route && route.children) {
|
|
162
|
+
children = (_a = route == null ? void 0 : route.children) == null ? void 0 : _a.map(traverseRouteTree);
|
|
104
163
|
}
|
|
105
164
|
let loader;
|
|
106
|
-
if (route.type ===
|
|
165
|
+
if (route.type === "nested") {
|
|
107
166
|
if (route.loader) {
|
|
108
167
|
loaders.push(route.loader);
|
|
109
168
|
loader = `loader_${loaders.length - 1}`;
|
|
110
169
|
}
|
|
111
170
|
}
|
|
112
|
-
const finalRoute =
|
|
171
|
+
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
113
172
|
loader,
|
|
114
173
|
children
|
|
115
174
|
});
|
|
@@ -119,63 +178,82 @@ const routesForServer = ({
|
|
|
119
178
|
export const routes = [
|
|
120
179
|
`;
|
|
121
180
|
for (const route of routes) {
|
|
122
|
-
if (
|
|
181
|
+
if ("type" in route) {
|
|
123
182
|
const newRoute = traverseRouteTree(route);
|
|
124
|
-
routesCode += `${JSON.stringify(newRoute, null, 2).replace(
|
|
183
|
+
routesCode += `${JSON.stringify(newRoute, null, 2).replace(
|
|
184
|
+
/"(loader_[^"])"/g,
|
|
185
|
+
"$1"
|
|
186
|
+
)},`;
|
|
125
187
|
} else {
|
|
126
188
|
routesCode += `${JSON.stringify(route, null, 2)}`;
|
|
127
189
|
}
|
|
128
190
|
}
|
|
129
|
-
routesCode +=
|
|
130
|
-
|
|
191
|
+
routesCode += `
|
|
192
|
+
];`;
|
|
193
|
+
let importLoadersCode = "";
|
|
131
194
|
if (loaders.length > 0) {
|
|
132
195
|
importLoadersCode = `
|
|
133
|
-
import { ${loaders.map(
|
|
196
|
+
import { ${loaders.map(
|
|
197
|
+
(loader, index2) => `loader_${index2}`
|
|
198
|
+
)} } from "${(0, import_utils.slash)(loaderIndexFile)}"`;
|
|
134
199
|
}
|
|
135
200
|
return `
|
|
136
201
|
${importLoadersCode}
|
|
137
202
|
${routesCode}
|
|
138
203
|
`;
|
|
139
204
|
};
|
|
140
|
-
|
|
141
|
-
const fileSystemRoutes = async ({
|
|
205
|
+
const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
142
206
|
routes,
|
|
143
207
|
ssrMode,
|
|
144
208
|
nestedRoutesEntry,
|
|
145
209
|
entryName,
|
|
146
|
-
internalDirectory
|
|
147
|
-
|
|
210
|
+
internalDirectory,
|
|
211
|
+
internalDirAlias
|
|
212
|
+
}) {
|
|
148
213
|
const loadings = [];
|
|
149
214
|
const errors = [];
|
|
150
215
|
const loaders = [];
|
|
151
216
|
const loadersMap = {};
|
|
152
|
-
const loadersIndexFile =
|
|
153
|
-
|
|
217
|
+
const loadersIndexFile = import_path.default.join(
|
|
218
|
+
internalDirAlias,
|
|
219
|
+
entryName,
|
|
220
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
221
|
+
"index.js"
|
|
222
|
+
);
|
|
223
|
+
const loadersMapFile = import_path.default.join(
|
|
224
|
+
internalDirectory,
|
|
225
|
+
entryName,
|
|
226
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
227
|
+
"map.json"
|
|
228
|
+
);
|
|
154
229
|
const importLazyCode = `
|
|
155
230
|
import { lazy } from "react";
|
|
156
231
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
157
232
|
`;
|
|
158
233
|
let rootLayoutCode = ``;
|
|
159
|
-
let dataLoaderPath =
|
|
160
|
-
let componentLoaderPath =
|
|
234
|
+
let dataLoaderPath = "";
|
|
235
|
+
let componentLoaderPath = "";
|
|
161
236
|
if (ssrMode) {
|
|
162
|
-
dataLoaderPath = require.resolve(
|
|
237
|
+
dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
163
238
|
if (nestedRoutesEntry) {
|
|
164
239
|
dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&mapFile=${loadersMapFile}!`;
|
|
165
240
|
}
|
|
166
|
-
componentLoaderPath = `${
|
|
241
|
+
componentLoaderPath = `${import_path.default.join(
|
|
242
|
+
__dirname,
|
|
243
|
+
"../builder/loaders/routerLoader"
|
|
244
|
+
)}!`;
|
|
167
245
|
}
|
|
168
|
-
const traverseRouteTree = route => {
|
|
246
|
+
const traverseRouteTree = (route) => {
|
|
247
|
+
var _a;
|
|
169
248
|
let children;
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
children = route === null || route === void 0 ? void 0 : (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.map(traverseRouteTree);
|
|
249
|
+
if ("children" in route && route.children) {
|
|
250
|
+
children = (_a = route == null ? void 0 : route.children) == null ? void 0 : _a.map(traverseRouteTree);
|
|
173
251
|
}
|
|
174
252
|
let loading;
|
|
175
253
|
let error;
|
|
176
254
|
let loader;
|
|
177
|
-
let component =
|
|
178
|
-
if (route.type ===
|
|
255
|
+
let component = "";
|
|
256
|
+
if (route.type === "nested") {
|
|
179
257
|
if (route.loading) {
|
|
180
258
|
loadings.push(route.loading);
|
|
181
259
|
loading = `loading_${loadings.length - 1}`;
|
|
@@ -194,17 +272,16 @@ const fileSystemRoutes = async ({
|
|
|
194
272
|
if (route.isRoot) {
|
|
195
273
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
196
274
|
component = `RootLayout`;
|
|
197
|
-
} else if (ssrMode ===
|
|
275
|
+
} else if (ssrMode === "string") {
|
|
198
276
|
component = `loadable(() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}'))`;
|
|
199
277
|
} else {
|
|
200
|
-
// csr and streaming
|
|
201
278
|
component = `lazy(() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}'))`;
|
|
202
279
|
}
|
|
203
280
|
}
|
|
204
281
|
} else if (route._component) {
|
|
205
282
|
component = `loadable(() => import('${route._component}'))`;
|
|
206
283
|
}
|
|
207
|
-
const finalRoute =
|
|
284
|
+
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
208
285
|
loading,
|
|
209
286
|
loader,
|
|
210
287
|
error,
|
|
@@ -219,45 +296,69 @@ const fileSystemRoutes = async ({
|
|
|
219
296
|
export const routes = [
|
|
220
297
|
`;
|
|
221
298
|
for (const route of routes) {
|
|
222
|
-
if (
|
|
299
|
+
if ("type" in route) {
|
|
223
300
|
const newRoute = traverseRouteTree(route);
|
|
224
|
-
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g,
|
|
301
|
+
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(lazy.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
225
302
|
} else {
|
|
226
303
|
const component = `loadable(() => import('${route._component}'))`;
|
|
227
|
-
const finalRoute =
|
|
304
|
+
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
228
305
|
component
|
|
229
306
|
});
|
|
230
|
-
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g,
|
|
307
|
+
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
|
|
231
308
|
}
|
|
232
309
|
}
|
|
233
|
-
routeComponentsCode +=
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
310
|
+
routeComponentsCode += `
|
|
311
|
+
];`;
|
|
312
|
+
const importLoadingCode = loadings.map((loading, index2) => {
|
|
313
|
+
return `import loading_${index2} from '${loading}';
|
|
314
|
+
`;
|
|
315
|
+
}).join("");
|
|
316
|
+
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
317
|
+
return `import error_${index2} from '${error}';
|
|
318
|
+
`;
|
|
319
|
+
}).join("");
|
|
320
|
+
let importLoadersCode = "";
|
|
241
321
|
if (loaders.length > 0) {
|
|
242
322
|
importLoadersCode = `
|
|
243
|
-
import { ${loaders.map(
|
|
323
|
+
import { ${loaders.map(
|
|
324
|
+
(loader, index2) => `loader_${index2}`
|
|
325
|
+
)} } from "${(0, import_utils.slash)(dataLoaderPath)}${(0, import_utils.slash)(loadersIndexFile)}"
|
|
244
326
|
`;
|
|
245
|
-
const loaderEntryCode = loaders.map((loader,
|
|
246
|
-
return `export * from './loader_${
|
|
247
|
-
}).join(
|
|
248
|
-
const loaderEntryFile =
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
327
|
+
const loaderEntryCode = loaders.map((loader, index2) => {
|
|
328
|
+
return `export * from './loader_${index2}.js';`;
|
|
329
|
+
}).join("\n");
|
|
330
|
+
const loaderEntryFile = import_path.default.join(
|
|
331
|
+
internalDirectory,
|
|
332
|
+
entryName,
|
|
333
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
334
|
+
"entry.js"
|
|
335
|
+
);
|
|
336
|
+
yield import_utils.fs.ensureFile(loaderEntryFile);
|
|
337
|
+
yield import_utils.fs.writeFile(loaderEntryFile, loaderEntryCode);
|
|
338
|
+
yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
|
339
|
+
yield Promise.all(
|
|
340
|
+
loaders.map((loader, index2) => __async(void 0, null, function* () {
|
|
341
|
+
const name = `loader_${index2}`;
|
|
342
|
+
const filename = import_path.default.join(
|
|
343
|
+
internalDirectory,
|
|
344
|
+
entryName,
|
|
345
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
346
|
+
`${name}.js`
|
|
347
|
+
);
|
|
348
|
+
let code = "";
|
|
349
|
+
if (loader.includes(".loader.")) {
|
|
350
|
+
code = `
|
|
351
|
+
export { default as ${name} } from '${(0, import_utils.slash)(loader)}'
|
|
352
|
+
`;
|
|
353
|
+
} else {
|
|
354
|
+
code = `
|
|
355
|
+
export { loader as ${name} } from '${(0, import_utils.slash)(loader)}'
|
|
257
356
|
`;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
357
|
+
}
|
|
358
|
+
yield import_utils.fs.ensureFile(filename);
|
|
359
|
+
yield import_utils.fs.writeFile(filename, code);
|
|
360
|
+
}))
|
|
361
|
+
);
|
|
261
362
|
}
|
|
262
363
|
return `
|
|
263
364
|
${importLazyCode}
|
|
@@ -267,5 +368,12 @@ const fileSystemRoutes = async ({
|
|
|
267
368
|
${importLoadersCode}
|
|
268
369
|
${routeComponentsCode}
|
|
269
370
|
`;
|
|
270
|
-
};
|
|
271
|
-
|
|
371
|
+
});
|
|
372
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
373
|
+
0 && (module.exports = {
|
|
374
|
+
fileSystemRoutes,
|
|
375
|
+
html,
|
|
376
|
+
index,
|
|
377
|
+
renderFunction,
|
|
378
|
+
routesForServer
|
|
379
|
+
});
|