@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
|
@@ -44,21 +44,19 @@ import {
|
|
|
44
44
|
isDevCommand
|
|
45
45
|
} from "@modern-js/utils";
|
|
46
46
|
import { legacySchema, schema } from "../schema";
|
|
47
|
+
import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
|
|
47
48
|
import {
|
|
48
49
|
checkIsLegacyConfig,
|
|
49
50
|
createDefaultConfig,
|
|
50
|
-
createLegacyDefaultConfig
|
|
51
|
-
transformNormalizedConfig
|
|
51
|
+
createLegacyDefaultConfig
|
|
52
52
|
} from "../config";
|
|
53
|
-
var initialize_default = ({
|
|
54
|
-
bundler
|
|
55
|
-
}) => ({
|
|
53
|
+
var initialize_default = () => ({
|
|
56
54
|
name: "@modern-js/plugin-initialize",
|
|
57
55
|
setup(api) {
|
|
58
56
|
const config = () => {
|
|
59
57
|
const appContext = api.useAppContext();
|
|
60
58
|
const userConfig = api.useConfigContext();
|
|
61
|
-
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext
|
|
59
|
+
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
|
|
62
60
|
};
|
|
63
61
|
const validateSchema = () => {
|
|
64
62
|
const userConfig = api.useConfigContext();
|
|
@@ -83,41 +81,35 @@ var initialize_default = ({
|
|
|
83
81
|
});
|
|
84
82
|
api.setAppContext(appContext);
|
|
85
83
|
const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
return { resolved };
|
|
84
|
+
return {
|
|
85
|
+
resolved: {
|
|
86
|
+
_raw: userConfig,
|
|
87
|
+
source: normalizedConfig.source || {},
|
|
88
|
+
server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
|
|
89
|
+
port
|
|
90
|
+
}),
|
|
91
|
+
bff: normalizedConfig.bff || {},
|
|
92
|
+
dev: normalizedConfig.dev || {},
|
|
93
|
+
html: normalizedConfig.html || {},
|
|
94
|
+
output: normalizedConfig.output || {},
|
|
95
|
+
security: normalizedConfig.security || {},
|
|
96
|
+
tools: normalizedConfig.tools || {},
|
|
97
|
+
testing: normalizedConfig.testing || {},
|
|
98
|
+
plugins: normalizedConfig.plugins || [],
|
|
99
|
+
builderPlugins: normalizedConfig.builderPlugins || [],
|
|
100
|
+
runtime: normalizedConfig.runtime || {},
|
|
101
|
+
runtimeByEntries: normalizedConfig.runtimeByEntries || {},
|
|
102
|
+
deploy: normalizedConfig.deploy || {},
|
|
103
|
+
performance: normalizedConfig.performance || {},
|
|
104
|
+
experiments: normalizedConfig.experiments || {},
|
|
105
|
+
autoLoadPlugins: normalizedConfig.autoLoadPlugins || false
|
|
106
|
+
}
|
|
107
|
+
};
|
|
111
108
|
});
|
|
112
109
|
}
|
|
113
110
|
};
|
|
114
111
|
}
|
|
115
112
|
});
|
|
116
|
-
function stabilizeConfig(resolve, config, keys) {
|
|
117
|
-
keys.forEach((key) => {
|
|
118
|
-
resolve[key] = config[key] || {};
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
113
|
function getServerPort(config) {
|
|
122
114
|
return __async(this, null, function* () {
|
|
123
115
|
const prodPort = config.server.port || 8080;
|
|
@@ -17,7 +17,7 @@ const ZH_LOCALE = {
|
|
|
17
17
|
serve: { describe: "应用启动命令" },
|
|
18
18
|
deploy: { describe: "部署应用命令" },
|
|
19
19
|
new: {
|
|
20
|
-
describe: "
|
|
20
|
+
describe: "MWA 项目中执行生成器",
|
|
21
21
|
debug: "开启 Debug 模式,打印调试日志信息",
|
|
22
22
|
config: "生成器运行默认配置(JSON 字符串)",
|
|
23
23
|
distTag: "生成器使用特殊的 npm Tag 版本",
|
|
@@ -66,9 +66,7 @@ const NESTED_ROUTE = {
|
|
|
66
66
|
PAGE_LOADER_FILE: "page.loader",
|
|
67
67
|
LOADING_FILE: "loading",
|
|
68
68
|
ERROR_FILE: "error",
|
|
69
|
-
LOADER_FILE: "loader"
|
|
70
|
-
SPLATE_FILE: "$",
|
|
71
|
-
SPLATE_LOADER_FILE: "$.loader"
|
|
69
|
+
LOADER_FILE: "loader"
|
|
72
70
|
};
|
|
73
71
|
const APP_CONFIG_NAME = "config";
|
|
74
72
|
const APP_INIT_EXPORTED = "init";
|
|
@@ -66,18 +66,16 @@ module.exports = __toCommonJS(analyze_exports);
|
|
|
66
66
|
var path = __toESM(require("path"));
|
|
67
67
|
var import_utils = require("@modern-js/utils");
|
|
68
68
|
var import_lodash = require("@modern-js/utils/lodash");
|
|
69
|
+
var import_builder = require("../builder");
|
|
69
70
|
var import_printInstructions = require("../utils/printInstructions");
|
|
70
71
|
var import_routes = require("../utils/routes");
|
|
71
72
|
var import_config = require("../utils/config");
|
|
72
73
|
var import_getSelectedEntries = require("../utils/getSelectedEntries");
|
|
73
74
|
var import_config2 = require("../config");
|
|
74
|
-
var import_builder = require("../builder");
|
|
75
75
|
var import_utils2 = require("./utils");
|
|
76
76
|
var import_constants = require("./constants");
|
|
77
77
|
const debug = (0, import_utils.createDebugger)("plugin-analyze");
|
|
78
|
-
var analyze_default = ({
|
|
79
|
-
bundler
|
|
80
|
-
}) => ({
|
|
78
|
+
var analyze_default = () => ({
|
|
81
79
|
name: "@modern-js/plugin-analyze",
|
|
82
80
|
setup: (api) => {
|
|
83
81
|
let pagesDir = [];
|
|
@@ -169,51 +167,56 @@ var analyze_default = ({
|
|
|
169
167
|
if (buildCommands.includes(command)) {
|
|
170
168
|
let _b;
|
|
171
169
|
const normalizedConfig = api.useResolvedConfigContext();
|
|
172
|
-
const
|
|
173
|
-
const builder = yield createBuilderForModern({
|
|
170
|
+
const builder = yield (0, import_builder.createBuilderForModern)({
|
|
174
171
|
normalizedConfig,
|
|
175
172
|
appContext,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
(
|
|
173
|
+
compatPluginConfig: {
|
|
174
|
+
onBeforeBuild(_0) {
|
|
175
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
176
|
+
const hookRunners2 = api.useHookRunners();
|
|
177
|
+
yield (0, import_routes.generateRoutes)(appContext);
|
|
178
|
+
yield hookRunners2.beforeBuild({ bundlerConfigs });
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
onAfterBuild(_0) {
|
|
182
|
+
return __async(this, arguments, function* ({ stats }) {
|
|
183
|
+
const hookRunners2 = api.useHookRunners();
|
|
184
|
+
yield hookRunners2.afterBuild({ stats });
|
|
185
|
+
yield (0, import_config.emitResolvedConfig)(
|
|
186
|
+
appContext.appDirectory,
|
|
187
|
+
normalizedConfig
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
onDevCompileDone(_0) {
|
|
192
|
+
return __async(this, arguments, function* ({ isFirstCompile }) {
|
|
193
|
+
const hookRunners2 = api.useHookRunners();
|
|
194
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
195
|
+
hookRunners2.afterDev();
|
|
196
|
+
if (isFirstCompile) {
|
|
197
|
+
(0, import_printInstructions.printInstructions)(
|
|
198
|
+
hookRunners2,
|
|
199
|
+
appContext,
|
|
200
|
+
normalizedConfig
|
|
201
|
+
);
|
|
202
|
+
}
|
|
200
203
|
}
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
},
|
|
204
|
-
onBeforeCreateCompiler(_0) {
|
|
205
|
-
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
206
|
-
const hookRunners2 = api.useHookRunners();
|
|
207
|
-
yield hookRunners2.beforeCreateCompiler({
|
|
208
|
-
bundlerConfigs
|
|
209
204
|
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
205
|
+
},
|
|
206
|
+
onBeforeCreateCompiler(_0) {
|
|
207
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
208
|
+
const hookRunners2 = api.useHookRunners();
|
|
209
|
+
yield hookRunners2.beforeCreateCompiler({
|
|
210
|
+
bundlerConfigs
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
onAfterCreateCompiler(_0) {
|
|
215
|
+
return __async(this, arguments, function* ({ compiler }) {
|
|
216
|
+
const hookRunners2 = api.useHookRunners();
|
|
217
|
+
yield hookRunners2.afterCreateCompiler({ compiler });
|
|
218
|
+
});
|
|
219
|
+
}
|
|
217
220
|
}
|
|
218
221
|
});
|
|
219
222
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
@@ -256,7 +259,7 @@ var analyze_default = ({
|
|
|
256
259
|
},
|
|
257
260
|
resolvedConfig({ resolved }) {
|
|
258
261
|
const appContext = api.useAppContext();
|
|
259
|
-
const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext
|
|
262
|
+
const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext);
|
|
260
263
|
return {
|
|
261
264
|
resolved: config
|
|
262
265
|
};
|
|
@@ -90,7 +90,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
|
90
90
|
});
|
|
91
91
|
};
|
|
92
92
|
const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
|
|
93
|
-
var _a, _b, _c
|
|
93
|
+
var _a, _b, _c;
|
|
94
94
|
if (!(yield import_utils.fs.pathExists(dirname))) {
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
@@ -116,8 +116,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
116
116
|
};
|
|
117
117
|
let pageLoaderFile = "";
|
|
118
118
|
let pageRoute = null;
|
|
119
|
-
let splatLoaderFile = "";
|
|
120
|
-
let splatRoute = null;
|
|
121
119
|
const items = yield import_utils.fs.readdir(dirname);
|
|
122
120
|
for (const item of items) {
|
|
123
121
|
const itemPath = path.join(dirname, item);
|
|
@@ -158,24 +156,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
158
156
|
}
|
|
159
157
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
160
158
|
}
|
|
161
|
-
if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
162
|
-
splatLoaderFile = itemPath;
|
|
163
|
-
}
|
|
164
|
-
if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_FILE) {
|
|
165
|
-
splatRoute = createRoute(
|
|
166
|
-
{
|
|
167
|
-
_component: (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name),
|
|
168
|
-
path: "*"
|
|
169
|
-
},
|
|
170
|
-
rootDir,
|
|
171
|
-
itemPath,
|
|
172
|
-
entryName
|
|
173
|
-
);
|
|
174
|
-
if (splatLoaderFile) {
|
|
175
|
-
splatRoute.loader = splatLoaderFile;
|
|
176
|
-
}
|
|
177
|
-
(_c = route.children) == null ? void 0 : _c.push(splatRoute);
|
|
178
|
-
}
|
|
179
159
|
if (itemWithoutExt === import_constants.NESTED_ROUTE.LOADING_FILE) {
|
|
180
160
|
route.loading = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
181
161
|
}
|
|
@@ -192,7 +172,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
192
172
|
if (isPathlessLayout) {
|
|
193
173
|
delete finalRoute.path;
|
|
194
174
|
}
|
|
195
|
-
route.children = (
|
|
175
|
+
route.children = (_c = route.children) == null ? void 0 : _c.filter((childRoute) => childRoute);
|
|
196
176
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
197
177
|
return null;
|
|
198
178
|
}
|
|
@@ -228,6 +228,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
228
228
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
229
229
|
`;
|
|
230
230
|
let rootLayoutCode = ``;
|
|
231
|
+
let componentLoaderPath = "";
|
|
231
232
|
const getDataLoaderPath = (loaderId) => {
|
|
232
233
|
if (!ssrMode) {
|
|
233
234
|
return "";
|
|
@@ -240,6 +241,12 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
240
241
|
}
|
|
241
242
|
return dataLoaderPath;
|
|
242
243
|
};
|
|
244
|
+
if (ssrMode) {
|
|
245
|
+
componentLoaderPath = `${import_path.default.join(
|
|
246
|
+
__dirname,
|
|
247
|
+
"../builder/loaders/routerLoader"
|
|
248
|
+
)}!`;
|
|
249
|
+
}
|
|
243
250
|
const traverseRouteTree = (route) => {
|
|
244
251
|
var _a;
|
|
245
252
|
let children;
|
|
@@ -275,10 +282,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
275
282
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
276
283
|
component = `RootLayout`;
|
|
277
284
|
} else if (ssrMode === "string") {
|
|
278
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
285
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
|
|
279
286
|
component = `loadable(${lazyImport})`;
|
|
280
287
|
} else {
|
|
281
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
288
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
|
|
282
289
|
component = `lazy(${lazyImport})`;
|
|
283
290
|
}
|
|
284
291
|
}
|
|
@@ -38,39 +38,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
38
38
|
mod
|
|
39
39
|
));
|
|
40
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
-
var
|
|
42
|
-
__export(
|
|
43
|
-
|
|
44
|
-
builderPluginAdapterModern: () => builderPluginAdapterModern
|
|
41
|
+
var compatModern_exports = {};
|
|
42
|
+
__export(compatModern_exports, {
|
|
43
|
+
PluginCompatModern: () => PluginCompatModern
|
|
45
44
|
});
|
|
46
|
-
module.exports = __toCommonJS(
|
|
45
|
+
module.exports = __toCommonJS(compatModern_exports);
|
|
46
|
+
var import_path = require("path");
|
|
47
47
|
var import_builder_shared = require("@modern-js/builder-shared");
|
|
48
|
-
var import_utils = require("@modern-js/utils");
|
|
49
|
-
var import_html_webpack_plugin = __toESM(require("@modern-js/builder-webpack-provider/html-webpack-plugin"));
|
|
50
48
|
var import_lodash = require("@modern-js/utils/lodash");
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
60
|
-
for (const name of Object.keys(server.ssrByEntries)) {
|
|
61
|
-
if (isStreaming(server.ssrByEntries[name])) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
};
|
|
68
|
-
const builderPluginAdapterModern = (options) => ({
|
|
69
|
-
name: "builder-plugin-adapter-modern",
|
|
49
|
+
var import_html_webpack_plugin = __toESM(require("@modern-js/builder-webpack-provider/html-webpack-plugin"));
|
|
50
|
+
var import_utils = require("@modern-js/utils");
|
|
51
|
+
var import_htmlBottomTemplate = require("../webpackPlugins/htmlBottomTemplate");
|
|
52
|
+
var import_htmlAsyncChunkPlugin = require("../webpackPlugins/htmlAsyncChunkPlugin");
|
|
53
|
+
var import_share = require("../share");
|
|
54
|
+
var import_routerPlugin = __toESM(require("../webpackPlugins/routerPlugin"));
|
|
55
|
+
const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
56
|
+
name: "builder-plugin-compat-modern",
|
|
70
57
|
setup(api) {
|
|
71
|
-
const { normalizedConfig, appContext } = options;
|
|
72
58
|
api.modifyBuilderConfig((config) => {
|
|
73
|
-
if (isStreamingSSR(
|
|
59
|
+
if (isStreamingSSR(modernConfig)) {
|
|
74
60
|
return (0, import_builder_shared.mergeBuilderConfig)(config, {
|
|
75
61
|
html: {
|
|
76
62
|
inject: "body"
|
|
@@ -79,8 +65,9 @@ const builderPluginAdapterModern = (options) => ({
|
|
|
79
65
|
}
|
|
80
66
|
return config;
|
|
81
67
|
});
|
|
82
|
-
api.
|
|
83
|
-
|
|
68
|
+
api.modifyWebpackChain((chain, { target, CHAIN_ID, isProd }) => {
|
|
69
|
+
var _a;
|
|
70
|
+
const builderNormalizedConfig = api.getNormalizedConfig();
|
|
84
71
|
if (target === "node") {
|
|
85
72
|
chain.name("server");
|
|
86
73
|
} else if (target === "modern-web") {
|
|
@@ -88,33 +75,61 @@ const builderPluginAdapterModern = (options) => ({
|
|
|
88
75
|
} else {
|
|
89
76
|
chain.name("client");
|
|
90
77
|
}
|
|
78
|
+
chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
|
|
91
79
|
if (target === "node") {
|
|
92
|
-
applyNodeCompat(chain,
|
|
80
|
+
applyNodeCompat(chain, modernConfig, isProd);
|
|
93
81
|
}
|
|
94
|
-
if (isHtmlEnabled(
|
|
95
|
-
|
|
82
|
+
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
83
|
+
applyBottomHtmlWebpackPlugin({
|
|
96
84
|
api,
|
|
97
85
|
chain,
|
|
98
|
-
|
|
86
|
+
CHAIN_ID,
|
|
99
87
|
appContext,
|
|
100
|
-
|
|
88
|
+
modernConfig
|
|
101
89
|
});
|
|
102
90
|
applyAsyncChunkHtmlPlugin({
|
|
103
91
|
chain,
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
CHAIN_ID,
|
|
93
|
+
modernConfig
|
|
106
94
|
});
|
|
107
95
|
}
|
|
96
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
97
|
+
const defaultCopyPattern = (0, import_share.createCopyPattern)(
|
|
98
|
+
appContext,
|
|
99
|
+
modernConfig,
|
|
100
|
+
"public",
|
|
101
|
+
chain
|
|
102
|
+
);
|
|
103
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
104
|
+
var _a2;
|
|
105
|
+
return [
|
|
106
|
+
{
|
|
107
|
+
patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const { entrypoints } = appContext;
|
|
113
|
+
const existNestedRoutes = entrypoints.some(
|
|
114
|
+
(entrypoint) => entrypoint.nestedRoutesEntry
|
|
115
|
+
);
|
|
116
|
+
const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
|
|
117
|
+
const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
|
|
118
|
+
if (existNestedRoutes || routerManifest) {
|
|
119
|
+
chain.plugin("route-plugin").use(import_routerPlugin.default);
|
|
120
|
+
}
|
|
108
121
|
if (target !== "node") {
|
|
109
122
|
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
110
123
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
111
124
|
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
112
125
|
}
|
|
126
|
+
function isHtmlEnabled(config, target2) {
|
|
127
|
+
var _a2;
|
|
128
|
+
return ((_a2 = config.tools) == null ? void 0 : _a2.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
|
|
129
|
+
}
|
|
113
130
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var _a;
|
|
117
|
-
return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "web-worker";
|
|
131
|
+
if (options) {
|
|
132
|
+
applyCallbacks(api, options);
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
135
|
});
|
|
@@ -128,49 +143,6 @@ function applyCallbacks(api, options) {
|
|
|
128
143
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
129
144
|
options.onExit && api.onExit(options.onExit);
|
|
130
145
|
}
|
|
131
|
-
function applyBottomHtmlPlugin({
|
|
132
|
-
api,
|
|
133
|
-
chain,
|
|
134
|
-
modernConfig,
|
|
135
|
-
appContext,
|
|
136
|
-
CHAIN_ID
|
|
137
|
-
}) {
|
|
138
|
-
for (const entryName of Object.keys(api.context.entry)) {
|
|
139
|
-
const baseTemplateParams = __spreadValues({
|
|
140
|
-
entryName,
|
|
141
|
-
title: (0, import_utils.getEntryOptions)(
|
|
142
|
-
entryName,
|
|
143
|
-
modernConfig.html.title,
|
|
144
|
-
modernConfig.html.titleByEntries,
|
|
145
|
-
appContext.packageName
|
|
146
|
-
),
|
|
147
|
-
mountId: modernConfig.html.mountId
|
|
148
|
-
}, (0, import_utils.getEntryOptions)(
|
|
149
|
-
entryName,
|
|
150
|
-
modernConfig.html.templateParameters,
|
|
151
|
-
modernConfig.html.templateParametersByEntries,
|
|
152
|
-
appContext.packageName
|
|
153
|
-
));
|
|
154
|
-
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
155
|
-
__spreadProps(__spreadValues({}, args[0] || {}), {
|
|
156
|
-
__internal__: true,
|
|
157
|
-
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
158
|
-
baseTemplateParams
|
|
159
|
-
)
|
|
160
|
-
})
|
|
161
|
-
]);
|
|
162
|
-
}
|
|
163
|
-
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_HtmlBottomTemplate.BottomTemplatePlugin, [import_html_webpack_plugin.default]);
|
|
164
|
-
}
|
|
165
|
-
function applyAsyncChunkHtmlPlugin({
|
|
166
|
-
chain,
|
|
167
|
-
modernConfig,
|
|
168
|
-
CHAIN_ID
|
|
169
|
-
}) {
|
|
170
|
-
if (isStreamingSSR(modernConfig)) {
|
|
171
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_HtmlAsyncChunkPlugin.HtmlAsyncChunkPlugin, [import_html_webpack_plugin.default]);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
146
|
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
175
147
|
for (const ext of [
|
|
176
148
|
".node.js",
|
|
@@ -222,8 +194,65 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
222
194
|
});
|
|
223
195
|
}
|
|
224
196
|
}
|
|
197
|
+
function applyBottomHtmlWebpackPlugin({
|
|
198
|
+
api,
|
|
199
|
+
chain,
|
|
200
|
+
modernConfig,
|
|
201
|
+
appContext,
|
|
202
|
+
CHAIN_ID
|
|
203
|
+
}) {
|
|
204
|
+
for (const entryName of Object.keys(api.context.entry)) {
|
|
205
|
+
const baseTemplateParams = __spreadValues({
|
|
206
|
+
entryName,
|
|
207
|
+
title: (0, import_utils.getEntryOptions)(
|
|
208
|
+
entryName,
|
|
209
|
+
modernConfig.html.title,
|
|
210
|
+
modernConfig.html.titleByEntries,
|
|
211
|
+
appContext.packageName
|
|
212
|
+
),
|
|
213
|
+
mountId: modernConfig.html.mountId
|
|
214
|
+
}, (0, import_utils.getEntryOptions)(
|
|
215
|
+
entryName,
|
|
216
|
+
modernConfig.html.templateParameters,
|
|
217
|
+
modernConfig.html.templateParametersByEntries,
|
|
218
|
+
appContext.packageName
|
|
219
|
+
));
|
|
220
|
+
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
221
|
+
__spreadProps(__spreadValues({}, args[0] || {}), {
|
|
222
|
+
__internal__: true,
|
|
223
|
+
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
224
|
+
baseTemplateParams
|
|
225
|
+
)
|
|
226
|
+
})
|
|
227
|
+
]);
|
|
228
|
+
}
|
|
229
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_htmlBottomTemplate.BottomTemplatePlugin, [import_html_webpack_plugin.default]);
|
|
230
|
+
}
|
|
231
|
+
const isStreamingSSR = (userConfig) => {
|
|
232
|
+
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
233
|
+
const { server } = userConfig;
|
|
234
|
+
if (isStreaming(server.ssr)) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
238
|
+
for (const name of Object.keys(server.ssrByEntries)) {
|
|
239
|
+
if (isStreaming(server.ssrByEntries[name])) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
};
|
|
246
|
+
function applyAsyncChunkHtmlPlugin({
|
|
247
|
+
chain,
|
|
248
|
+
modernConfig,
|
|
249
|
+
CHAIN_ID
|
|
250
|
+
}) {
|
|
251
|
+
if (isStreamingSSR(modernConfig)) {
|
|
252
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_htmlAsyncChunkPlugin.HtmlAsyncChunkPlugin, [import_html_webpack_plugin.default]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
225
255
|
// Annotate the CommonJS export names for ESM import in node:
|
|
226
256
|
0 && (module.exports = {
|
|
227
|
-
|
|
228
|
-
builderPluginAdapterModern
|
|
257
|
+
PluginCompatModern
|
|
229
258
|
});
|