@modern-js/app-tools 2.5.1-alpha.0 → 2.5.1-alpha.1
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 +19 -13
- package/dist/cjs/analyze/getBundleEntry.js +1 -1
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +3 -3
- package/dist/cjs/builder/builder-webpack/index.js +11 -5
- package/dist/cjs/builder/generator/getBuilderTargets.js +1 -1
- package/dist/cjs/commands/dev.js +12 -14
- package/dist/cjs/commands/serve.js +17 -0
- package/dist/cjs/config/legacy/createToolsConfig.js +1 -4
- package/dist/esm/analyze/generateCode.js +37 -26
- package/dist/esm/analyze/getBundleEntry.js +2 -2
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm/builder/builder-webpack/index.js +11 -7
- package/dist/esm/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm/commands/dev.js +9 -8
- package/dist/esm/commands/serve.js +6 -1
- package/dist/esm/config/legacy/createToolsConfig.js +1 -4
- package/dist/esm-node/analyze/generateCode.js +20 -14
- package/dist/esm-node/analyze/getBundleEntry.js +2 -3
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm-node/builder/builder-webpack/index.js +12 -6
- package/dist/esm-node/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm-node/commands/dev.js +12 -14
- package/dist/esm-node/commands/serve.js +18 -1
- package/dist/esm-node/config/legacy/createToolsConfig.js +1 -4
- package/dist/js/modern/analyze/constants.js +3 -1
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +47 -46
- package/dist/js/modern/analyze/nestedRoutes.js +32 -3
- package/dist/js/modern/analyze/templates.js +4 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +48 -47
- package/dist/js/node/analyze/nestedRoutes.js +32 -3
- package/dist/js/node/analyze/templates.js +4 -10
- package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
- package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +3 -1
- package/dist/js/treeshaking/analyze/generateCode.js +14 -14
- package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
- package/dist/js/treeshaking/analyze/index.js +142 -137
- package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -13
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +36 -28
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/builder/builder-webpack/builderPlugins/compatModern.d.ts +7 -1
- package/package.json +6 -6
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
|
@@ -83,6 +83,7 @@ ${initialize || ""}`
|
|
|
83
83
|
).join("\n");
|
|
84
84
|
};
|
|
85
85
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
86
|
+
var _a, _b, _c;
|
|
86
87
|
const {
|
|
87
88
|
internalDirectory,
|
|
88
89
|
srcDirectory,
|
|
@@ -91,7 +92,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
91
92
|
packageName
|
|
92
93
|
} = appContext;
|
|
93
94
|
const hookRunners = api.useHookRunners();
|
|
94
|
-
const isV5 = (0
|
|
95
|
+
const isV5 = typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
|
|
95
96
|
const { mountId } = config.html;
|
|
96
97
|
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
|
97
98
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
@@ -110,18 +111,23 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
110
111
|
internalDirAlias
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
if (entrypoint.nestedRoutesEntry) {
|
|
115
|
+
if (!isV5) {
|
|
116
|
+
nestedRoute = await (0, import_nestedRoutes.walk)(
|
|
117
|
+
entrypoint.nestedRoutesEntry,
|
|
118
|
+
entrypoint.nestedRoutesEntry,
|
|
119
|
+
{
|
|
120
|
+
name: internalSrcAlias,
|
|
121
|
+
basename: srcDirectory
|
|
122
|
+
},
|
|
123
|
+
entrypoint.entryName
|
|
124
|
+
);
|
|
125
|
+
if (nestedRoute) {
|
|
126
|
+
initialRoutes.unshift(nestedRoute);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
import_utils.logger.error("Nested routes is not supported in legacy mode.");
|
|
130
|
+
process.exit(1);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
@@ -78,7 +78,7 @@ const getBundleEntry = (appContext, config) => {
|
|
|
78
78
|
customBootstrap: value.customBootstrap && (0, import_utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
|
|
79
79
|
fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
80
80
|
};
|
|
81
|
-
if (entrypoint.fileSystemRoutes
|
|
81
|
+
if (entrypoint.fileSystemRoutes) {
|
|
82
82
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
83
83
|
}
|
|
84
84
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -17,13 +17,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var compatModern_exports = {};
|
|
19
19
|
__export(compatModern_exports, {
|
|
20
|
-
|
|
20
|
+
PluginCompatModern: () => PluginCompatModern
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(compatModern_exports);
|
|
23
23
|
var import_path = require("path");
|
|
24
24
|
var import_shared = require("../../shared");
|
|
25
25
|
var import_webpackPlugins = require("../webpackPlugins");
|
|
26
|
-
const
|
|
26
|
+
const PluginCompatModern = (options) => ({
|
|
27
27
|
name: "builder-plugin-compat-modern",
|
|
28
28
|
setup(api) {
|
|
29
29
|
const { normalizedConfig: modernConfig, appContext } = options;
|
|
@@ -60,5 +60,5 @@ const builderPluginCompatModern = (options) => ({
|
|
|
60
60
|
});
|
|
61
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
62
|
0 && (module.exports = {
|
|
63
|
-
|
|
63
|
+
PluginCompatModern
|
|
64
64
|
});
|
|
@@ -27,6 +27,7 @@ __export(builder_webpack_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(builder_webpack_exports);
|
|
29
29
|
var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
30
31
|
var import_shared = require("../shared");
|
|
31
32
|
var import_generator = require("../generator");
|
|
32
33
|
var import_compatModern = require("./builderPlugins/compatModern");
|
|
@@ -56,15 +57,20 @@ function modifyOutputConfig(config, appContext) {
|
|
|
56
57
|
async function applyBuilderPlugins(builder, options) {
|
|
57
58
|
const { normalizedConfig } = options;
|
|
58
59
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
59
|
-
const {
|
|
60
|
-
builder.addPlugins([
|
|
60
|
+
const { PluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
|
|
61
|
+
builder.addPlugins([PluginNodePolyfill()]);
|
|
61
62
|
}
|
|
62
63
|
if (normalizedConfig.tools.esbuild) {
|
|
63
64
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
64
|
-
const {
|
|
65
|
-
builder.addPlugins([
|
|
65
|
+
const { PluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
|
|
66
|
+
builder.addPlugins([
|
|
67
|
+
PluginEsbuild({
|
|
68
|
+
loader: false,
|
|
69
|
+
minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
|
|
70
|
+
})
|
|
71
|
+
]);
|
|
66
72
|
}
|
|
67
|
-
builder.addPlugins([(0, import_compatModern.
|
|
73
|
+
builder.addPlugins([(0, import_compatModern.PluginCompatModern)(options)]);
|
|
68
74
|
}
|
|
69
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
76
|
0 && (module.exports = {
|
|
@@ -27,7 +27,7 @@ function getBuilderTargets(normalizedConfig) {
|
|
|
27
27
|
if (useNodeTarget) {
|
|
28
28
|
targets.push("node");
|
|
29
29
|
}
|
|
30
|
-
const useWorkerTarget = (0, import_utils.isServiceWorker)(normalizedConfig);
|
|
30
|
+
const useWorkerTarget = (0, import_utils.isProd)() ? (0, import_utils.isServiceWorker)(normalizedConfig) : false;
|
|
31
31
|
if (useWorkerTarget) {
|
|
32
32
|
targets.push("service-worker");
|
|
33
33
|
}
|
package/dist/cjs/commands/dev.js
CHANGED
|
@@ -27,7 +27,7 @@ var import_routes = require("../utils/routes");
|
|
|
27
27
|
var import_config = require("../utils/config");
|
|
28
28
|
var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
29
29
|
const dev = async (api, options) => {
|
|
30
|
-
var _a
|
|
30
|
+
var _a;
|
|
31
31
|
if (options.analyze) {
|
|
32
32
|
process.env.BUNDLE_ANALYZE = "true";
|
|
33
33
|
}
|
|
@@ -59,9 +59,14 @@ const dev = async (api, options) => {
|
|
|
59
59
|
dev: {
|
|
60
60
|
port,
|
|
61
61
|
https: normalizedConfig.dev.https,
|
|
62
|
-
host: normalizedConfig.dev.host,
|
|
63
62
|
...(_a = normalizedConfig.tools) == null ? void 0 : _a.devServer
|
|
64
63
|
},
|
|
64
|
+
appContext: {
|
|
65
|
+
appDirectory: appContext.appDirectory,
|
|
66
|
+
sharedDirectory: appContext.sharedDirectory,
|
|
67
|
+
apiDirectory: appContext.apiDirectory,
|
|
68
|
+
lambdaDirectory: appContext.lambdaDirectory
|
|
69
|
+
},
|
|
65
70
|
pwd: appDirectory,
|
|
66
71
|
config: normalizedConfig,
|
|
67
72
|
serverConfigFile,
|
|
@@ -72,19 +77,12 @@ const dev = async (api, options) => {
|
|
|
72
77
|
...serverOptions,
|
|
73
78
|
compiler: null
|
|
74
79
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
port,
|
|
79
|
-
host
|
|
80
|
-
},
|
|
81
|
-
async (err) => {
|
|
82
|
-
if (err) {
|
|
83
|
-
throw err;
|
|
84
|
-
}
|
|
85
|
-
(0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
|
|
80
|
+
app.listen(port, async (err) => {
|
|
81
|
+
if (err) {
|
|
82
|
+
throw err;
|
|
86
83
|
}
|
|
87
|
-
|
|
84
|
+
(0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
|
|
85
|
+
});
|
|
88
86
|
} else {
|
|
89
87
|
const { server } = await appContext.builder.startDevServer({
|
|
90
88
|
printURLs: false,
|
|
@@ -46,6 +46,23 @@ const start = async (api) => {
|
|
|
46
46
|
const app = await (0, import_prod_server.default)({
|
|
47
47
|
pwd: appDirectory,
|
|
48
48
|
config: userConfig,
|
|
49
|
+
appContext: {
|
|
50
|
+
sharedDirectory: (0, import_utils.getTargetDir)(
|
|
51
|
+
appContext.sharedDirectory,
|
|
52
|
+
appContext.appDirectory,
|
|
53
|
+
appContext.distDirectory
|
|
54
|
+
),
|
|
55
|
+
apiDirectory: (0, import_utils.getTargetDir)(
|
|
56
|
+
appContext.apiDirectory,
|
|
57
|
+
appContext.appDirectory,
|
|
58
|
+
appContext.distDirectory
|
|
59
|
+
),
|
|
60
|
+
lambdaDirectory: (0, import_utils.getTargetDir)(
|
|
61
|
+
appContext.lambdaDirectory,
|
|
62
|
+
appContext.appDirectory,
|
|
63
|
+
appContext.distDirectory
|
|
64
|
+
)
|
|
65
|
+
},
|
|
49
66
|
serverConfigFile,
|
|
50
67
|
internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
|
|
51
68
|
apiOnly
|
|
@@ -148,7 +148,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
import path from "path";
|
|
151
|
-
import { fs, getEntryOptions,
|
|
151
|
+
import { fs, getEntryOptions, logger } from "@modern-js/utils";
|
|
152
152
|
import { useResolvedConfigContext } from "@modern-js/core";
|
|
153
153
|
import * as templates from "./templates";
|
|
154
154
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
@@ -240,7 +240,7 @@ var createImportStatements = function(statements) {
|
|
|
240
240
|
};
|
|
241
241
|
var generateCode = function() {
|
|
242
242
|
var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
|
|
243
|
-
var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
|
|
243
|
+
var _config_runtime, _config_runtime1, _config_runtime_router, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
|
|
244
244
|
function generateEntryCode(entrypoint) {
|
|
245
245
|
return _generateEntryCode.apply(this, arguments);
|
|
246
246
|
}
|
|
@@ -253,11 +253,11 @@ var generateCode = function() {
|
|
|
253
253
|
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
254
254
|
if (!isAutoMount) return [
|
|
255
255
|
3,
|
|
256
|
-
|
|
256
|
+
17
|
|
257
257
|
];
|
|
258
258
|
if (!fileSystemRoutes) return [
|
|
259
259
|
3,
|
|
260
|
-
|
|
260
|
+
10
|
|
261
261
|
];
|
|
262
262
|
initialRoutes = [];
|
|
263
263
|
nestedRoute = null;
|
|
@@ -270,7 +270,11 @@ var generateCode = function() {
|
|
|
270
270
|
internalDirAlias: internalDirAlias
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
|
-
if (!
|
|
273
|
+
if (!entrypoint.nestedRoutesEntry) return [
|
|
274
|
+
3,
|
|
275
|
+
3
|
|
276
|
+
];
|
|
277
|
+
if (!!isV5) return [
|
|
274
278
|
3,
|
|
275
279
|
2
|
|
276
280
|
];
|
|
@@ -286,8 +290,15 @@ var generateCode = function() {
|
|
|
286
290
|
if (nestedRoute) {
|
|
287
291
|
initialRoutes.unshift(nestedRoute);
|
|
288
292
|
}
|
|
289
|
-
|
|
293
|
+
return [
|
|
294
|
+
3,
|
|
295
|
+
3
|
|
296
|
+
];
|
|
290
297
|
case 2:
|
|
298
|
+
logger.error("Nested routes is not supported in legacy mode.");
|
|
299
|
+
process.exit(1);
|
|
300
|
+
_state.label = 3;
|
|
301
|
+
case 3:
|
|
291
302
|
return [
|
|
292
303
|
4,
|
|
293
304
|
hookRunners.modifyFileSystemRoutes({
|
|
@@ -295,7 +306,7 @@ var generateCode = function() {
|
|
|
295
306
|
routes: initialRoutes
|
|
296
307
|
})
|
|
297
308
|
];
|
|
298
|
-
case
|
|
309
|
+
case 4:
|
|
299
310
|
routes = _state.sent().routes;
|
|
300
311
|
config2 = useResolvedConfigContext();
|
|
301
312
|
ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
@@ -327,18 +338,18 @@ var generateCode = function() {
|
|
|
327
338
|
internalDirectory: internalDirectory
|
|
328
339
|
})
|
|
329
340
|
];
|
|
330
|
-
case
|
|
341
|
+
case 5:
|
|
331
342
|
return [
|
|
332
343
|
4,
|
|
333
344
|
_.apply(hookRunners, [
|
|
334
345
|
(_tmp.code = _state.sent(), _tmp)
|
|
335
346
|
])
|
|
336
347
|
];
|
|
337
|
-
case
|
|
348
|
+
case 6:
|
|
338
349
|
_ref = _state.sent(), code2 = _ref.code;
|
|
339
350
|
if (!(entrypoint.nestedRoutesEntry && mode)) return [
|
|
340
351
|
3,
|
|
341
|
-
|
|
352
|
+
9
|
|
342
353
|
];
|
|
343
354
|
routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
344
355
|
code3 = templates.routesForServer({
|
|
@@ -348,19 +359,19 @@ var generateCode = function() {
|
|
|
348
359
|
4,
|
|
349
360
|
fs.ensureFile(routesServerFile)
|
|
350
361
|
];
|
|
351
|
-
case
|
|
362
|
+
case 7:
|
|
352
363
|
_state.sent();
|
|
353
364
|
return [
|
|
354
365
|
4,
|
|
355
366
|
fs.writeFile(routesServerFile, code3)
|
|
356
367
|
];
|
|
357
|
-
case 7:
|
|
358
|
-
_state.sent();
|
|
359
|
-
_state.label = 8;
|
|
360
368
|
case 8:
|
|
361
|
-
|
|
369
|
+
_state.sent();
|
|
362
370
|
_state.label = 9;
|
|
363
371
|
case 9:
|
|
372
|
+
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
|
|
373
|
+
_state.label = 10;
|
|
374
|
+
case 10:
|
|
364
375
|
return [
|
|
365
376
|
4,
|
|
366
377
|
hookRunners.modifyEntryImports({
|
|
@@ -374,7 +385,7 @@ var generateCode = function() {
|
|
|
374
385
|
})
|
|
375
386
|
})
|
|
376
387
|
];
|
|
377
|
-
case
|
|
388
|
+
case 11:
|
|
378
389
|
_ref1 = _state.sent(), importStatements = _ref1.imports;
|
|
379
390
|
return [
|
|
380
391
|
4,
|
|
@@ -383,7 +394,7 @@ var generateCode = function() {
|
|
|
383
394
|
plugins: []
|
|
384
395
|
})
|
|
385
396
|
];
|
|
386
|
-
case
|
|
397
|
+
case 12:
|
|
387
398
|
plugins = _state.sent().plugins;
|
|
388
399
|
return [
|
|
389
400
|
4,
|
|
@@ -396,7 +407,7 @@ var generateCode = function() {
|
|
|
396
407
|
})
|
|
397
408
|
})
|
|
398
409
|
];
|
|
399
|
-
case
|
|
410
|
+
case 13:
|
|
400
411
|
_ref2 = _state.sent(), renderFunction = _ref2.code;
|
|
401
412
|
return [
|
|
402
413
|
4,
|
|
@@ -405,7 +416,7 @@ var generateCode = function() {
|
|
|
405
416
|
exportStatement: "export default AppWrapper;"
|
|
406
417
|
})
|
|
407
418
|
];
|
|
408
|
-
case
|
|
419
|
+
case 14:
|
|
409
420
|
exportStatement = _state.sent().exportStatement;
|
|
410
421
|
code = templates.index({
|
|
411
422
|
mountId: mountId,
|
|
@@ -417,7 +428,7 @@ var generateCode = function() {
|
|
|
417
428
|
entrypoint.entry = entryFile;
|
|
418
429
|
if (!config.source.enableAsyncEntry) return [
|
|
419
430
|
3,
|
|
420
|
-
|
|
431
|
+
16
|
|
421
432
|
];
|
|
422
433
|
return [
|
|
423
434
|
4,
|
|
@@ -426,19 +437,19 @@ var generateCode = function() {
|
|
|
426
437
|
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
427
438
|
})
|
|
428
439
|
];
|
|
429
|
-
case
|
|
440
|
+
case 15:
|
|
430
441
|
_ref3 = _state.sent(), asyncEntryCode = _ref3.code;
|
|
431
442
|
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
432
443
|
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
433
444
|
fs.outputFileSync(bootstrapFile, code, "utf8");
|
|
434
445
|
return [
|
|
435
446
|
3,
|
|
436
|
-
|
|
447
|
+
17
|
|
437
448
|
];
|
|
438
|
-
case 15:
|
|
439
|
-
fs.outputFileSync(entryFile, code, "utf8");
|
|
440
|
-
_state.label = 16;
|
|
441
449
|
case 16:
|
|
450
|
+
fs.outputFileSync(entryFile, code, "utf8");
|
|
451
|
+
_state.label = 17;
|
|
452
|
+
case 17:
|
|
442
453
|
return [
|
|
443
454
|
2
|
|
444
455
|
];
|
|
@@ -452,7 +463,7 @@ var generateCode = function() {
|
|
|
452
463
|
case 0:
|
|
453
464
|
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
|
454
465
|
hookRunners = api.useHookRunners();
|
|
455
|
-
isV5 =
|
|
466
|
+
isV5 = typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
|
|
456
467
|
mountId = config.html.mountId;
|
|
457
468
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
458
469
|
return [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME
|
|
2
|
+
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME } from "@modern-js/utils";
|
|
3
3
|
import { getFileSystemEntry } from "./getFileSystemEntry";
|
|
4
4
|
import { JS_EXTENSIONS } from "./constants";
|
|
5
5
|
var ensureExtensions = function(file) {
|
|
@@ -43,7 +43,7 @@ var getBundleEntry = function(appContext, config) {
|
|
|
43
43
|
customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
|
44
44
|
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
45
45
|
};
|
|
46
|
-
if (entrypoint.fileSystemRoutes
|
|
46
|
+
if (entrypoint.fileSystemRoutes) {
|
|
47
47
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
48
48
|
}
|
|
49
49
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -26,7 +26,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
26
26
|
import { join } from "path";
|
|
27
27
|
import { createCopyPattern } from "../../shared";
|
|
28
28
|
import { RouterPlugin } from "../webpackPlugins";
|
|
29
|
-
var
|
|
29
|
+
var PluginCompatModern = function(options) {
|
|
30
30
|
return {
|
|
31
31
|
name: "builder-plugin-compat-modern",
|
|
32
32
|
setup: function setup(api) {
|
|
@@ -61,4 +61,4 @@ var builderPluginCompatModern = function(options) {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
export {
|
|
64
|
+
export { PluginCompatModern };
|
|
@@ -200,9 +200,10 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
import { builderWebpackProvider } from "@modern-js/builder-webpack-provider";
|
|
203
|
+
import { applyOptionsChain } from "@modern-js/utils";
|
|
203
204
|
import { createCopyPattern } from "../shared";
|
|
204
205
|
import { generateBuilder } from "../generator";
|
|
205
|
-
import {
|
|
206
|
+
import { PluginCompatModern } from "./builderPlugins/compatModern";
|
|
206
207
|
function createWebpackBuilderForModern(options) {
|
|
207
208
|
return generateBuilder(options, builderWebpackProvider, {
|
|
208
209
|
modifyBuilderConfig: function modifyBuilderConfig(config) {
|
|
@@ -247,7 +248,7 @@ function applyBuilderPlugins(builder, options) {
|
|
|
247
248
|
}
|
|
248
249
|
function _applyBuilderPlugins() {
|
|
249
250
|
_applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
|
|
250
|
-
var normalizedConfig,
|
|
251
|
+
var normalizedConfig, PluginNodePolyfill, _normalizedConfig_tools, esbuildOptions, PluginEsbuild;
|
|
251
252
|
return __generator(this, function(_state) {
|
|
252
253
|
switch(_state.label){
|
|
253
254
|
case 0:
|
|
@@ -261,9 +262,9 @@ function _applyBuilderPlugins() {
|
|
|
261
262
|
import("@modern-js/builder-plugin-node-polyfill")
|
|
262
263
|
];
|
|
263
264
|
case 1:
|
|
264
|
-
|
|
265
|
+
PluginNodePolyfill = _state.sent().PluginNodePolyfill;
|
|
265
266
|
builder.addPlugins([
|
|
266
|
-
|
|
267
|
+
PluginNodePolyfill()
|
|
267
268
|
]);
|
|
268
269
|
_state.label = 2;
|
|
269
270
|
case 2:
|
|
@@ -277,14 +278,17 @@ function _applyBuilderPlugins() {
|
|
|
277
278
|
import("@modern-js/builder-plugin-esbuild")
|
|
278
279
|
];
|
|
279
280
|
case 3:
|
|
280
|
-
|
|
281
|
+
PluginEsbuild = _state.sent().PluginEsbuild;
|
|
281
282
|
builder.addPlugins([
|
|
282
|
-
|
|
283
|
+
PluginEsbuild({
|
|
284
|
+
loader: false,
|
|
285
|
+
minimize: applyOptionsChain({}, esbuildOptions)
|
|
286
|
+
})
|
|
283
287
|
]);
|
|
284
288
|
_state.label = 4;
|
|
285
289
|
case 4:
|
|
286
290
|
builder.addPlugins([
|
|
287
|
-
|
|
291
|
+
PluginCompatModern(options)
|
|
288
292
|
]);
|
|
289
293
|
return [
|
|
290
294
|
2
|
|
@@ -7,7 +7,7 @@ function getBuilderTargets(normalizedConfig) {
|
|
|
7
7
|
if (useNodeTarget) {
|
|
8
8
|
targets.push("node");
|
|
9
9
|
}
|
|
10
|
-
var useWorkerTarget = isServiceWorker(normalizedConfig);
|
|
10
|
+
var useWorkerTarget = isProd() ? isServiceWorker(normalizedConfig) : false;
|
|
11
11
|
if (useWorkerTarget) {
|
|
12
12
|
targets.push("service-worker");
|
|
13
13
|
}
|
package/dist/esm/commands/dev.js
CHANGED
|
@@ -182,7 +182,7 @@ import { buildServerConfig } from "../utils/config";
|
|
|
182
182
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
183
183
|
var dev = function() {
|
|
184
184
|
var _ref = _asyncToGenerator(function(api, options) {
|
|
185
|
-
var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions,
|
|
185
|
+
var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, app, server;
|
|
186
186
|
return __generator(this, function(_state) {
|
|
187
187
|
switch(_state.label){
|
|
188
188
|
case 0:
|
|
@@ -236,9 +236,14 @@ var dev = function() {
|
|
|
236
236
|
serverOptions = {
|
|
237
237
|
dev: _objectSpread({
|
|
238
238
|
port: port,
|
|
239
|
-
https: normalizedConfig.dev.https
|
|
240
|
-
host: normalizedConfig.dev.host
|
|
239
|
+
https: normalizedConfig.dev.https
|
|
241
240
|
}, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
|
|
241
|
+
appContext: {
|
|
242
|
+
appDirectory: appContext.appDirectory,
|
|
243
|
+
sharedDirectory: appContext.sharedDirectory,
|
|
244
|
+
apiDirectory: appContext.apiDirectory,
|
|
245
|
+
lambdaDirectory: appContext.lambdaDirectory
|
|
246
|
+
},
|
|
242
247
|
pwd: appDirectory,
|
|
243
248
|
config: normalizedConfig,
|
|
244
249
|
serverConfigFile: serverConfigFile,
|
|
@@ -256,11 +261,7 @@ var dev = function() {
|
|
|
256
261
|
];
|
|
257
262
|
case 5:
|
|
258
263
|
app = _state.sent();
|
|
259
|
-
|
|
260
|
-
app.listen({
|
|
261
|
-
port: port,
|
|
262
|
-
host: host
|
|
263
|
-
}, function() {
|
|
264
|
+
app.listen(port, function() {
|
|
264
265
|
var _ref = _asyncToGenerator(function(err) {
|
|
265
266
|
return __generator(this, function(_state) {
|
|
266
267
|
if (err) {
|
|
@@ -122,7 +122,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
|
-
import { logger, chalk, isApiOnly } from "@modern-js/utils";
|
|
125
|
+
import { logger, chalk, isApiOnly, getTargetDir } from "@modern-js/utils";
|
|
126
126
|
import server from "@modern-js/prod-server";
|
|
127
127
|
import { printInstructions } from "../utils/printInstructions";
|
|
128
128
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
@@ -155,6 +155,11 @@ var start = function() {
|
|
|
155
155
|
server({
|
|
156
156
|
pwd: appDirectory,
|
|
157
157
|
config: userConfig,
|
|
158
|
+
appContext: {
|
|
159
|
+
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
160
|
+
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
161
|
+
lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
|
162
|
+
},
|
|
158
163
|
serverConfigFile: serverConfigFile,
|
|
159
164
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
|
|
160
165
|
apiOnly: apiOnly
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, getEntryOptions,
|
|
2
|
+
import { fs, getEntryOptions, logger } from "@modern-js/utils";
|
|
3
3
|
import {
|
|
4
4
|
useResolvedConfigContext
|
|
5
5
|
} from "@modern-js/core";
|
|
@@ -60,6 +60,7 @@ ${initialize || ""}`
|
|
|
60
60
|
).join("\n");
|
|
61
61
|
};
|
|
62
62
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
63
|
+
var _a, _b, _c;
|
|
63
64
|
const {
|
|
64
65
|
internalDirectory,
|
|
65
66
|
srcDirectory,
|
|
@@ -68,7 +69,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
68
69
|
packageName
|
|
69
70
|
} = appContext;
|
|
70
71
|
const hookRunners = api.useHookRunners();
|
|
71
|
-
const isV5 =
|
|
72
|
+
const isV5 = typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
|
|
72
73
|
const { mountId } = config.html;
|
|
73
74
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
74
75
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
@@ -87,18 +88,23 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
87
88
|
internalDirAlias
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
if (entrypoint.nestedRoutesEntry) {
|
|
92
|
+
if (!isV5) {
|
|
93
|
+
nestedRoute = await walk(
|
|
94
|
+
entrypoint.nestedRoutesEntry,
|
|
95
|
+
entrypoint.nestedRoutesEntry,
|
|
96
|
+
{
|
|
97
|
+
name: internalSrcAlias,
|
|
98
|
+
basename: srcDirectory
|
|
99
|
+
},
|
|
100
|
+
entrypoint.entryName
|
|
101
|
+
);
|
|
102
|
+
if (nestedRoute) {
|
|
103
|
+
initialRoutes.unshift(nestedRoute);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
logger.error("Nested routes is not supported in legacy mode.");
|
|
107
|
+
process.exit(1);
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|