@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, getEntryOptions, logger } from "@modern-js/utils";
|
|
2
|
+
import { fs, getEntryOptions, isRouterV5, logger } from "@modern-js/utils";
|
|
3
3
|
import {
|
|
4
4
|
useResolvedConfigContext
|
|
5
5
|
} from "@modern-js/core";
|
|
@@ -60,17 +60,15 @@ ${initialize || ""}`
|
|
|
60
60
|
).join("\n");
|
|
61
61
|
};
|
|
62
62
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
63
|
-
var _a, _b, _c;
|
|
64
63
|
const {
|
|
65
64
|
internalDirectory,
|
|
66
65
|
srcDirectory,
|
|
67
66
|
internalDirAlias,
|
|
68
67
|
internalSrcAlias,
|
|
69
|
-
packageName
|
|
70
|
-
metaName
|
|
68
|
+
packageName
|
|
71
69
|
} = appContext;
|
|
72
70
|
const hookRunners = api.useHookRunners();
|
|
73
|
-
const isV5 =
|
|
71
|
+
const isV5 = isRouterV5(config);
|
|
74
72
|
const { mountId } = config.html;
|
|
75
73
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
76
74
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
@@ -89,23 +87,18 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
89
87
|
internalDirAlias
|
|
90
88
|
});
|
|
91
89
|
}
|
|
92
|
-
if (entrypoint.nestedRoutesEntry) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
initialRoutes.unshift(nestedRoute);
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
logger.error("Nested routes is not supported in legacy mode.");
|
|
108
|
-
process.exit(1);
|
|
90
|
+
if (!isV5 && entrypoint.nestedRoutesEntry) {
|
|
91
|
+
nestedRoute = await walk(
|
|
92
|
+
entrypoint.nestedRoutesEntry,
|
|
93
|
+
entrypoint.nestedRoutesEntry,
|
|
94
|
+
{
|
|
95
|
+
name: internalSrcAlias,
|
|
96
|
+
basename: srcDirectory
|
|
97
|
+
},
|
|
98
|
+
entrypoint.entryName
|
|
99
|
+
);
|
|
100
|
+
if (nestedRoute) {
|
|
101
|
+
initialRoutes.unshift(nestedRoute);
|
|
109
102
|
}
|
|
110
103
|
}
|
|
111
104
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
@@ -152,8 +145,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
152
145
|
entryName
|
|
153
146
|
);
|
|
154
147
|
const code3 = templates.routesForServer({
|
|
155
|
-
routes
|
|
156
|
-
metaName
|
|
148
|
+
routes
|
|
157
149
|
});
|
|
158
150
|
await fs.ensureFile(routesServerFile);
|
|
159
151
|
await fs.writeFile(routesServerFile, code3);
|
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
ensureAbsolutePath,
|
|
4
4
|
fs,
|
|
5
5
|
findExists,
|
|
6
|
-
MAIN_ENTRY_NAME
|
|
6
|
+
MAIN_ENTRY_NAME,
|
|
7
|
+
isRouterV5
|
|
7
8
|
} from "@modern-js/utils";
|
|
8
9
|
import { getFileSystemEntry } from "./getFileSystemEntry";
|
|
9
10
|
import { JS_EXTENSIONS } from "./constants";
|
|
@@ -55,7 +56,7 @@ const getBundleEntry = (appContext, config) => {
|
|
|
55
56
|
customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
|
56
57
|
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
57
58
|
};
|
|
58
|
-
if (entrypoint.fileSystemRoutes) {
|
|
59
|
+
if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
|
|
59
60
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
60
61
|
}
|
|
61
62
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -196,10 +196,6 @@ var analyze_default = ({
|
|
|
196
196
|
entryName
|
|
197
197
|
);
|
|
198
198
|
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
199
|
-
chain.resolve.alias.set(
|
|
200
|
-
"@modern-js/plugin-data-loader/runtime",
|
|
201
|
-
require.resolve("@modern-js/plugin-data-loader/runtime")
|
|
202
|
-
);
|
|
203
199
|
}
|
|
204
200
|
});
|
|
205
201
|
}
|
|
@@ -89,8 +89,7 @@ const html = (partials) => `
|
|
|
89
89
|
</html>
|
|
90
90
|
`;
|
|
91
91
|
const routesForServer = ({
|
|
92
|
-
routes
|
|
93
|
-
metaName
|
|
92
|
+
routes
|
|
94
93
|
}) => {
|
|
95
94
|
const loaders = [];
|
|
96
95
|
const traverseRouteTree = (route) => {
|
|
@@ -135,13 +134,9 @@ const routesForServer = ({
|
|
|
135
134
|
return `import loader_${index2} from "${slash(loader)}"`;
|
|
136
135
|
}).join("\n");
|
|
137
136
|
}
|
|
138
|
-
const exportCode = `
|
|
139
|
-
export { handleRequest } from '@modern-js/plugin-data-loader/runtime';
|
|
140
|
-
`;
|
|
141
137
|
return `
|
|
142
138
|
${importLoadersCode}
|
|
143
139
|
${routesCode}
|
|
144
|
-
${exportCode}
|
|
145
140
|
`;
|
|
146
141
|
};
|
|
147
142
|
const fileSystemRoutes = async ({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import { createCopyPattern } from "../../shared";
|
|
3
3
|
import { RouterPlugin } from "../webpackPlugins";
|
|
4
|
-
const
|
|
4
|
+
const builderPluginCompatModern = (options) => ({
|
|
5
5
|
name: "builder-plugin-compat-modern",
|
|
6
6
|
setup(api) {
|
|
7
7
|
const { normalizedConfig: modernConfig, appContext } = options;
|
|
@@ -37,5 +37,5 @@ const PluginCompatModern = (options) => ({
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
export {
|
|
40
|
-
|
|
40
|
+
builderPluginCompatModern
|
|
41
41
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
builderWebpackProvider
|
|
3
3
|
} from "@modern-js/builder-webpack-provider";
|
|
4
|
-
import { applyOptionsChain } from "@modern-js/utils";
|
|
5
4
|
import { createCopyPattern } from "../shared";
|
|
6
5
|
import { generateBuilder } from "../generator";
|
|
7
|
-
import {
|
|
6
|
+
import { builderPluginCompatModern } from "./builderPlugins/compatModern";
|
|
8
7
|
function createWebpackBuilderForModern(options) {
|
|
9
8
|
return generateBuilder(options, builderWebpackProvider, {
|
|
10
9
|
modifyBuilderConfig(config) {
|
|
@@ -31,20 +30,15 @@ function modifyOutputConfig(config, appContext) {
|
|
|
31
30
|
async function applyBuilderPlugins(builder, options) {
|
|
32
31
|
const { normalizedConfig } = options;
|
|
33
32
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
34
|
-
const {
|
|
35
|
-
builder.addPlugins([
|
|
33
|
+
const { builderPluginNodePolyfill } = await import("@modern-js/builder-plugin-node-polyfill");
|
|
34
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
36
35
|
}
|
|
37
36
|
if (normalizedConfig.tools.esbuild) {
|
|
38
37
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
39
|
-
const {
|
|
40
|
-
builder.addPlugins([
|
|
41
|
-
PluginEsbuild({
|
|
42
|
-
loader: false,
|
|
43
|
-
minimize: applyOptionsChain({}, esbuildOptions)
|
|
44
|
-
})
|
|
45
|
-
]);
|
|
38
|
+
const { builderPluginEsbuild } = await import("@modern-js/builder-plugin-esbuild");
|
|
39
|
+
builder.addPlugins([builderPluginEsbuild(esbuildOptions)]);
|
|
46
40
|
}
|
|
47
|
-
builder.addPlugins([
|
|
41
|
+
builder.addPlugins([builderPluginCompatModern(options)]);
|
|
48
42
|
}
|
|
49
43
|
export {
|
|
50
44
|
createWebpackBuilderForModern
|
|
@@ -10,7 +10,7 @@ function getBuilderTargets(normalizedConfig) {
|
|
|
10
10
|
if (useNodeTarget) {
|
|
11
11
|
targets.push("node");
|
|
12
12
|
}
|
|
13
|
-
const useWorkerTarget =
|
|
13
|
+
const useWorkerTarget = isServiceWorker(normalizedConfig);
|
|
14
14
|
if (useWorkerTarget) {
|
|
15
15
|
targets.push("service-worker");
|
|
16
16
|
}
|
|
@@ -9,7 +9,7 @@ import { generateRoutes } from "../utils/routes";
|
|
|
9
9
|
import { buildServerConfig } from "../utils/config";
|
|
10
10
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
11
11
|
const dev = async (api, options) => {
|
|
12
|
-
var _a;
|
|
12
|
+
var _a, _b;
|
|
13
13
|
if (options.analyze) {
|
|
14
14
|
process.env.BUNDLE_ANALYZE = "true";
|
|
15
15
|
}
|
|
@@ -41,6 +41,7 @@ const dev = async (api, options) => {
|
|
|
41
41
|
dev: {
|
|
42
42
|
port,
|
|
43
43
|
https: normalizedConfig.dev.https,
|
|
44
|
+
host: normalizedConfig.dev.host,
|
|
44
45
|
...(_a = normalizedConfig.tools) == null ? void 0 : _a.devServer
|
|
45
46
|
},
|
|
46
47
|
pwd: appDirectory,
|
|
@@ -53,12 +54,19 @@ const dev = async (api, options) => {
|
|
|
53
54
|
...serverOptions,
|
|
54
55
|
compiler: null
|
|
55
56
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const host = ((_b = normalizedConfig.dev) == null ? void 0 : _b.host) || "localhost";
|
|
58
|
+
app.listen(
|
|
59
|
+
{
|
|
60
|
+
port,
|
|
61
|
+
host
|
|
62
|
+
},
|
|
63
|
+
async (err) => {
|
|
64
|
+
if (err) {
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
59
68
|
}
|
|
60
|
-
|
|
61
|
-
});
|
|
69
|
+
);
|
|
62
70
|
} else {
|
|
63
71
|
const { server } = await appContext.builder.startDevServer({
|
|
64
72
|
printURLs: false,
|
|
@@ -23,9 +23,7 @@ const NESTED_ROUTE = {
|
|
|
23
23
|
PAGE_LOADER_FILE: "page.loader",
|
|
24
24
|
LOADING_FILE: "loading",
|
|
25
25
|
ERROR_FILE: "error",
|
|
26
|
-
LOADER_FILE: "loader"
|
|
27
|
-
SPLATE_FILE: "$",
|
|
28
|
-
SPLATE_LOADER_FILE: "$.loader"
|
|
26
|
+
LOADER_FILE: "loader"
|
|
29
27
|
};
|
|
30
28
|
const APP_CONFIG_NAME = "config";
|
|
31
29
|
const APP_INIT_EXPORTED = "init";
|
|
@@ -49,12 +49,12 @@ import {
|
|
|
49
49
|
isDevCommand
|
|
50
50
|
} from "@modern-js/utils";
|
|
51
51
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
52
|
+
import { createBuilderForModern } from "../builder";
|
|
52
53
|
import { printInstructions } from "../utils/printInstructions";
|
|
53
54
|
import { generateRoutes } from "../utils/routes";
|
|
54
55
|
import { emitResolvedConfig } from "../utils/config";
|
|
55
56
|
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
56
57
|
import { initialNormalizedConfig } from "../config";
|
|
57
|
-
import { createBuilderGenerator } from "../builder";
|
|
58
58
|
import {
|
|
59
59
|
getServerLoadersFile,
|
|
60
60
|
isPageComponentFile,
|
|
@@ -67,9 +67,7 @@ import {
|
|
|
67
67
|
APP_INIT_IMPORTED
|
|
68
68
|
} from "./constants";
|
|
69
69
|
const debug = createDebugger("plugin-analyze");
|
|
70
|
-
var analyze_default = ({
|
|
71
|
-
bundler
|
|
72
|
-
}) => ({
|
|
70
|
+
var analyze_default = () => ({
|
|
73
71
|
name: "@modern-js/plugin-analyze",
|
|
74
72
|
setup: (api) => {
|
|
75
73
|
let pagesDir = [];
|
|
@@ -161,51 +159,56 @@ var analyze_default = ({
|
|
|
161
159
|
if (buildCommands.includes(command)) {
|
|
162
160
|
let _b;
|
|
163
161
|
const normalizedConfig = api.useResolvedConfigContext();
|
|
164
|
-
const createBuilderForModern = yield createBuilderGenerator(bundler);
|
|
165
162
|
const builder = yield createBuilderForModern({
|
|
166
163
|
normalizedConfig,
|
|
167
164
|
appContext,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
165
|
+
compatPluginConfig: {
|
|
166
|
+
onBeforeBuild(_0) {
|
|
167
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
168
|
+
const hookRunners2 = api.useHookRunners();
|
|
169
|
+
yield generateRoutes(appContext);
|
|
170
|
+
yield hookRunners2.beforeBuild({ bundlerConfigs });
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
onAfterBuild(_0) {
|
|
174
|
+
return __async(this, arguments, function* ({ stats }) {
|
|
175
|
+
const hookRunners2 = api.useHookRunners();
|
|
176
|
+
yield hookRunners2.afterBuild({ stats });
|
|
177
|
+
yield emitResolvedConfig(
|
|
178
|
+
appContext.appDirectory,
|
|
179
|
+
normalizedConfig
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
onDevCompileDone(_0) {
|
|
184
|
+
return __async(this, arguments, function* ({ isFirstCompile }) {
|
|
185
|
+
const hookRunners2 = api.useHookRunners();
|
|
186
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
187
|
+
hookRunners2.afterDev();
|
|
188
|
+
if (isFirstCompile) {
|
|
189
|
+
printInstructions(
|
|
190
|
+
hookRunners2,
|
|
191
|
+
appContext,
|
|
192
|
+
normalizedConfig
|
|
193
|
+
);
|
|
194
|
+
}
|
|
192
195
|
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
onBeforeCreateCompiler(_0) {
|
|
197
|
-
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
198
|
-
const hookRunners2 = api.useHookRunners();
|
|
199
|
-
yield hookRunners2.beforeCreateCompiler({
|
|
200
|
-
bundlerConfigs
|
|
201
196
|
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
197
|
+
},
|
|
198
|
+
onBeforeCreateCompiler(_0) {
|
|
199
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
200
|
+
const hookRunners2 = api.useHookRunners();
|
|
201
|
+
yield hookRunners2.beforeCreateCompiler({
|
|
202
|
+
bundlerConfigs
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
onAfterCreateCompiler(_0) {
|
|
207
|
+
return __async(this, arguments, function* ({ compiler }) {
|
|
208
|
+
const hookRunners2 = api.useHookRunners();
|
|
209
|
+
yield hookRunners2.afterCreateCompiler({ compiler });
|
|
210
|
+
});
|
|
211
|
+
}
|
|
209
212
|
}
|
|
210
213
|
});
|
|
211
214
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
@@ -248,7 +251,7 @@ var analyze_default = ({
|
|
|
248
251
|
},
|
|
249
252
|
resolvedConfig({ resolved }) {
|
|
250
253
|
const appContext = api.useAppContext();
|
|
251
|
-
const config = initialNormalizedConfig(resolved, appContext
|
|
254
|
+
const config = initialNormalizedConfig(resolved, appContext);
|
|
252
255
|
return {
|
|
253
256
|
resolved: config
|
|
254
257
|
};
|
|
@@ -64,7 +64,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
|
|
67
|
-
var _a, _b, _c
|
|
67
|
+
var _a, _b, _c;
|
|
68
68
|
if (!(yield fs.pathExists(dirname))) {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
@@ -90,8 +90,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
90
90
|
};
|
|
91
91
|
let pageLoaderFile = "";
|
|
92
92
|
let pageRoute = null;
|
|
93
|
-
let splatLoaderFile = "";
|
|
94
|
-
let splatRoute = null;
|
|
95
93
|
const items = yield fs.readdir(dirname);
|
|
96
94
|
for (const item of items) {
|
|
97
95
|
const itemPath = path.join(dirname, item);
|
|
@@ -132,24 +130,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
132
130
|
}
|
|
133
131
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
134
132
|
}
|
|
135
|
-
if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
136
|
-
splatLoaderFile = itemPath;
|
|
137
|
-
}
|
|
138
|
-
if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
|
|
139
|
-
splatRoute = createRoute(
|
|
140
|
-
{
|
|
141
|
-
_component: replaceWithAlias(alias.basename, itemPath, alias.name),
|
|
142
|
-
path: "*"
|
|
143
|
-
},
|
|
144
|
-
rootDir,
|
|
145
|
-
itemPath,
|
|
146
|
-
entryName
|
|
147
|
-
);
|
|
148
|
-
if (splatLoaderFile) {
|
|
149
|
-
splatRoute.loader = splatLoaderFile;
|
|
150
|
-
}
|
|
151
|
-
(_c = route.children) == null ? void 0 : _c.push(splatRoute);
|
|
152
|
-
}
|
|
153
133
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
154
134
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
155
135
|
}
|
|
@@ -166,7 +146,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
166
146
|
if (isPathlessLayout) {
|
|
167
147
|
delete finalRoute.path;
|
|
168
148
|
}
|
|
169
|
-
route.children = (
|
|
149
|
+
route.children = (_c = route.children) == null ? void 0 : _c.filter((childRoute) => childRoute);
|
|
170
150
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
171
151
|
return null;
|
|
172
152
|
}
|
|
@@ -198,6 +198,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
198
198
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
199
199
|
`;
|
|
200
200
|
let rootLayoutCode = ``;
|
|
201
|
+
let componentLoaderPath = "";
|
|
201
202
|
const getDataLoaderPath = (loaderId) => {
|
|
202
203
|
if (!ssrMode) {
|
|
203
204
|
return "";
|
|
@@ -210,6 +211,12 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
210
211
|
}
|
|
211
212
|
return dataLoaderPath;
|
|
212
213
|
};
|
|
214
|
+
if (ssrMode) {
|
|
215
|
+
componentLoaderPath = `${path.join(
|
|
216
|
+
__dirname,
|
|
217
|
+
"../builder/loaders/routerLoader"
|
|
218
|
+
)}!`;
|
|
219
|
+
}
|
|
213
220
|
const traverseRouteTree = (route) => {
|
|
214
221
|
var _a;
|
|
215
222
|
let children;
|
|
@@ -245,10 +252,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
245
252
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
246
253
|
component = `RootLayout`;
|
|
247
254
|
} else if (ssrMode === "string") {
|
|
248
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
255
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
|
|
249
256
|
component = `loadable(${lazyImport})`;
|
|
250
257
|
} else {
|
|
251
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
258
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
|
|
252
259
|
component = `lazy(${lazyImport})`;
|
|
253
260
|
}
|
|
254
261
|
}
|