@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
|
@@ -17,35 +17,22 @@ 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";
|
|
20
21
|
import {
|
|
21
22
|
mergeBuilderConfig
|
|
22
23
|
} from "@modern-js/builder-shared";
|
|
23
|
-
import { getEntryOptions } from "@modern-js/utils";
|
|
24
|
-
import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
|
|
25
24
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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",
|
|
25
|
+
import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
|
|
26
|
+
import { getEntryOptions } from "@modern-js/utils";
|
|
27
|
+
import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
|
|
28
|
+
import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
|
|
29
|
+
import { createCopyPattern } from "../share";
|
|
30
|
+
import RouterPlugin from "../webpackPlugins/routerPlugin";
|
|
31
|
+
const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
32
|
+
name: "builder-plugin-compat-modern",
|
|
45
33
|
setup(api) {
|
|
46
|
-
const { normalizedConfig, appContext } = options;
|
|
47
34
|
api.modifyBuilderConfig((config) => {
|
|
48
|
-
if (isStreamingSSR(
|
|
35
|
+
if (isStreamingSSR(modernConfig)) {
|
|
49
36
|
return mergeBuilderConfig(config, {
|
|
50
37
|
html: {
|
|
51
38
|
inject: "body"
|
|
@@ -54,8 +41,9 @@ const builderPluginAdapterModern = (options) => ({
|
|
|
54
41
|
}
|
|
55
42
|
return config;
|
|
56
43
|
});
|
|
57
|
-
api.
|
|
58
|
-
|
|
44
|
+
api.modifyWebpackChain((chain, { target, CHAIN_ID, isProd }) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const builderNormalizedConfig = api.getNormalizedConfig();
|
|
59
47
|
if (target === "node") {
|
|
60
48
|
chain.name("server");
|
|
61
49
|
} else if (target === "modern-web") {
|
|
@@ -63,33 +51,61 @@ const builderPluginAdapterModern = (options) => ({
|
|
|
63
51
|
} else {
|
|
64
52
|
chain.name("client");
|
|
65
53
|
}
|
|
54
|
+
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
66
55
|
if (target === "node") {
|
|
67
|
-
applyNodeCompat(chain,
|
|
56
|
+
applyNodeCompat(chain, modernConfig, isProd);
|
|
68
57
|
}
|
|
69
|
-
if (isHtmlEnabled(
|
|
70
|
-
|
|
58
|
+
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
59
|
+
applyBottomHtmlWebpackPlugin({
|
|
71
60
|
api,
|
|
72
61
|
chain,
|
|
73
|
-
|
|
62
|
+
CHAIN_ID,
|
|
74
63
|
appContext,
|
|
75
|
-
|
|
64
|
+
modernConfig
|
|
76
65
|
});
|
|
77
66
|
applyAsyncChunkHtmlPlugin({
|
|
78
67
|
chain,
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
CHAIN_ID,
|
|
69
|
+
modernConfig
|
|
81
70
|
});
|
|
82
71
|
}
|
|
72
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
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
|
+
}
|
|
83
97
|
if (target !== "node") {
|
|
84
98
|
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
85
99
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
86
100
|
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
87
101
|
}
|
|
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
|
+
}
|
|
88
106
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var _a;
|
|
92
|
-
return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "web-worker";
|
|
107
|
+
if (options) {
|
|
108
|
+
applyCallbacks(api, options);
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
});
|
|
@@ -103,49 +119,6 @@ function applyCallbacks(api, options) {
|
|
|
103
119
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
104
120
|
options.onExit && api.onExit(options.onExit);
|
|
105
121
|
}
|
|
106
|
-
function applyBottomHtmlPlugin({
|
|
107
|
-
api,
|
|
108
|
-
chain,
|
|
109
|
-
modernConfig,
|
|
110
|
-
appContext,
|
|
111
|
-
CHAIN_ID
|
|
112
|
-
}) {
|
|
113
|
-
for (const entryName of Object.keys(api.context.entry)) {
|
|
114
|
-
const baseTemplateParams = __spreadValues({
|
|
115
|
-
entryName,
|
|
116
|
-
title: getEntryOptions(
|
|
117
|
-
entryName,
|
|
118
|
-
modernConfig.html.title,
|
|
119
|
-
modernConfig.html.titleByEntries,
|
|
120
|
-
appContext.packageName
|
|
121
|
-
),
|
|
122
|
-
mountId: modernConfig.html.mountId
|
|
123
|
-
}, getEntryOptions(
|
|
124
|
-
entryName,
|
|
125
|
-
modernConfig.html.templateParameters,
|
|
126
|
-
modernConfig.html.templateParametersByEntries,
|
|
127
|
-
appContext.packageName
|
|
128
|
-
));
|
|
129
|
-
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
130
|
-
__spreadProps(__spreadValues({}, args[0] || {}), {
|
|
131
|
-
__internal__: true,
|
|
132
|
-
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
133
|
-
baseTemplateParams
|
|
134
|
-
)
|
|
135
|
-
})
|
|
136
|
-
]);
|
|
137
|
-
}
|
|
138
|
-
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
139
|
-
}
|
|
140
|
-
function applyAsyncChunkHtmlPlugin({
|
|
141
|
-
chain,
|
|
142
|
-
modernConfig,
|
|
143
|
-
CHAIN_ID
|
|
144
|
-
}) {
|
|
145
|
-
if (isStreamingSSR(modernConfig)) {
|
|
146
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
122
|
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
150
123
|
for (const ext of [
|
|
151
124
|
".node.js",
|
|
@@ -197,7 +170,64 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
197
170
|
});
|
|
198
171
|
}
|
|
199
172
|
}
|
|
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
|
+
}
|
|
200
231
|
export {
|
|
201
|
-
|
|
202
|
-
builderPluginAdapterModern
|
|
232
|
+
PluginCompatModern
|
|
203
233
|
};
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
var __async = (__this, __arguments, generator) => {
|
|
2
21
|
return new Promise((resolve, reject) => {
|
|
3
22
|
var fulfilled = (value) => {
|
|
@@ -18,22 +37,123 @@ var __async = (__this, __arguments, generator) => {
|
|
|
18
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
38
|
});
|
|
20
39
|
};
|
|
21
|
-
|
|
40
|
+
import {
|
|
41
|
+
createBuilder
|
|
42
|
+
} from "@modern-js/builder";
|
|
43
|
+
import {
|
|
44
|
+
builderWebpackProvider
|
|
45
|
+
} from "@modern-js/builder-webpack-provider";
|
|
46
|
+
import {
|
|
47
|
+
applyOptionsChain,
|
|
48
|
+
isProd,
|
|
49
|
+
isSSR,
|
|
50
|
+
isUseSSRBundle
|
|
51
|
+
} from "@modern-js/utils";
|
|
52
|
+
import {
|
|
53
|
+
PluginCompatModern
|
|
54
|
+
} from "./builderPlugins/compatModern";
|
|
55
|
+
import { createCopyPattern } from "./share";
|
|
56
|
+
function getBuilderTargets(normalizedConfig) {
|
|
57
|
+
const targets = ["web"];
|
|
58
|
+
const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
|
59
|
+
if (useNodeTarget) {
|
|
60
|
+
targets.push("node");
|
|
61
|
+
}
|
|
62
|
+
return targets;
|
|
63
|
+
}
|
|
64
|
+
function createBuilderForModern(_0) {
|
|
65
|
+
return __async(this, arguments, function* ({
|
|
66
|
+
normalizedConfig,
|
|
67
|
+
appContext,
|
|
68
|
+
compatPluginConfig
|
|
69
|
+
}) {
|
|
70
|
+
const builderConfig = createBuilderProviderConfig(
|
|
71
|
+
normalizedConfig,
|
|
72
|
+
appContext
|
|
73
|
+
);
|
|
74
|
+
const webpackProvider = builderWebpackProvider({
|
|
75
|
+
builderConfig
|
|
76
|
+
});
|
|
77
|
+
const target = getBuilderTargets(normalizedConfig);
|
|
78
|
+
const builderOptions = createBuilderOptions(target, appContext);
|
|
79
|
+
const builder = yield createBuilder(webpackProvider, builderOptions);
|
|
80
|
+
yield applyBuilderPlugins(
|
|
81
|
+
builder,
|
|
82
|
+
normalizedConfig,
|
|
83
|
+
appContext,
|
|
84
|
+
compatPluginConfig
|
|
85
|
+
);
|
|
86
|
+
return builder;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
90
|
+
const output = createOutputConfig(normalizedConfig, appContext);
|
|
91
|
+
const htmlConfig = __spreadValues({}, normalizedConfig.html);
|
|
92
|
+
if (!htmlConfig.template) {
|
|
93
|
+
htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
|
|
94
|
+
}
|
|
95
|
+
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
96
|
+
output,
|
|
97
|
+
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
98
|
+
port: appContext.port
|
|
99
|
+
}),
|
|
100
|
+
html: htmlConfig
|
|
101
|
+
});
|
|
102
|
+
function createOutputConfig(config, appContext2) {
|
|
103
|
+
const defaultCopyPattern = createCopyPattern(appContext2, config, "upload");
|
|
104
|
+
const { copy } = config.output;
|
|
105
|
+
const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
|
|
106
|
+
const builderCopy = [...copyOptions || [], defaultCopyPattern];
|
|
107
|
+
return __spreadProps(__spreadValues({}, config.output), {
|
|
108
|
+
copy: builderCopy,
|
|
109
|
+
cleanDistPath: false
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function createBuilderOptions(target, appContext) {
|
|
114
|
+
const entries = {};
|
|
115
|
+
const { entrypoints = [], checkedEntries } = appContext;
|
|
116
|
+
for (const { entryName, entry } of entrypoints) {
|
|
117
|
+
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (entryName in entries) {
|
|
121
|
+
entries[entryName].push(entry);
|
|
122
|
+
} else {
|
|
123
|
+
entries[entryName] = [entry];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
cwd: appContext.appDirectory,
|
|
128
|
+
target,
|
|
129
|
+
configPath: appContext.configFile || void 0,
|
|
130
|
+
entry: entries,
|
|
131
|
+
framework: appContext.metaName
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
22
135
|
return __async(this, null, function* () {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
136
|
+
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
137
|
+
const { builderPluginNodePolyfill } = yield import("@modern-js/builder-plugin-node-polyfill");
|
|
138
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
139
|
+
}
|
|
140
|
+
if (normalizedConfig.tools.esbuild) {
|
|
141
|
+
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
142
|
+
const { builderPluginEsbuild } = yield import("@modern-js/builder-plugin-esbuild");
|
|
143
|
+
builder.addPlugins([
|
|
144
|
+
builderPluginEsbuild({
|
|
145
|
+
loader: false,
|
|
146
|
+
minimize: applyOptionsChain({}, esbuildOptions)
|
|
147
|
+
})
|
|
148
|
+
]);
|
|
32
149
|
}
|
|
33
|
-
|
|
34
|
-
|
|
150
|
+
builder.addPlugins([
|
|
151
|
+
PluginCompatModern(appContext, normalizedConfig, compatPluginConfig)
|
|
152
|
+
]);
|
|
35
153
|
});
|
|
36
154
|
}
|
|
37
155
|
export {
|
|
38
|
-
|
|
156
|
+
createBuilderForModern,
|
|
157
|
+
createBuilderOptions,
|
|
158
|
+
createBuilderProviderConfig
|
|
39
159
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { slash } from "@modern-js/utils";
|
|
2
|
+
function loader(source) {
|
|
3
|
+
this.cacheable();
|
|
4
|
+
const { target } = this._compiler.options;
|
|
5
|
+
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
|
6
|
+
return source;
|
|
7
|
+
}
|
|
8
|
+
const { resourcePath } = this;
|
|
9
|
+
const code = `
|
|
10
|
+
export { default } from "${slash(resourcePath)}";
|
|
11
|
+
`;
|
|
12
|
+
return code;
|
|
13
|
+
}
|
|
14
|
+
var routerLoader_default = loader;
|
|
15
|
+
export {
|
|
16
|
+
routerLoader_default as default
|
|
17
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class HtmlAsyncChunkPlugin {
|
|
2
|
+
constructor(htmlWebpackPlugin) {
|
|
3
|
+
this.name = "HtmlAsyncChunkPlugin";
|
|
4
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
5
|
+
}
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
compiler.hooks.compilation.tap(
|
|
8
|
+
this.name,
|
|
9
|
+
(compilation) => {
|
|
10
|
+
const hooks = this.htmlWebpackPlugin.getHooks(compilation);
|
|
11
|
+
hooks.alterAssetTagGroups.tap(this.name, (assets) => {
|
|
12
|
+
const tags = [...assets.headTags, ...assets.bodyTags];
|
|
13
|
+
for (const tag of tags) {
|
|
14
|
+
if (tag.tagName === "script") {
|
|
15
|
+
const { attributes } = tag;
|
|
16
|
+
if (attributes && attributes.defer === true) {
|
|
17
|
+
attributes.async = true;
|
|
18
|
+
delete attributes.defer;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return assets;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
HtmlAsyncChunkPlugin
|
|
30
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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(
|
|
10
|
+
this.name,
|
|
11
|
+
(compilation) => {
|
|
12
|
+
this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
if (this.bottomTemplateReg.test(data.html)) {
|
|
18
|
+
data.html = data.html.replace(this.bottomTemplateReg, "");
|
|
19
|
+
const { bottomTemplate } = data.plugin.options;
|
|
20
|
+
if (bottomTemplate) {
|
|
21
|
+
data.html = data.html.replace(
|
|
22
|
+
this.bodyRegExp,
|
|
23
|
+
(match) => `
|
|
24
|
+
${bottomTemplate}
|
|
25
|
+
${match}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return data;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
BottomTemplatePlugin
|
|
37
|
+
};
|
|
@@ -18,11 +18,12 @@ 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) {
|
|
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);
|
|
26
27
|
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
27
28
|
disableNodePolyfill: true
|
|
28
29
|
});
|
|
@@ -60,7 +61,6 @@ function createDefaultConfig(appContext, bundler) {
|
|
|
60
61
|
baseUrl: "/",
|
|
61
62
|
port: 8080
|
|
62
63
|
};
|
|
63
|
-
const tools = bundler === "webpack" ? __spreadValues({}, defaultBuilderConfig.tools) : void 0;
|
|
64
64
|
return {
|
|
65
65
|
source,
|
|
66
66
|
output,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { createDefaultConfig, createLegacyDefaultConfig } from "./default";
|
|
2
|
+
import { initialNormalizedConfig, checkIsLegacyConfig } from "./initial";
|
|
3
|
+
export {
|
|
4
|
+
checkIsLegacyConfig,
|
|
5
|
+
createDefaultConfig,
|
|
6
|
+
createLegacyDefaultConfig,
|
|
7
|
+
initialNormalizedConfig
|
|
8
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { initHtmlConfig, initSourceConfig, initToolsConfig } from "./inits";
|
|
2
|
+
import { transformNormalizedConfig } from "./transformNormalizedConfig";
|
|
3
|
+
function checkIsLegacyConfig(config) {
|
|
4
|
+
return Boolean(config.legacy);
|
|
5
|
+
}
|
|
6
|
+
function initialNormalizedConfig(config, appContext) {
|
|
7
|
+
initHtmlConfig(config, appContext);
|
|
8
|
+
initSourceConfig(config, appContext);
|
|
9
|
+
initToolsConfig(config);
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
checkIsLegacyConfig,
|
|
14
|
+
initialNormalizedConfig,
|
|
15
|
+
transformNormalizedConfig
|
|
16
|
+
};
|
|
@@ -59,12 +59,10 @@ 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) {
|
|
63
63
|
config.source.include = createBuilderInclude(config, appContext);
|
|
64
|
+
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
64
65
|
config.source.globalVars = createBuilderGlobalVars(config, appContext);
|
|
65
|
-
if (bundler === "webpack") {
|
|
66
|
-
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
67
|
-
}
|
|
68
66
|
function createBuilderGlobalVars(config2, appContext2) {
|
|
69
67
|
const { globalVars = {} } = config2.source;
|
|
70
68
|
const publicEnv = getAutoInjectEnv(appContext2);
|
package/dist/js/modern/index.js
CHANGED
|
@@ -103,9 +103,7 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
-
var src_default = (
|
|
107
|
-
bundler: "webpack"
|
|
108
|
-
}) => ({
|
|
106
|
+
var src_default = () => ({
|
|
109
107
|
name: "@modern-js/app-tools",
|
|
110
108
|
post: [
|
|
111
109
|
"@modern-js/plugin-initialize",
|
|
@@ -118,15 +116,7 @@ var src_default = (options = {
|
|
|
118
116
|
"@modern-js/plugin-polyfill"
|
|
119
117
|
],
|
|
120
118
|
registerHook: hooks,
|
|
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
|
-
],
|
|
119
|
+
usePlugins: [initializePlugin(), analyzePlugin(), lintPlugin()],
|
|
130
120
|
setup: (api) => {
|
|
131
121
|
const locale = getLocaleLanguage();
|
|
132
122
|
i18n.changeLanguage({ locale });
|
|
@@ -145,19 +135,19 @@ var src_default = (options = {
|
|
|
145
135
|
program.command("deploy").usage("[options]").option(
|
|
146
136
|
"-c --config <config>",
|
|
147
137
|
i18n.t(localeKeys.command.shared.config)
|
|
148
|
-
).description(i18n.t(localeKeys.command.deploy.describe)).action((
|
|
138
|
+
).description(i18n.t(localeKeys.command.deploy.describe)).action((options) => __async(this, null, function* () {
|
|
149
139
|
const { build } = yield import("./commands/build");
|
|
150
140
|
yield build(api);
|
|
151
141
|
const { deploy } = yield import("./commands/deploy");
|
|
152
|
-
yield deploy(api,
|
|
142
|
+
yield deploy(api, options);
|
|
153
143
|
process.exit(0);
|
|
154
144
|
}));
|
|
155
145
|
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(
|
|
156
146
|
"-c, --config <config>",
|
|
157
147
|
i18n.t(localeKeys.command.new.config)
|
|
158
|
-
).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action((
|
|
148
|
+
).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
|
|
159
149
|
const { MWANewAction } = yield import("@modern-js/new-action");
|
|
160
|
-
yield MWANewAction(__spreadProps(__spreadValues({},
|
|
150
|
+
yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
|
|
161
151
|
}));
|
|
162
152
|
program.command("inspect").description("inspect internal webpack config").option(
|
|
163
153
|
`--env <env>`,
|
|
@@ -170,9 +160,9 @@ var src_default = (options = {
|
|
|
170
160
|
).option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option(
|
|
171
161
|
"-c --config <config>",
|
|
172
162
|
i18n.t(localeKeys.command.shared.config)
|
|
173
|
-
).action((
|
|
163
|
+
).action((options) => __async(this, null, function* () {
|
|
174
164
|
const { inspect } = yield import("./commands/inspect");
|
|
175
|
-
inspect(api,
|
|
165
|
+
inspect(api, options);
|
|
176
166
|
}));
|
|
177
167
|
upgradeModel.defineCommand(program.command("upgrade"));
|
|
178
168
|
});
|