@modern-js/app-tools 2.5.1-alpha.0 → 2.5.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/analyze/generateCode.js +19 -13
- package/dist/cjs/analyze/getBundleEntry.js +1 -1
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +3 -3
- package/dist/cjs/builder/builder-webpack/index.js +11 -5
- package/dist/cjs/builder/generator/getBuilderTargets.js +1 -1
- package/dist/cjs/commands/dev.js +12 -14
- package/dist/cjs/commands/serve.js +17 -0
- package/dist/cjs/config/legacy/createToolsConfig.js +1 -4
- package/dist/esm/analyze/generateCode.js +37 -26
- package/dist/esm/analyze/getBundleEntry.js +2 -2
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm/builder/builder-webpack/index.js +11 -7
- package/dist/esm/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm/commands/dev.js +9 -8
- package/dist/esm/commands/serve.js +6 -1
- package/dist/esm/config/legacy/createToolsConfig.js +1 -4
- package/dist/esm-node/analyze/generateCode.js +20 -14
- package/dist/esm-node/analyze/getBundleEntry.js +2 -3
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm-node/builder/builder-webpack/index.js +12 -6
- package/dist/esm-node/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm-node/commands/dev.js +12 -14
- package/dist/esm-node/commands/serve.js +18 -1
- package/dist/esm-node/config/legacy/createToolsConfig.js +1 -4
- package/dist/js/modern/analyze/constants.js +3 -1
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +47 -46
- package/dist/js/modern/analyze/nestedRoutes.js +32 -3
- package/dist/js/modern/analyze/templates.js +4 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +48 -47
- package/dist/js/node/analyze/nestedRoutes.js +32 -3
- package/dist/js/node/analyze/templates.js +4 -10
- package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
- package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +3 -1
- package/dist/js/treeshaking/analyze/generateCode.js +14 -14
- package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
- package/dist/js/treeshaking/analyze/index.js +142 -137
- package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -13
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +36 -28
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/builder/builder-webpack/builderPlugins/compatModern.d.ts +7 -1
- package/package.json +6 -6
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
|
@@ -59,10 +59,12 @@ function initHtmlConfig(config, appContext) {
|
|
|
59
59
|
return favicon || defaultFavicon || void 0;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
function initSourceConfig(config, appContext) {
|
|
62
|
+
function initSourceConfig(config, appContext, bundler) {
|
|
63
63
|
config.source.include = createBuilderInclude(config, appContext);
|
|
64
|
-
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
65
64
|
config.source.globalVars = createBuilderGlobalVars(config, appContext);
|
|
65
|
+
if (bundler === "webpack") {
|
|
66
|
+
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
67
|
+
}
|
|
66
68
|
function createBuilderGlobalVars(config2, appContext2) {
|
|
67
69
|
const { globalVars = {} } = config2.source;
|
|
68
70
|
const publicEnv = getAutoInjectEnv(appContext2);
|
package/dist/js/modern/index.js
CHANGED
|
@@ -103,7 +103,9 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
-
var src_default = (
|
|
106
|
+
var src_default = (options = {
|
|
107
|
+
bundler: "webpack"
|
|
108
|
+
}) => ({
|
|
107
109
|
name: "@modern-js/app-tools",
|
|
108
110
|
post: [
|
|
109
111
|
"@modern-js/plugin-initialize",
|
|
@@ -116,7 +118,15 @@ var src_default = () => ({
|
|
|
116
118
|
"@modern-js/plugin-polyfill"
|
|
117
119
|
],
|
|
118
120
|
registerHook: hooks,
|
|
119
|
-
usePlugins: [
|
|
121
|
+
usePlugins: [
|
|
122
|
+
initializePlugin({
|
|
123
|
+
bundler: (options == null ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
124
|
+
}),
|
|
125
|
+
analyzePlugin({
|
|
126
|
+
bundler: (options == null ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
127
|
+
}),
|
|
128
|
+
lintPlugin()
|
|
129
|
+
],
|
|
120
130
|
setup: (api) => {
|
|
121
131
|
const locale = getLocaleLanguage();
|
|
122
132
|
i18n.changeLanguage({ locale });
|
|
@@ -135,19 +145,19 @@ var src_default = () => ({
|
|
|
135
145
|
program.command("deploy").usage("[options]").option(
|
|
136
146
|
"-c --config <config>",
|
|
137
147
|
i18n.t(localeKeys.command.shared.config)
|
|
138
|
-
).description(i18n.t(localeKeys.command.deploy.describe)).action((
|
|
148
|
+
).description(i18n.t(localeKeys.command.deploy.describe)).action((options2) => __async(this, null, function* () {
|
|
139
149
|
const { build } = yield import("./commands/build");
|
|
140
150
|
yield build(api);
|
|
141
151
|
const { deploy } = yield import("./commands/deploy");
|
|
142
|
-
yield deploy(api,
|
|
152
|
+
yield deploy(api, options2);
|
|
143
153
|
process.exit(0);
|
|
144
154
|
}));
|
|
145
155
|
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option(
|
|
146
156
|
"-c, --config <config>",
|
|
147
157
|
i18n.t(localeKeys.command.new.config)
|
|
148
|
-
).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action((
|
|
158
|
+
).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action((options2) => __async(this, null, function* () {
|
|
149
159
|
const { MWANewAction } = yield import("@modern-js/new-action");
|
|
150
|
-
yield MWANewAction(__spreadProps(__spreadValues({},
|
|
160
|
+
yield MWANewAction(__spreadProps(__spreadValues({}, options2), { locale: options2.lang || locale }));
|
|
151
161
|
}));
|
|
152
162
|
program.command("inspect").description("inspect internal webpack config").option(
|
|
153
163
|
`--env <env>`,
|
|
@@ -160,9 +170,9 @@ var src_default = () => ({
|
|
|
160
170
|
).option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option(
|
|
161
171
|
"-c --config <config>",
|
|
162
172
|
i18n.t(localeKeys.command.shared.config)
|
|
163
|
-
).action((
|
|
173
|
+
).action((options2) => __async(this, null, function* () {
|
|
164
174
|
const { inspect } = yield import("./commands/inspect");
|
|
165
|
-
inspect(api,
|
|
175
|
+
inspect(api, options2);
|
|
166
176
|
}));
|
|
167
177
|
upgradeModel.defineCommand(program.command("upgrade"));
|
|
168
178
|
});
|
|
@@ -44,19 +44,21 @@ import {
|
|
|
44
44
|
isDevCommand
|
|
45
45
|
} from "@modern-js/utils";
|
|
46
46
|
import { legacySchema, schema } from "../schema";
|
|
47
|
-
import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
|
|
48
47
|
import {
|
|
49
48
|
checkIsLegacyConfig,
|
|
50
49
|
createDefaultConfig,
|
|
51
|
-
createLegacyDefaultConfig
|
|
50
|
+
createLegacyDefaultConfig,
|
|
51
|
+
transformNormalizedConfig
|
|
52
52
|
} from "../config";
|
|
53
|
-
var initialize_default = (
|
|
53
|
+
var initialize_default = ({
|
|
54
|
+
bundler
|
|
55
|
+
}) => ({
|
|
54
56
|
name: "@modern-js/plugin-initialize",
|
|
55
57
|
setup(api) {
|
|
56
58
|
const config = () => {
|
|
57
59
|
const appContext = api.useAppContext();
|
|
58
60
|
const userConfig = api.useConfigContext();
|
|
59
|
-
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
|
|
61
|
+
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext, bundler);
|
|
60
62
|
};
|
|
61
63
|
const validateSchema = () => {
|
|
62
64
|
const userConfig = api.useConfigContext();
|
|
@@ -81,35 +83,41 @@ var initialize_default = () => ({
|
|
|
81
83
|
});
|
|
82
84
|
api.setAppContext(appContext);
|
|
83
85
|
const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
86
|
+
resolved._raw = userConfig;
|
|
87
|
+
resolved.server = __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
|
|
88
|
+
port
|
|
89
|
+
});
|
|
90
|
+
resolved.autoLoadPlugins = normalizedConfig.autoLoadPlugins || false;
|
|
91
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
|
92
|
+
"source",
|
|
93
|
+
"bff",
|
|
94
|
+
"dev",
|
|
95
|
+
"html",
|
|
96
|
+
"output",
|
|
97
|
+
"tools",
|
|
98
|
+
"testing",
|
|
99
|
+
"plugins",
|
|
100
|
+
"builderPlugins",
|
|
101
|
+
"runtime",
|
|
102
|
+
"runtimeByEntries",
|
|
103
|
+
"deploy",
|
|
104
|
+
"performance"
|
|
105
|
+
]);
|
|
106
|
+
if (bundler === "webpack") {
|
|
107
|
+
resolved.security = normalizedConfig.security || {};
|
|
108
|
+
resolved.experiments = normalizedConfig.experiments;
|
|
109
|
+
}
|
|
110
|
+
return { resolved };
|
|
108
111
|
});
|
|
109
112
|
}
|
|
110
113
|
};
|
|
111
114
|
}
|
|
112
115
|
});
|
|
116
|
+
function stabilizeConfig(resolve, config, keys) {
|
|
117
|
+
keys.forEach((key) => {
|
|
118
|
+
resolve[key] = config[key] || {};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
113
121
|
function getServerPort(config) {
|
|
114
122
|
return __async(this, null, function* () {
|
|
115
123
|
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: "Web App 项目中执行生成器",
|
|
21
21
|
debug: "开启 Debug 模式,打印调试日志信息",
|
|
22
22
|
config: "生成器运行默认配置(JSON 字符串)",
|
|
23
23
|
distTag: "生成器使用特殊的 npm Tag 版本",
|
|
File without changes
|
|
@@ -66,7 +66,9 @@ const NESTED_ROUTE = {
|
|
|
66
66
|
PAGE_LOADER_FILE: "page.loader",
|
|
67
67
|
LOADING_FILE: "loading",
|
|
68
68
|
ERROR_FILE: "error",
|
|
69
|
-
LOADER_FILE: "loader"
|
|
69
|
+
LOADER_FILE: "loader",
|
|
70
|
+
SPLATE_FILE: "$",
|
|
71
|
+
SPLATE_LOADER_FILE: "$.loader"
|
|
70
72
|
};
|
|
71
73
|
const APP_CONFIG_NAME = "config";
|
|
72
74
|
const APP_INIT_EXPORTED = "init";
|
|
@@ -119,7 +119,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
119
119
|
const {
|
|
120
120
|
html: { disableHtmlFolder },
|
|
121
121
|
output: { distPath: { html: htmlPath } = {} },
|
|
122
|
-
server: { baseUrl, routes, ssr, ssrByEntries }
|
|
122
|
+
server: { baseUrl, routes, ssr, ssrByEntries, worker }
|
|
123
123
|
} = config;
|
|
124
124
|
const { packageName } = appContext;
|
|
125
125
|
let htmlRoutes = entrypoints.reduce(
|
|
@@ -131,6 +131,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
131
131
|
packageName
|
|
132
132
|
);
|
|
133
133
|
const isSSR = Boolean(entryOptions);
|
|
134
|
+
const isWorker = Boolean(worker);
|
|
134
135
|
const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
|
|
135
136
|
let route = {
|
|
136
137
|
urlPath: `/${entryName === import_utils.MAIN_ENTRY_NAME ? "" : entryName}`,
|
|
@@ -143,6 +144,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
143
144
|
isSPA: true,
|
|
144
145
|
isSSR,
|
|
145
146
|
responseHeaders: resHeaders,
|
|
147
|
+
worker: isWorker ? `${import_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
|
|
146
148
|
bundle: isSSR ? `${import_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
|
|
147
149
|
};
|
|
148
150
|
if (routes == null ? void 0 : routes.hasOwnProperty(entryName)) {
|
|
@@ -66,16 +66,18 @@ 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");
|
|
70
69
|
var import_printInstructions = require("../utils/printInstructions");
|
|
71
70
|
var import_routes = require("../utils/routes");
|
|
72
71
|
var import_config = require("../utils/config");
|
|
73
72
|
var import_getSelectedEntries = require("../utils/getSelectedEntries");
|
|
74
73
|
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 = (
|
|
78
|
+
var analyze_default = ({
|
|
79
|
+
bundler
|
|
80
|
+
}) => ({
|
|
79
81
|
name: "@modern-js/plugin-analyze",
|
|
80
82
|
setup: (api) => {
|
|
81
83
|
let pagesDir = [];
|
|
@@ -167,56 +169,55 @@ var analyze_default = () => ({
|
|
|
167
169
|
if (buildCommands.includes(command)) {
|
|
168
170
|
let _b;
|
|
169
171
|
const normalizedConfig = api.useResolvedConfigContext();
|
|
170
|
-
const
|
|
172
|
+
const createBuilderForModern = yield (0, import_builder.createBuilderGenerator)(bundler);
|
|
173
|
+
const builder = yield createBuilderForModern({
|
|
171
174
|
normalizedConfig,
|
|
172
175
|
appContext,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
);
|
|
176
|
+
onBeforeBuild(_0) {
|
|
177
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
178
|
+
const hookRunners2 = api.useHookRunners();
|
|
179
|
+
yield (0, import_routes.generateRoutes)(appContext);
|
|
180
|
+
yield hookRunners2.beforeBuild({
|
|
181
|
+
bundlerConfigs
|
|
189
182
|
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
onAfterBuild(_0) {
|
|
186
|
+
return __async(this, arguments, function* ({ stats }) {
|
|
187
|
+
const hookRunners2 = api.useHookRunners();
|
|
188
|
+
yield hookRunners2.afterBuild({ stats });
|
|
189
|
+
yield (0, import_config.emitResolvedConfig)(
|
|
190
|
+
appContext.appDirectory,
|
|
191
|
+
normalizedConfig
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
onDevCompileDone(_0) {
|
|
196
|
+
return __async(this, arguments, function* ({ isFirstCompile }) {
|
|
197
|
+
const hookRunners2 = api.useHookRunners();
|
|
198
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
199
|
+
hookRunners2.afterDev();
|
|
200
|
+
if (isFirstCompile) {
|
|
201
|
+
(0, import_printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
|
|
203
202
|
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
onBeforeCreateCompiler(_0) {
|
|
207
|
+
return __async(this, arguments, function* ({ bundlerConfigs }) {
|
|
208
|
+
const hookRunners2 = api.useHookRunners();
|
|
209
|
+
yield hookRunners2.beforeCreateCompiler({
|
|
210
|
+
bundlerConfigs
|
|
204
211
|
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
213
|
-
},
|
|
214
|
-
onAfterCreateCompiler(_0) {
|
|
215
|
-
return __async(this, arguments, function* ({ compiler }) {
|
|
216
|
-
const hookRunners2 = api.useHookRunners();
|
|
217
|
-
yield hookRunners2.afterCreateCompiler({ compiler });
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
onAfterCreateCompiler(_0) {
|
|
215
|
+
return __async(this, arguments, function* ({ compiler }) {
|
|
216
|
+
const hookRunners2 = api.useHookRunners();
|
|
217
|
+
yield hookRunners2.afterCreateCompiler({
|
|
218
|
+
compiler
|
|
218
219
|
});
|
|
219
|
-
}
|
|
220
|
+
});
|
|
220
221
|
}
|
|
221
222
|
});
|
|
222
223
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
@@ -259,7 +260,7 @@ var analyze_default = () => ({
|
|
|
259
260
|
},
|
|
260
261
|
resolvedConfig({ resolved }) {
|
|
261
262
|
const appContext = api.useAppContext();
|
|
262
|
-
const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext);
|
|
263
|
+
const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext, bundler);
|
|
263
264
|
return {
|
|
264
265
|
resolved: config
|
|
265
266
|
};
|
|
@@ -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, _d;
|
|
94
94
|
if (!(yield import_utils.fs.pathExists(dirname))) {
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
@@ -116,6 +116,8 @@ 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;
|
|
119
121
|
const items = yield import_utils.fs.readdir(dirname);
|
|
120
122
|
for (const item of items) {
|
|
121
123
|
const itemPath = path.join(dirname, item);
|
|
@@ -156,6 +158,24 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
156
158
|
}
|
|
157
159
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
158
160
|
}
|
|
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
|
+
}
|
|
159
179
|
if (itemWithoutExt === import_constants.NESTED_ROUTE.LOADING_FILE) {
|
|
160
180
|
route.loading = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
161
181
|
}
|
|
@@ -163,7 +183,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
163
183
|
route.error = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
164
184
|
}
|
|
165
185
|
}
|
|
166
|
-
|
|
186
|
+
let finalRoute = createRoute(
|
|
167
187
|
route,
|
|
168
188
|
rootDir,
|
|
169
189
|
path.join(dirname, `${import_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
@@ -172,10 +192,19 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
172
192
|
if (isPathlessLayout) {
|
|
173
193
|
delete finalRoute.path;
|
|
174
194
|
}
|
|
175
|
-
route.children = (
|
|
195
|
+
route.children = (_d = route.children) == null ? void 0 : _d.filter((childRoute) => childRoute);
|
|
176
196
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
177
197
|
return null;
|
|
178
198
|
}
|
|
199
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
200
|
+
const childRoute = finalRoute.children[0];
|
|
201
|
+
if (childRoute.path === "*") {
|
|
202
|
+
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
203
|
+
finalRoute = __spreadProps(__spreadValues({}, childRoute), {
|
|
204
|
+
path: path2
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
179
208
|
return finalRoute;
|
|
180
209
|
});
|
|
181
210
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -99,6 +99,7 @@ const renderFunction = ({
|
|
|
99
99
|
customBootstrap,
|
|
100
100
|
fileSystemRoutes: fileSystemRoutes2
|
|
101
101
|
}) => {
|
|
102
|
+
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
|
102
103
|
return `
|
|
103
104
|
const finalAppConfig = {
|
|
104
105
|
...App.config,
|
|
@@ -120,7 +121,7 @@ const renderFunction = ({
|
|
|
120
121
|
|
|
121
122
|
|
|
122
123
|
if (IS_BROWSER) {
|
|
123
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` :
|
|
124
|
+
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
return AppWrapper
|
|
@@ -228,7 +229,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
228
229
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
229
230
|
`;
|
|
230
231
|
let rootLayoutCode = ``;
|
|
231
|
-
let componentLoaderPath = "";
|
|
232
232
|
const getDataLoaderPath = (loaderId) => {
|
|
233
233
|
if (!ssrMode) {
|
|
234
234
|
return "";
|
|
@@ -241,12 +241,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
241
241
|
}
|
|
242
242
|
return dataLoaderPath;
|
|
243
243
|
};
|
|
244
|
-
if (ssrMode) {
|
|
245
|
-
componentLoaderPath = `${import_path.default.join(
|
|
246
|
-
__dirname,
|
|
247
|
-
"../builder/loaders/routerLoader"
|
|
248
|
-
)}!`;
|
|
249
|
-
}
|
|
250
244
|
const traverseRouteTree = (route) => {
|
|
251
245
|
var _a;
|
|
252
246
|
let children;
|
|
@@ -282,10 +276,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
282
276
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
283
277
|
component = `RootLayout`;
|
|
284
278
|
} else if (ssrMode === "string") {
|
|
285
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
279
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
286
280
|
component = `loadable(${lazyImport})`;
|
|
287
281
|
} else {
|
|
288
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
282
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
289
283
|
component = `lazy(${lazyImport})`;
|
|
290
284
|
}
|
|
291
285
|
}
|
|
@@ -15,27 +15,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
-
|
|
21
|
-
initialNormalizedConfig: () => initialNormalizedConfig,
|
|
22
|
-
transformNormalizedConfig: () => import_transformNormalizedConfig.transformNormalizedConfig
|
|
18
|
+
var builder_rspack_exports = {};
|
|
19
|
+
__export(builder_rspack_exports, {
|
|
20
|
+
createRspackBuilderForModern: () => createRspackBuilderForModern
|
|
23
21
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
function
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
function initialNormalizedConfig(config, appContext) {
|
|
31
|
-
(0, import_inits.initHtmlConfig)(config, appContext);
|
|
32
|
-
(0, import_inits.initSourceConfig)(config, appContext);
|
|
33
|
-
(0, import_inits.initToolsConfig)(config);
|
|
34
|
-
return config;
|
|
22
|
+
module.exports = __toCommonJS(builder_rspack_exports);
|
|
23
|
+
var import_builder_rspack_provider = require("@modern-js/builder-rspack-provider");
|
|
24
|
+
var import_generator = require("../generator");
|
|
25
|
+
function createRspackBuilderForModern(options) {
|
|
26
|
+
return (0, import_generator.generateBuilder)(options, import_builder_rspack_provider.builderRspackProvider);
|
|
35
27
|
}
|
|
36
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
29
|
0 && (module.exports = {
|
|
38
|
-
|
|
39
|
-
initialNormalizedConfig,
|
|
40
|
-
transformNormalizedConfig
|
|
30
|
+
createRspackBuilderForModern
|
|
41
31
|
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var compatModern_exports = {};
|
|
19
|
+
__export(compatModern_exports, {
|
|
20
|
+
PluginCompatModern: () => PluginCompatModern
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(compatModern_exports);
|
|
23
|
+
var import_path = require("path");
|
|
24
|
+
var import_shared = require("../../shared");
|
|
25
|
+
var import_webpackPlugins = require("../webpackPlugins");
|
|
26
|
+
const PluginCompatModern = (options) => ({
|
|
27
|
+
name: "builder-plugin-compat-modern",
|
|
28
|
+
setup(api) {
|
|
29
|
+
const { normalizedConfig: modernConfig, appContext } = options;
|
|
30
|
+
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
31
|
+
var _a;
|
|
32
|
+
chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
|
|
33
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
34
|
+
const defaultCopyPattern = (0, import_shared.createCopyPattern)(
|
|
35
|
+
appContext,
|
|
36
|
+
modernConfig,
|
|
37
|
+
"public",
|
|
38
|
+
chain
|
|
39
|
+
);
|
|
40
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
41
|
+
var _a2;
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const { entrypoints } = appContext;
|
|
50
|
+
const existNestedRoutes = entrypoints.some(
|
|
51
|
+
(entrypoint) => entrypoint.nestedRoutesEntry
|
|
52
|
+
);
|
|
53
|
+
const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
|
|
54
|
+
const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
|
|
55
|
+
if (existNestedRoutes || routerManifest) {
|
|
56
|
+
chain.plugin("route-plugin").use(import_webpackPlugins.RouterPlugin);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
PluginCompatModern
|
|
64
|
+
});
|