@modern-js/app-tools 2.5.0-alpha.1 → 2.5.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/analyze/generateCode.js +15 -23
- package/dist/cjs/analyze/getBundleEntry.js +1 -1
- package/dist/cjs/analyze/index.js +0 -4
- package/dist/cjs/analyze/templates.js +1 -6
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +3 -3
- package/dist/cjs/builder/builder-webpack/index.js +5 -11
- package/dist/cjs/builder/generator/getBuilderTargets.js +1 -1
- package/dist/cjs/commands/dev.js +14 -6
- package/dist/cjs/config/legacy/createToolsConfig.js +4 -1
- package/dist/esm/analyze/generateCode.js +28 -40
- package/dist/esm/analyze/getBundleEntry.js +2 -2
- package/dist/esm/analyze/index.js +0 -1
- package/dist/esm/analyze/templates.js +2 -3
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm/builder/builder-webpack/index.js +7 -11
- package/dist/esm/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm/commands/dev.js +8 -3
- package/dist/esm/config/legacy/createToolsConfig.js +4 -1
- package/dist/esm-node/analyze/generateCode.js +16 -24
- package/dist/esm-node/analyze/getBundleEntry.js +3 -2
- package/dist/esm-node/analyze/index.js +0 -4
- package/dist/esm-node/analyze/templates.js +1 -6
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm-node/builder/builder-webpack/index.js +6 -12
- package/dist/esm-node/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm-node/commands/dev.js +14 -6
- package/dist/esm-node/config/legacy/createToolsConfig.js +4 -1
- package/dist/js/modern/analyze/constants.js +1 -3
- package/dist/js/modern/analyze/index.js +48 -45
- package/dist/js/modern/analyze/nestedRoutes.js +2 -22
- package/dist/js/modern/analyze/templates.js +9 -2
- package/dist/js/modern/builder/{shared/builderPlugins/adapterModern.js → builderPlugins/compatModern.js} +111 -81
- package/dist/js/modern/builder/index.js +133 -13
- package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
- package/dist/js/modern/builder/{shared/loaders → loaders}/serverModuleLoader.js +0 -0
- package/dist/js/modern/builder/{shared/createCopyPattern.js → share.js} +0 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
- package/dist/js/modern/builder/{builder-webpack/webpackPlugins/RouterPlugin.js → webpackPlugins/routerPlugin.js} +1 -1
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +8 -3
- package/dist/js/modern/config/{legacy → initial}/createHtmlConfig.js +0 -0
- package/dist/js/modern/config/{legacy → initial}/createOutputConfig.js +0 -0
- package/dist/js/modern/config/{legacy → initial}/createSourceConfig.js +0 -0
- package/dist/js/modern/config/{legacy → initial}/createToolsConfig.js +0 -0
- package/dist/js/modern/config/initial/index.js +16 -0
- package/dist/js/modern/config/{initialize → initial}/inits.js +2 -4
- package/dist/js/modern/config/{legacy/index.js → initial/transformNormalizedConfig.js} +0 -4
- package/dist/js/modern/index.js +8 -18
- package/dist/js/modern/initialize/index.js +28 -36
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/node/analyze/constants.js +1 -3
- package/dist/js/node/analyze/index.js +49 -46
- package/dist/js/node/analyze/nestedRoutes.js +2 -22
- package/dist/js/node/analyze/templates.js +9 -2
- package/dist/js/node/builder/{shared/builderPlugins/adapterModern.js → builderPlugins/compatModern.js} +115 -86
- package/dist/js/node/builder/index.js +123 -14
- package/dist/js/node/builder/{generator/getBuilderTargets.js → loaders/routerLoader.js} +16 -13
- package/dist/js/node/builder/{shared/loaders → loaders}/serverModuleLoader.js +0 -0
- package/dist/js/node/builder/{shared/createCopyPattern.js → share.js} +3 -3
- package/dist/js/node/builder/{shared/bundlerPlugins/HtmlAsyncChunkPlugin.js → webpackPlugins/htmlAsyncChunkPlugin.js} +20 -17
- package/dist/js/node/builder/{shared/bundlerPlugins/HtmlBottomTemplate.js → webpackPlugins/htmlBottomTemplate.js} +24 -21
- package/dist/js/node/builder/{builder-webpack/webpackPlugins/RouterPlugin.js → webpackPlugins/routerPlugin.js} +5 -7
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +19 -4
- package/dist/js/node/config/{legacy → initial}/createHtmlConfig.js +0 -0
- package/dist/js/node/config/{legacy → initial}/createOutputConfig.js +0 -0
- package/dist/js/node/config/{legacy → initial}/createSourceConfig.js +0 -0
- package/dist/js/node/config/{legacy → initial}/createToolsConfig.js +0 -0
- package/dist/js/node/config/{initialize → initial}/index.js +16 -10
- package/dist/js/node/config/{initialize → initial}/inits.js +2 -4
- package/dist/js/node/config/{legacy/index.js → initial/transformNormalizedConfig.js} +3 -8
- package/dist/js/node/index.js +8 -18
- package/dist/js/node/initialize/index.js +28 -35
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/treeshaking/analyze/constants.js +1 -3
- package/dist/js/treeshaking/analyze/index.js +130 -135
- package/dist/js/treeshaking/analyze/nestedRoutes.js +1 -17
- package/dist/js/treeshaking/analyze/templates.js +7 -3
- package/dist/js/treeshaking/builder/{shared/builderPlugins/adapterModern.js → builderPlugins/compatModern.js} +156 -103
- package/dist/js/treeshaking/builder/index.js +228 -29
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
- package/dist/js/treeshaking/builder/{shared/loaders → loaders}/serverModuleLoader.js +0 -0
- package/dist/js/treeshaking/builder/{shared/createCopyPattern.js → share.js} +0 -0
- package/dist/js/treeshaking/builder/{shared/bundlerPlugins/HtmlAsyncChunkPlugin.js → webpackPlugins/htmlAsyncChunkPlugin.js} +0 -0
- package/dist/js/treeshaking/builder/{shared/bundlerPlugins/HtmlBottomTemplate.js → webpackPlugins/htmlBottomTemplate.js} +0 -0
- package/dist/js/treeshaking/builder/{builder-webpack/webpackPlugins/RouterPlugin.js → webpackPlugins/routerPlugin.js} +1 -1
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/{legacy → initial}/createHtmlConfig.js +0 -0
- package/dist/js/treeshaking/config/{legacy → initial}/createOutputConfig.js +0 -0
- package/dist/js/treeshaking/config/{legacy → initial}/createSourceConfig.js +0 -0
- package/dist/js/treeshaking/config/{legacy → initial}/createToolsConfig.js +0 -0
- package/dist/js/treeshaking/config/initial/index.js +12 -0
- package/dist/js/treeshaking/config/{initialize → initial}/inits.js +2 -4
- package/dist/js/treeshaking/config/{legacy/index.js → initial/transformNormalizedConfig.js} +1 -4
- package/dist/js/treeshaking/index.js +12 -19
- package/dist/js/treeshaking/initialize/index.js +26 -34
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/types/analyze/templates.d.ts +1 -3
- package/dist/types/builder/builder-webpack/builderPlugins/compatModern.d.ts +1 -7
- package/package.json +14 -14
- package/dist/js/modern/builder/builder-rspack/index.js +0 -8
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +0 -41
- package/dist/js/modern/builder/builder-webpack/index.js +0 -93
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +0 -1
- package/dist/js/modern/builder/generator/createBuilderOptions.js +0 -24
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +0 -39
- package/dist/js/modern/builder/generator/getBuilderTargets.js +0 -12
- package/dist/js/modern/builder/generator/index.js +0 -53
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -27
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -34
- package/dist/js/modern/builder/shared/index.js +0 -3
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/initialize/index.js +0 -12
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/builder/builder-rspack/index.js +0 -31
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +0 -64
- package/dist/js/node/builder/builder-webpack/index.js +0 -118
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +0 -17
- package/dist/js/node/builder/generator/createBuilderOptions.js +0 -47
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +0 -60
- package/dist/js/node/builder/generator/index.js +0 -82
- package/dist/js/node/builder/shared/index.js +0 -19
- package/dist/js/node/builder/shared/types.js +0 -15
- package/dist/js/node/types/utils.js +0 -15
- package/dist/js/treeshaking/builder/builder-rspack/index.js +0 -6
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +0 -64
- package/dist/js/treeshaking/builder/builder-webpack/index.js +0 -301
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +0 -1
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +0 -41
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +0 -70
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +0 -12
- package/dist/js/treeshaking/builder/generator/index.js +0 -199
- package/dist/js/treeshaking/builder/shared/index.js +0 -3
- package/dist/js/treeshaking/builder/shared/types.js +0 -1
- package/dist/js/treeshaking/config/initialize/index.js +0 -10
- package/dist/js/treeshaking/types/utils.js +0 -1
|
@@ -83,17 +83,15 @@ ${initialize || ""}`
|
|
|
83
83
|
).join("\n");
|
|
84
84
|
};
|
|
85
85
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
86
|
-
var _a, _b, _c;
|
|
87
86
|
const {
|
|
88
87
|
internalDirectory,
|
|
89
88
|
srcDirectory,
|
|
90
89
|
internalDirAlias,
|
|
91
90
|
internalSrcAlias,
|
|
92
|
-
packageName
|
|
93
|
-
metaName
|
|
91
|
+
packageName
|
|
94
92
|
} = appContext;
|
|
95
93
|
const hookRunners = api.useHookRunners();
|
|
96
|
-
const isV5 =
|
|
94
|
+
const isV5 = (0, import_utils.isRouterV5)(config);
|
|
97
95
|
const { mountId } = config.html;
|
|
98
96
|
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
|
99
97
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
@@ -112,23 +110,18 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
112
110
|
internalDirAlias
|
|
113
111
|
});
|
|
114
112
|
}
|
|
115
|
-
if (entrypoint.nestedRoutesEntry) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
initialRoutes.unshift(nestedRoute);
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
import_utils.logger.error("Nested routes is not supported in legacy mode.");
|
|
131
|
-
process.exit(1);
|
|
113
|
+
if (!isV5 && entrypoint.nestedRoutesEntry) {
|
|
114
|
+
nestedRoute = await (0, import_nestedRoutes.walk)(
|
|
115
|
+
entrypoint.nestedRoutesEntry,
|
|
116
|
+
entrypoint.nestedRoutesEntry,
|
|
117
|
+
{
|
|
118
|
+
name: internalSrcAlias,
|
|
119
|
+
basename: srcDirectory
|
|
120
|
+
},
|
|
121
|
+
entrypoint.entryName
|
|
122
|
+
);
|
|
123
|
+
if (nestedRoute) {
|
|
124
|
+
initialRoutes.unshift(nestedRoute);
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
127
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
@@ -175,8 +168,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
175
168
|
entryName
|
|
176
169
|
);
|
|
177
170
|
const code3 = templates.routesForServer({
|
|
178
|
-
routes
|
|
179
|
-
metaName
|
|
171
|
+
routes
|
|
180
172
|
});
|
|
181
173
|
await import_utils.fs.ensureFile(routesServerFile);
|
|
182
174
|
await import_utils.fs.writeFile(routesServerFile, code3);
|
|
@@ -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 && (0, import_utils.isRouterV5)(config)) {
|
|
82
82
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
83
83
|
}
|
|
84
84
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -206,10 +206,6 @@ var analyze_default = ({
|
|
|
206
206
|
entryName
|
|
207
207
|
);
|
|
208
208
|
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
209
|
-
chain.resolve.alias.set(
|
|
210
|
-
"@modern-js/plugin-data-loader/runtime",
|
|
211
|
-
require.resolve("@modern-js/plugin-data-loader/runtime")
|
|
212
|
-
);
|
|
213
209
|
}
|
|
214
210
|
});
|
|
215
211
|
}
|
|
@@ -121,8 +121,7 @@ const html = (partials) => `
|
|
|
121
121
|
</html>
|
|
122
122
|
`;
|
|
123
123
|
const routesForServer = ({
|
|
124
|
-
routes
|
|
125
|
-
metaName
|
|
124
|
+
routes
|
|
126
125
|
}) => {
|
|
127
126
|
const loaders = [];
|
|
128
127
|
const traverseRouteTree = (route) => {
|
|
@@ -167,13 +166,9 @@ const routesForServer = ({
|
|
|
167
166
|
return `import loader_${index2} from "${(0, import_utils.slash)(loader)}"`;
|
|
168
167
|
}).join("\n");
|
|
169
168
|
}
|
|
170
|
-
const exportCode = `
|
|
171
|
-
export { handleRequest } from '@modern-js/plugin-data-loader/runtime';
|
|
172
|
-
`;
|
|
173
169
|
return `
|
|
174
170
|
${importLoadersCode}
|
|
175
171
|
${routesCode}
|
|
176
|
-
${exportCode}
|
|
177
172
|
`;
|
|
178
173
|
};
|
|
179
174
|
const fileSystemRoutes = async ({
|
|
@@ -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
|
+
builderPluginCompatModern: () => builderPluginCompatModern
|
|
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 builderPluginCompatModern = (options) => ({
|
|
27
27
|
name: "builder-plugin-compat-modern",
|
|
28
28
|
setup(api) {
|
|
29
29
|
const { normalizedConfig: modernConfig, appContext } = options;
|
|
@@ -60,5 +60,5 @@ const PluginCompatModern = (options) => ({
|
|
|
60
60
|
});
|
|
61
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
62
|
0 && (module.exports = {
|
|
63
|
-
|
|
63
|
+
builderPluginCompatModern
|
|
64
64
|
});
|
|
@@ -27,7 +27,6 @@ __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");
|
|
31
30
|
var import_shared = require("../shared");
|
|
32
31
|
var import_generator = require("../generator");
|
|
33
32
|
var import_compatModern = require("./builderPlugins/compatModern");
|
|
@@ -57,20 +56,15 @@ function modifyOutputConfig(config, appContext) {
|
|
|
57
56
|
async function applyBuilderPlugins(builder, options) {
|
|
58
57
|
const { normalizedConfig } = options;
|
|
59
58
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
60
|
-
const {
|
|
61
|
-
builder.addPlugins([
|
|
59
|
+
const { builderPluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
|
|
60
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
62
61
|
}
|
|
63
62
|
if (normalizedConfig.tools.esbuild) {
|
|
64
63
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
65
|
-
const {
|
|
66
|
-
builder.addPlugins([
|
|
67
|
-
PluginEsbuild({
|
|
68
|
-
loader: false,
|
|
69
|
-
minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
|
|
70
|
-
})
|
|
71
|
-
]);
|
|
64
|
+
const { builderPluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
|
|
65
|
+
builder.addPlugins([builderPluginEsbuild(esbuildOptions)]);
|
|
72
66
|
}
|
|
73
|
-
builder.addPlugins([(0, import_compatModern.
|
|
67
|
+
builder.addPlugins([(0, import_compatModern.builderPluginCompatModern)(options)]);
|
|
74
68
|
}
|
|
75
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
70
|
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.
|
|
30
|
+
const useWorkerTarget = (0, import_utils.isServiceWorker)(normalizedConfig);
|
|
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, _b;
|
|
31
31
|
if (options.analyze) {
|
|
32
32
|
process.env.BUNDLE_ANALYZE = "true";
|
|
33
33
|
}
|
|
@@ -59,6 +59,7 @@ const dev = async (api, options) => {
|
|
|
59
59
|
dev: {
|
|
60
60
|
port,
|
|
61
61
|
https: normalizedConfig.dev.https,
|
|
62
|
+
host: normalizedConfig.dev.host,
|
|
62
63
|
...(_a = normalizedConfig.tools) == null ? void 0 : _a.devServer
|
|
63
64
|
},
|
|
64
65
|
pwd: appDirectory,
|
|
@@ -71,12 +72,19 @@ const dev = async (api, options) => {
|
|
|
71
72
|
...serverOptions,
|
|
72
73
|
compiler: null
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const host = ((_b = normalizedConfig.dev) == null ? void 0 : _b.host) || "localhost";
|
|
76
|
+
app.listen(
|
|
77
|
+
{
|
|
78
|
+
port,
|
|
79
|
+
host
|
|
80
|
+
},
|
|
81
|
+
async (err) => {
|
|
82
|
+
if (err) {
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
(0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
|
|
77
86
|
}
|
|
78
|
-
|
|
79
|
-
});
|
|
87
|
+
);
|
|
80
88
|
} else {
|
|
81
89
|
const { server } = await appContext.builder.startDevServer({
|
|
82
90
|
printURLs: false,
|
|
@@ -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, logger } from "@modern-js/utils";
|
|
151
|
+
import { fs, getEntryOptions, isRouterV5, 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
|
|
243
|
+
var 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
|
+
16
|
|
257
257
|
];
|
|
258
258
|
if (!fileSystemRoutes) return [
|
|
259
259
|
3,
|
|
260
|
-
|
|
260
|
+
9
|
|
261
261
|
];
|
|
262
262
|
initialRoutes = [];
|
|
263
263
|
nestedRoute = null;
|
|
@@ -270,11 +270,7 @@ var generateCode = function() {
|
|
|
270
270
|
internalDirAlias: internalDirAlias
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
|
-
if (!entrypoint.nestedRoutesEntry) return [
|
|
274
|
-
3,
|
|
275
|
-
3
|
|
276
|
-
];
|
|
277
|
-
if (!!isV5) return [
|
|
273
|
+
if (!(!isV5 && entrypoint.nestedRoutesEntry)) return [
|
|
278
274
|
3,
|
|
279
275
|
2
|
|
280
276
|
];
|
|
@@ -290,15 +286,8 @@ var generateCode = function() {
|
|
|
290
286
|
if (nestedRoute) {
|
|
291
287
|
initialRoutes.unshift(nestedRoute);
|
|
292
288
|
}
|
|
293
|
-
|
|
294
|
-
3,
|
|
295
|
-
3
|
|
296
|
-
];
|
|
289
|
+
_state.label = 2;
|
|
297
290
|
case 2:
|
|
298
|
-
logger.error("Nested routes is not supported in legacy mode.");
|
|
299
|
-
process.exit(1);
|
|
300
|
-
_state.label = 3;
|
|
301
|
-
case 3:
|
|
302
291
|
return [
|
|
303
292
|
4,
|
|
304
293
|
hookRunners.modifyFileSystemRoutes({
|
|
@@ -306,7 +295,7 @@ var generateCode = function() {
|
|
|
306
295
|
routes: initialRoutes
|
|
307
296
|
})
|
|
308
297
|
];
|
|
309
|
-
case
|
|
298
|
+
case 3:
|
|
310
299
|
routes = _state.sent().routes;
|
|
311
300
|
config2 = useResolvedConfigContext();
|
|
312
301
|
ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
@@ -338,41 +327,40 @@ var generateCode = function() {
|
|
|
338
327
|
internalDirectory: internalDirectory
|
|
339
328
|
})
|
|
340
329
|
];
|
|
341
|
-
case
|
|
330
|
+
case 4:
|
|
342
331
|
return [
|
|
343
332
|
4,
|
|
344
333
|
_.apply(hookRunners, [
|
|
345
334
|
(_tmp.code = _state.sent(), _tmp)
|
|
346
335
|
])
|
|
347
336
|
];
|
|
348
|
-
case
|
|
337
|
+
case 5:
|
|
349
338
|
_ref = _state.sent(), code2 = _ref.code;
|
|
350
339
|
if (!(entrypoint.nestedRoutesEntry && mode)) return [
|
|
351
340
|
3,
|
|
352
|
-
|
|
341
|
+
8
|
|
353
342
|
];
|
|
354
343
|
routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
355
344
|
code3 = templates.routesForServer({
|
|
356
|
-
routes: routes
|
|
357
|
-
metaName: metaName
|
|
345
|
+
routes: routes
|
|
358
346
|
});
|
|
359
347
|
return [
|
|
360
348
|
4,
|
|
361
349
|
fs.ensureFile(routesServerFile)
|
|
362
350
|
];
|
|
363
|
-
case
|
|
351
|
+
case 6:
|
|
364
352
|
_state.sent();
|
|
365
353
|
return [
|
|
366
354
|
4,
|
|
367
355
|
fs.writeFile(routesServerFile, code3)
|
|
368
356
|
];
|
|
369
|
-
case
|
|
357
|
+
case 7:
|
|
370
358
|
_state.sent();
|
|
359
|
+
_state.label = 8;
|
|
360
|
+
case 8:
|
|
361
|
+
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
|
|
371
362
|
_state.label = 9;
|
|
372
363
|
case 9:
|
|
373
|
-
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
|
|
374
|
-
_state.label = 10;
|
|
375
|
-
case 10:
|
|
376
364
|
return [
|
|
377
365
|
4,
|
|
378
366
|
hookRunners.modifyEntryImports({
|
|
@@ -386,7 +374,7 @@ var generateCode = function() {
|
|
|
386
374
|
})
|
|
387
375
|
})
|
|
388
376
|
];
|
|
389
|
-
case
|
|
377
|
+
case 10:
|
|
390
378
|
_ref1 = _state.sent(), importStatements = _ref1.imports;
|
|
391
379
|
return [
|
|
392
380
|
4,
|
|
@@ -395,7 +383,7 @@ var generateCode = function() {
|
|
|
395
383
|
plugins: []
|
|
396
384
|
})
|
|
397
385
|
];
|
|
398
|
-
case
|
|
386
|
+
case 11:
|
|
399
387
|
plugins = _state.sent().plugins;
|
|
400
388
|
return [
|
|
401
389
|
4,
|
|
@@ -408,7 +396,7 @@ var generateCode = function() {
|
|
|
408
396
|
})
|
|
409
397
|
})
|
|
410
398
|
];
|
|
411
|
-
case
|
|
399
|
+
case 12:
|
|
412
400
|
_ref2 = _state.sent(), renderFunction = _ref2.code;
|
|
413
401
|
return [
|
|
414
402
|
4,
|
|
@@ -417,7 +405,7 @@ var generateCode = function() {
|
|
|
417
405
|
exportStatement: "export default AppWrapper;"
|
|
418
406
|
})
|
|
419
407
|
];
|
|
420
|
-
case
|
|
408
|
+
case 13:
|
|
421
409
|
exportStatement = _state.sent().exportStatement;
|
|
422
410
|
code = templates.index({
|
|
423
411
|
mountId: mountId,
|
|
@@ -429,7 +417,7 @@ var generateCode = function() {
|
|
|
429
417
|
entrypoint.entry = entryFile;
|
|
430
418
|
if (!config.source.enableAsyncEntry) return [
|
|
431
419
|
3,
|
|
432
|
-
|
|
420
|
+
15
|
|
433
421
|
];
|
|
434
422
|
return [
|
|
435
423
|
4,
|
|
@@ -438,19 +426,19 @@ var generateCode = function() {
|
|
|
438
426
|
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
439
427
|
})
|
|
440
428
|
];
|
|
441
|
-
case
|
|
429
|
+
case 14:
|
|
442
430
|
_ref3 = _state.sent(), asyncEntryCode = _ref3.code;
|
|
443
431
|
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
444
432
|
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
445
433
|
fs.outputFileSync(bootstrapFile, code, "utf8");
|
|
446
434
|
return [
|
|
447
435
|
3,
|
|
448
|
-
|
|
436
|
+
16
|
|
449
437
|
];
|
|
450
|
-
case
|
|
438
|
+
case 15:
|
|
451
439
|
fs.outputFileSync(entryFile, code, "utf8");
|
|
452
|
-
_state.label =
|
|
453
|
-
case
|
|
440
|
+
_state.label = 16;
|
|
441
|
+
case 16:
|
|
454
442
|
return [
|
|
455
443
|
2
|
|
456
444
|
];
|
|
@@ -462,9 +450,9 @@ var generateCode = function() {
|
|
|
462
450
|
return __generator(this, function(_state) {
|
|
463
451
|
switch(_state.label){
|
|
464
452
|
case 0:
|
|
465
|
-
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName
|
|
453
|
+
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
|
466
454
|
hookRunners = api.useHookRunners();
|
|
467
|
-
isV5 =
|
|
455
|
+
isV5 = isRouterV5(config);
|
|
468
456
|
mountId = config.html.mountId;
|
|
469
457
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
470
458
|
return [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME } from "@modern-js/utils";
|
|
2
|
+
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME, isRouterV5 } 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 && isRouterV5(config)) {
|
|
47
47
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
48
48
|
}
|
|
49
49
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -556,7 +556,6 @@ var analyze_default = function(param) {
|
|
|
556
556
|
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
557
557
|
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
558
558
|
chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
|
|
559
|
-
chain.resolve.alias.set("@modern-js/plugin-data-loader/runtime", require.resolve("@modern-js/plugin-data-loader/runtime"));
|
|
560
559
|
}
|
|
561
560
|
});
|
|
562
561
|
}
|
|
@@ -239,7 +239,7 @@ var html = function(partials) {
|
|
|
239
239
|
return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join("\n"), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join("\n"), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\n <div id=\"<%= mountId %>\"><!--<?- html ?>--></div>\n ").concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
|
|
240
240
|
};
|
|
241
241
|
var routesForServer = function(param) {
|
|
242
|
-
var routes = param.routes
|
|
242
|
+
var routes = param.routes;
|
|
243
243
|
var loaders = [];
|
|
244
244
|
var traverseRouteTree = function(route) {
|
|
245
245
|
var children;
|
|
@@ -293,8 +293,7 @@ var routesForServer = function(param) {
|
|
|
293
293
|
return "import loader_".concat(index2, ' from "').concat(slash(loader), '"');
|
|
294
294
|
}).join("\n");
|
|
295
295
|
}
|
|
296
|
-
|
|
297
|
-
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ").concat(exportCode, "\n ");
|
|
296
|
+
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
|
298
297
|
};
|
|
299
298
|
var fileSystemRoutes = function() {
|
|
300
299
|
var _ref = _asyncToGenerator(function(param) {
|
|
@@ -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 builderPluginCompatModern = function(options) {
|
|
30
30
|
return {
|
|
31
31
|
name: "builder-plugin-compat-modern",
|
|
32
32
|
setup: function setup(api) {
|
|
@@ -61,4 +61,4 @@ var PluginCompatModern = function(options) {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
export {
|
|
64
|
+
export { builderPluginCompatModern };
|
|
@@ -200,10 +200,9 @@ 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";
|
|
204
203
|
import { createCopyPattern } from "../shared";
|
|
205
204
|
import { generateBuilder } from "../generator";
|
|
206
|
-
import {
|
|
205
|
+
import { builderPluginCompatModern } from "./builderPlugins/compatModern";
|
|
207
206
|
function createWebpackBuilderForModern(options) {
|
|
208
207
|
return generateBuilder(options, builderWebpackProvider, {
|
|
209
208
|
modifyBuilderConfig: function modifyBuilderConfig(config) {
|
|
@@ -248,7 +247,7 @@ function applyBuilderPlugins(builder, options) {
|
|
|
248
247
|
}
|
|
249
248
|
function _applyBuilderPlugins() {
|
|
250
249
|
_applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
|
|
251
|
-
var normalizedConfig,
|
|
250
|
+
var normalizedConfig, builderPluginNodePolyfill, _normalizedConfig_tools, esbuildOptions, builderPluginEsbuild;
|
|
252
251
|
return __generator(this, function(_state) {
|
|
253
252
|
switch(_state.label){
|
|
254
253
|
case 0:
|
|
@@ -262,9 +261,9 @@ function _applyBuilderPlugins() {
|
|
|
262
261
|
import("@modern-js/builder-plugin-node-polyfill")
|
|
263
262
|
];
|
|
264
263
|
case 1:
|
|
265
|
-
|
|
264
|
+
builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
|
|
266
265
|
builder.addPlugins([
|
|
267
|
-
|
|
266
|
+
builderPluginNodePolyfill()
|
|
268
267
|
]);
|
|
269
268
|
_state.label = 2;
|
|
270
269
|
case 2:
|
|
@@ -278,17 +277,14 @@ function _applyBuilderPlugins() {
|
|
|
278
277
|
import("@modern-js/builder-plugin-esbuild")
|
|
279
278
|
];
|
|
280
279
|
case 3:
|
|
281
|
-
|
|
280
|
+
builderPluginEsbuild = _state.sent().builderPluginEsbuild;
|
|
282
281
|
builder.addPlugins([
|
|
283
|
-
|
|
284
|
-
loader: false,
|
|
285
|
-
minimize: applyOptionsChain({}, esbuildOptions)
|
|
286
|
-
})
|
|
282
|
+
builderPluginEsbuild(esbuildOptions)
|
|
287
283
|
]);
|
|
288
284
|
_state.label = 4;
|
|
289
285
|
case 4:
|
|
290
286
|
builder.addPlugins([
|
|
291
|
-
|
|
287
|
+
builderPluginCompatModern(options)
|
|
292
288
|
]);
|
|
293
289
|
return [
|
|
294
290
|
2
|
|
@@ -7,7 +7,7 @@ function getBuilderTargets(normalizedConfig) {
|
|
|
7
7
|
if (useNodeTarget) {
|
|
8
8
|
targets.push("node");
|
|
9
9
|
}
|
|
10
|
-
var useWorkerTarget =
|
|
10
|
+
var useWorkerTarget = isServiceWorker(normalizedConfig);
|
|
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, app, server;
|
|
185
|
+
var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
|
186
186
|
return __generator(this, function(_state) {
|
|
187
187
|
switch(_state.label){
|
|
188
188
|
case 0:
|
|
@@ -236,7 +236,8 @@ var dev = function() {
|
|
|
236
236
|
serverOptions = {
|
|
237
237
|
dev: _objectSpread({
|
|
238
238
|
port: port,
|
|
239
|
-
https: normalizedConfig.dev.https
|
|
239
|
+
https: normalizedConfig.dev.https,
|
|
240
|
+
host: normalizedConfig.dev.host
|
|
240
241
|
}, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
|
|
241
242
|
pwd: appDirectory,
|
|
242
243
|
config: normalizedConfig,
|
|
@@ -255,7 +256,11 @@ var dev = function() {
|
|
|
255
256
|
];
|
|
256
257
|
case 5:
|
|
257
258
|
app = _state.sent();
|
|
258
|
-
|
|
259
|
+
host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || "localhost";
|
|
260
|
+
app.listen({
|
|
261
|
+
port: port,
|
|
262
|
+
host: host
|
|
263
|
+
}, function() {
|
|
259
264
|
var _ref = _asyncToGenerator(function(err) {
|
|
260
265
|
return __generator(this, function(_state) {
|
|
261
266
|
if (err) {
|