@modern-js/app-tools 2.10.1-alpha.0 → 2.11.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/CHANGELOG.md +66 -0
- package/dist/cjs/analyze/index.js +1 -1
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +17 -12
- package/dist/cjs/utils/restart.js +1 -1
- package/dist/esm/analyze/index.js +2 -2
- package/dist/esm/builder/index.js +14 -9
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +20 -13
- package/dist/esm/utils/restart.js +2 -2
- package/dist/esm-node/analyze/index.js +3 -2
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +17 -12
- package/dist/esm-node/utils/restart.js +8 -2
- 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/types/config/source.d.ts +2 -2
- package/package.json +24 -24
- 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
|
@@ -17,22 +17,35 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { join } from "path";
|
|
21
20
|
import {
|
|
22
21
|
mergeBuilderConfig
|
|
23
22
|
} from "@modern-js/builder-shared";
|
|
24
|
-
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
25
|
-
import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
|
|
26
23
|
import { getEntryOptions } from "@modern-js/utils";
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import
|
|
31
|
-
const
|
|
32
|
-
|
|
24
|
+
import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
|
|
25
|
+
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
26
|
+
import { HtmlAsyncChunkPlugin } from "../bundlerPlugins/HtmlAsyncChunkPlugin";
|
|
27
|
+
import { BottomTemplatePlugin } from "../bundlerPlugins/HtmlBottomTemplate";
|
|
28
|
+
const isStreamingSSR = (userConfig) => {
|
|
29
|
+
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
30
|
+
const { server } = userConfig;
|
|
31
|
+
if (isStreaming(server.ssr)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
35
|
+
for (const name of Object.keys(server.ssrByEntries)) {
|
|
36
|
+
if (isStreaming(server.ssrByEntries[name])) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
43
|
+
const builderPluginAdapterModern = (options) => ({
|
|
44
|
+
name: "builder-plugin-adapter-modern",
|
|
33
45
|
setup(api) {
|
|
46
|
+
const { normalizedConfig, appContext } = options;
|
|
34
47
|
api.modifyBuilderConfig((config) => {
|
|
35
|
-
if (isStreamingSSR(
|
|
48
|
+
if (isStreamingSSR(normalizedConfig)) {
|
|
36
49
|
return mergeBuilderConfig(config, {
|
|
37
50
|
html: {
|
|
38
51
|
inject: "body"
|
|
@@ -41,71 +54,46 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
41
54
|
}
|
|
42
55
|
return config;
|
|
43
56
|
});
|
|
44
|
-
api.
|
|
45
|
-
|
|
46
|
-
const builderNormalizedConfig = api.getNormalizedConfig();
|
|
57
|
+
api.modifyBundlerChain((chain, { target, CHAIN_ID, isProd }) => {
|
|
58
|
+
const builderConfig = api.getNormalizedConfig();
|
|
47
59
|
if (target === "node") {
|
|
48
60
|
chain.name("server");
|
|
61
|
+
} else if (target === "service-worker") {
|
|
62
|
+
chain.name("service-worker");
|
|
63
|
+
} else if (target === "web-worker") {
|
|
64
|
+
chain.name("worker");
|
|
49
65
|
} else if (target === "modern-web") {
|
|
50
66
|
chain.name("modern");
|
|
51
67
|
} else {
|
|
52
68
|
chain.name("client");
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
applyNodeCompat(chain, modernConfig, isProd);
|
|
70
|
+
if (target === "node" || target === "service-worker") {
|
|
71
|
+
applyNodeCompat(target, chain, normalizedConfig, isProd);
|
|
57
72
|
}
|
|
58
|
-
if (isHtmlEnabled(
|
|
59
|
-
|
|
73
|
+
if (isHtmlEnabled(builderConfig, target)) {
|
|
74
|
+
applyBottomHtmlPlugin({
|
|
60
75
|
api,
|
|
61
76
|
chain,
|
|
62
|
-
|
|
77
|
+
modernConfig: normalizedConfig,
|
|
63
78
|
appContext,
|
|
64
|
-
|
|
79
|
+
CHAIN_ID
|
|
65
80
|
});
|
|
66
81
|
applyAsyncChunkHtmlPlugin({
|
|
67
82
|
chain,
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
modernConfig: normalizedConfig,
|
|
84
|
+
CHAIN_ID
|
|
70
85
|
});
|
|
71
86
|
}
|
|
72
|
-
if (
|
|
73
|
-
const defaultCopyPattern = createCopyPattern(
|
|
74
|
-
appContext,
|
|
75
|
-
modernConfig,
|
|
76
|
-
"public",
|
|
77
|
-
chain
|
|
78
|
-
);
|
|
79
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
80
|
-
var _a2;
|
|
81
|
-
return [
|
|
82
|
-
{
|
|
83
|
-
patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
|
|
84
|
-
}
|
|
85
|
-
];
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const { entrypoints } = appContext;
|
|
89
|
-
const existNestedRoutes = entrypoints.some(
|
|
90
|
-
(entrypoint) => entrypoint.nestedRoutesEntry
|
|
91
|
-
);
|
|
92
|
-
const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
|
|
93
|
-
const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
|
|
94
|
-
if (existNestedRoutes || routerManifest) {
|
|
95
|
-
chain.plugin("route-plugin").use(RouterPlugin);
|
|
96
|
-
}
|
|
97
|
-
if (target !== "node") {
|
|
87
|
+
if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
|
|
98
88
|
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
99
89
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
100
90
|
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
101
91
|
}
|
|
102
|
-
function isHtmlEnabled(config, target2) {
|
|
103
|
-
var _a2;
|
|
104
|
-
return ((_a2 = config.tools) == null ? void 0 : _a2.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
|
|
105
|
-
}
|
|
106
92
|
});
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
applyCallbacks(api, options);
|
|
94
|
+
function isHtmlEnabled(config, target) {
|
|
95
|
+
var _a;
|
|
96
|
+
return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
109
97
|
}
|
|
110
98
|
}
|
|
111
99
|
});
|
|
@@ -119,8 +107,51 @@ function applyCallbacks(api, options) {
|
|
|
119
107
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
120
108
|
options.onExit && api.onExit(options.onExit);
|
|
121
109
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
110
|
+
function applyBottomHtmlPlugin({
|
|
111
|
+
api,
|
|
112
|
+
chain,
|
|
113
|
+
modernConfig,
|
|
114
|
+
appContext,
|
|
115
|
+
CHAIN_ID
|
|
116
|
+
}) {
|
|
117
|
+
for (const entryName of Object.keys(api.context.entry)) {
|
|
118
|
+
const baseTemplateParams = __spreadValues({
|
|
119
|
+
entryName,
|
|
120
|
+
title: getEntryOptions(
|
|
121
|
+
entryName,
|
|
122
|
+
modernConfig.html.title,
|
|
123
|
+
modernConfig.html.titleByEntries,
|
|
124
|
+
appContext.packageName
|
|
125
|
+
),
|
|
126
|
+
mountId: modernConfig.html.mountId
|
|
127
|
+
}, getEntryOptions(
|
|
128
|
+
entryName,
|
|
129
|
+
modernConfig.html.templateParameters,
|
|
130
|
+
modernConfig.html.templateParametersByEntries,
|
|
131
|
+
appContext.packageName
|
|
132
|
+
));
|
|
133
|
+
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
134
|
+
__spreadProps(__spreadValues({}, args[0] || {}), {
|
|
135
|
+
__internal__: true,
|
|
136
|
+
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
137
|
+
baseTemplateParams
|
|
138
|
+
)
|
|
139
|
+
})
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
143
|
+
}
|
|
144
|
+
function applyAsyncChunkHtmlPlugin({
|
|
145
|
+
chain,
|
|
146
|
+
modernConfig,
|
|
147
|
+
CHAIN_ID
|
|
148
|
+
}) {
|
|
149
|
+
if (isStreamingSSR(modernConfig)) {
|
|
150
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function applyNodeCompat(target, chain, modernConfig, isProd) {
|
|
154
|
+
const nodeExts = [
|
|
124
155
|
".node.js",
|
|
125
156
|
".node.jsx",
|
|
126
157
|
".node.ts",
|
|
@@ -129,9 +160,21 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
129
160
|
".server.ts",
|
|
130
161
|
".server.ts",
|
|
131
162
|
".server.tsx"
|
|
132
|
-
]
|
|
163
|
+
];
|
|
164
|
+
const webWorkerExts = [
|
|
165
|
+
".worker.js",
|
|
166
|
+
".worker.jsx",
|
|
167
|
+
".worker.ts",
|
|
168
|
+
".worker.tsx"
|
|
169
|
+
];
|
|
170
|
+
for (const ext of nodeExts) {
|
|
133
171
|
chain.resolve.extensions.prepend(ext);
|
|
134
172
|
}
|
|
173
|
+
if (target === "service-worker") {
|
|
174
|
+
for (const ext of webWorkerExts) {
|
|
175
|
+
chain.resolve.extensions.prepend(ext);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
135
178
|
filterEntriesBySSRConfig(
|
|
136
179
|
isProd,
|
|
137
180
|
chain,
|
|
@@ -170,64 +213,7 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
170
213
|
});
|
|
171
214
|
}
|
|
172
215
|
}
|
|
173
|
-
function applyBottomHtmlWebpackPlugin({
|
|
174
|
-
api,
|
|
175
|
-
chain,
|
|
176
|
-
modernConfig,
|
|
177
|
-
appContext,
|
|
178
|
-
CHAIN_ID
|
|
179
|
-
}) {
|
|
180
|
-
for (const entryName of Object.keys(api.context.entry)) {
|
|
181
|
-
const baseTemplateParams = __spreadValues({
|
|
182
|
-
entryName,
|
|
183
|
-
title: getEntryOptions(
|
|
184
|
-
entryName,
|
|
185
|
-
modernConfig.html.title,
|
|
186
|
-
modernConfig.html.titleByEntries,
|
|
187
|
-
appContext.packageName
|
|
188
|
-
),
|
|
189
|
-
mountId: modernConfig.html.mountId
|
|
190
|
-
}, getEntryOptions(
|
|
191
|
-
entryName,
|
|
192
|
-
modernConfig.html.templateParameters,
|
|
193
|
-
modernConfig.html.templateParametersByEntries,
|
|
194
|
-
appContext.packageName
|
|
195
|
-
));
|
|
196
|
-
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
197
|
-
__spreadProps(__spreadValues({}, args[0] || {}), {
|
|
198
|
-
__internal__: true,
|
|
199
|
-
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
200
|
-
baseTemplateParams
|
|
201
|
-
)
|
|
202
|
-
})
|
|
203
|
-
]);
|
|
204
|
-
}
|
|
205
|
-
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
206
|
-
}
|
|
207
|
-
const isStreamingSSR = (userConfig) => {
|
|
208
|
-
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
209
|
-
const { server } = userConfig;
|
|
210
|
-
if (isStreaming(server.ssr)) {
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
214
|
-
for (const name of Object.keys(server.ssrByEntries)) {
|
|
215
|
-
if (isStreaming(server.ssrByEntries[name])) {
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return false;
|
|
221
|
-
};
|
|
222
|
-
function applyAsyncChunkHtmlPlugin({
|
|
223
|
-
chain,
|
|
224
|
-
modernConfig,
|
|
225
|
-
CHAIN_ID
|
|
226
|
-
}) {
|
|
227
|
-
if (isStreamingSSR(modernConfig)) {
|
|
228
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
216
|
export {
|
|
232
|
-
|
|
217
|
+
applyCallbacks,
|
|
218
|
+
builderPluginAdapterModern
|
|
233
219
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class HtmlAsyncChunkPlugin {
|
|
2
|
+
constructor(htmlWebpackPlugin) {
|
|
3
|
+
this.name = "HtmlAsyncChunkPlugin";
|
|
4
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
5
|
+
}
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
8
|
+
const hooks = this.htmlWebpackPlugin.getHooks(compilation);
|
|
9
|
+
hooks.alterAssetTagGroups.tap(this.name, (assets) => {
|
|
10
|
+
const tags = [...assets.headTags, ...assets.bodyTags];
|
|
11
|
+
for (const tag of tags) {
|
|
12
|
+
if (tag.tagName === "script") {
|
|
13
|
+
const { attributes } = tag;
|
|
14
|
+
if (attributes && attributes.defer === true) {
|
|
15
|
+
attributes.async = true;
|
|
16
|
+
delete attributes.defer;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return assets;
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
HtmlAsyncChunkPlugin
|
|
27
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class BottomTemplatePlugin {
|
|
2
|
+
constructor(htmlWebpackPlugin) {
|
|
3
|
+
this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
|
|
4
|
+
this.bodyRegExp = /(<\/\s*body\s*>)/i;
|
|
5
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
6
|
+
this.name = "bottom-template";
|
|
7
|
+
}
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
10
|
+
this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
|
|
11
|
+
var _a;
|
|
12
|
+
if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
if (this.bottomTemplateReg.test(data.html)) {
|
|
16
|
+
data.html = data.html.replace(this.bottomTemplateReg, "");
|
|
17
|
+
const { bottomTemplate } = data.plugin.options;
|
|
18
|
+
if (bottomTemplate) {
|
|
19
|
+
data.html = data.html.replace(
|
|
20
|
+
this.bodyRegExp,
|
|
21
|
+
(match) => `
|
|
22
|
+
${bottomTemplate}
|
|
23
|
+
${match}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
BottomTemplatePlugin
|
|
34
|
+
};
|
|
File without changes
|
|
@@ -18,12 +18,11 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
21
|
-
function createDefaultConfig(appContext) {
|
|
21
|
+
function createDefaultConfig(appContext, bundler) {
|
|
22
22
|
const defaultBuilderConfig = createDefaultBuilderConfig();
|
|
23
23
|
const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
|
|
24
24
|
port: void 0
|
|
25
25
|
});
|
|
26
|
-
const tools = __spreadValues({}, defaultBuilderConfig.tools);
|
|
27
26
|
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
28
27
|
disableNodePolyfill: true
|
|
29
28
|
});
|
|
@@ -61,6 +60,7 @@ function createDefaultConfig(appContext) {
|
|
|
61
60
|
baseUrl: "/",
|
|
62
61
|
port: 8080
|
|
63
62
|
};
|
|
63
|
+
const tools = bundler === "webpack" ? __spreadValues({}, defaultBuilderConfig.tools) : void 0;
|
|
64
64
|
return {
|
|
65
65
|
source,
|
|
66
66
|
output,
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
checkIsLegacyConfig,
|
|
5
|
-
createDefaultConfig,
|
|
6
|
-
createLegacyDefaultConfig,
|
|
7
|
-
initialNormalizedConfig
|
|
8
|
-
};
|
|
1
|
+
export * from "./legacy";
|
|
2
|
+
export * from "./initialize";
|
|
3
|
+
export * from "./default";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { initHtmlConfig, initSourceConfig, initToolsConfig } from "./inits";
|
|
2
|
+
function initialNormalizedConfig(config, appContext, bundler) {
|
|
3
|
+
initHtmlConfig(config, appContext);
|
|
4
|
+
initSourceConfig(config, appContext, bundler);
|
|
5
|
+
if (bundler === "webpack") {
|
|
6
|
+
initToolsConfig(config);
|
|
7
|
+
}
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
initialNormalizedConfig
|
|
12
|
+
};
|
|
@@ -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)) {
|