@modern-js/uni-builder 2.48.2 → 2.48.3
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/shared/devServer.d.ts +1 -1
- package/dist/shared/devServer.js +18 -27
- package/dist/shared/parseCommonConfig.js +34 -8
- package/dist/types.d.ts +17 -1
- package/dist/webpack/index.js +8 -3
- package/dist/webpack/plugins/minimize.d.ts +3 -0
- package/dist/webpack/plugins/minimize.js +78 -0
- package/package.json +25 -24
|
@@ -8,7 +8,7 @@ export declare const transformToRsbuildServerOptions: (dev: NonNullable<UniBuild
|
|
|
8
8
|
dev: DevConfig;
|
|
9
9
|
server: ServerConfig;
|
|
10
10
|
};
|
|
11
|
-
export type StartDevServerOptions =
|
|
11
|
+
export type StartDevServerOptions = RsbuildStartDevServerOptions & {
|
|
12
12
|
apiOnly?: boolean;
|
|
13
13
|
serverOptions?: ServerOptions;
|
|
14
14
|
};
|
package/dist/shared/devServer.js
CHANGED
|
@@ -94,10 +94,12 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
|
94
94
|
}
|
|
95
95
|
const server = (0, import_shared.isProd)() ? {
|
|
96
96
|
publicDir: false,
|
|
97
|
-
htmlFallback: false
|
|
97
|
+
htmlFallback: false,
|
|
98
|
+
printUrls: false
|
|
98
99
|
} : {
|
|
99
100
|
publicDir: false,
|
|
100
101
|
htmlFallback: false,
|
|
102
|
+
printUrls: false,
|
|
101
103
|
compress: newDevServerConfig.compress,
|
|
102
104
|
headers: newDevServerConfig.headers,
|
|
103
105
|
historyApiFallback: newDevServerConfig.historyApiFallback,
|
|
@@ -119,42 +121,39 @@ const getDevServerOptions = async ({ builderConfig, serverOptions }) => {
|
|
|
119
121
|
};
|
|
120
122
|
};
|
|
121
123
|
async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
122
|
-
var _serverOptions_dev, _serverOptions_dev1
|
|
123
|
-
(0, import_shared.debug)("create dev server");
|
|
124
|
+
var _serverOptions_dev, _serverOptions_dev1;
|
|
124
125
|
const { ServerForRsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/server")));
|
|
125
|
-
const rsbuildServer = await rsbuild.
|
|
126
|
+
const rsbuildServer = await rsbuild.createDevServer({
|
|
127
|
+
...options,
|
|
128
|
+
runCompile: !options.apiOnly
|
|
129
|
+
});
|
|
126
130
|
const { serverOptions = {} } = options;
|
|
127
131
|
const { config } = await getDevServerOptions({
|
|
128
132
|
builderConfig,
|
|
129
133
|
serverOptions
|
|
130
134
|
});
|
|
131
|
-
const
|
|
132
|
-
const rsbuildConfig = rsbuild.getRsbuildConfig();
|
|
135
|
+
const rsbuildConfig = rsbuild.getNormalizedConfig();
|
|
133
136
|
var _serverOptions_dev_https;
|
|
134
|
-
const https = (_serverOptions_dev_https = (_serverOptions_dev = serverOptions.dev) === null || _serverOptions_dev === void 0 ? void 0 : _serverOptions_dev.https) !== null && _serverOptions_dev_https !== void 0 ? _serverOptions_dev_https :
|
|
137
|
+
const https = (_serverOptions_dev_https = (_serverOptions_dev = serverOptions.dev) === null || _serverOptions_dev === void 0 ? void 0 : _serverOptions_dev.https) !== null && _serverOptions_dev_https !== void 0 ? _serverOptions_dev_https : rsbuildConfig.server.https;
|
|
138
|
+
const { port } = rsbuildServer;
|
|
139
|
+
const { server: { host }, dev: { writeToDisk } } = rsbuildConfig;
|
|
135
140
|
var _serverOptions_dev_watch;
|
|
136
141
|
const server = new ServerForRsbuild({
|
|
137
142
|
pwd: rsbuild.context.rootPath,
|
|
138
143
|
...serverOptions,
|
|
139
144
|
rsbuild,
|
|
140
|
-
getMiddlewares: (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
getMiddlewares: () => ({
|
|
146
|
+
middlewares: rsbuildServer.middlewares,
|
|
147
|
+
close: rsbuildServer.close,
|
|
148
|
+
onHTTPUpgrade: rsbuildServer.onHTTPUpgrade
|
|
144
149
|
}),
|
|
145
150
|
dev: {
|
|
146
151
|
watch: (_serverOptions_dev_watch = (_serverOptions_dev1 = serverOptions.dev) === null || _serverOptions_dev1 === void 0 ? void 0 : _serverOptions_dev1.watch) !== null && _serverOptions_dev_watch !== void 0 ? _serverOptions_dev_watch : true,
|
|
147
|
-
compress: (_rsbuildConfig_server = rsbuildConfig.server) === null || _rsbuildConfig_server === void 0 ? void 0 : _rsbuildConfig_server.compress,
|
|
148
152
|
https,
|
|
149
|
-
|
|
150
|
-
writeToDisk: (_rsbuildConfig_dev = rsbuildConfig.dev) === null || _rsbuildConfig_dev === void 0 ? void 0 : _rsbuildConfig_dev.writeToDisk
|
|
151
|
-
}
|
|
153
|
+
writeToDisk
|
|
152
154
|
},
|
|
153
155
|
config
|
|
154
156
|
});
|
|
155
|
-
const { config: { port, host } } = rsbuildServer;
|
|
156
|
-
(0, import_shared.debug)("create dev server done");
|
|
157
|
-
await rsbuildServer.beforeStart();
|
|
158
157
|
const protocol = https ? "https" : "http";
|
|
159
158
|
const urls = (0, import_shared.getAddressUrls)({
|
|
160
159
|
protocol,
|
|
@@ -172,15 +171,7 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
172
171
|
throw err;
|
|
173
172
|
}
|
|
174
173
|
(0, import_shared.debug)("listen dev server done");
|
|
175
|
-
await rsbuildServer.
|
|
176
|
-
port,
|
|
177
|
-
routes: [
|
|
178
|
-
{
|
|
179
|
-
pathname: "/",
|
|
180
|
-
entryName: "index"
|
|
181
|
-
}
|
|
182
|
-
]
|
|
183
|
-
});
|
|
174
|
+
await rsbuildServer.afterListen();
|
|
184
175
|
resolve({
|
|
185
176
|
port,
|
|
186
177
|
urls: urls.map((item) => item.url),
|
|
@@ -108,7 +108,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
108
108
|
var _uniBuilderConfig_output, _uniBuilderConfig_tools;
|
|
109
109
|
var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
|
|
110
110
|
const { cwd, frameworkConfigPath, entry, target } = options;
|
|
111
|
-
const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, disableSourceMap, convertToRem, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, ...toolsConfig } = {} } = uniBuilderConfig;
|
|
111
|
+
const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, disableSourceMap, convertToRem, disableMinimize, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, tagsByEntries, tags, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, ...toolsConfig } = {} } = uniBuilderConfig;
|
|
112
112
|
const rsbuildConfig = {
|
|
113
113
|
plugins,
|
|
114
114
|
output: outputConfig,
|
|
@@ -127,14 +127,18 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
127
127
|
version: "2022-03"
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
if (
|
|
130
|
+
if (disableMinimize) {
|
|
131
131
|
var _output2;
|
|
132
|
-
(_output2 = output).
|
|
132
|
+
(_output2 = output).minify || (_output2.minify = false);
|
|
133
|
+
}
|
|
134
|
+
if (cssModuleLocalIdentName) {
|
|
135
|
+
var _output3;
|
|
136
|
+
(_output3 = output).cssModules || (_output3.cssModules = {});
|
|
133
137
|
output.cssModules.localIdentName = cssModuleLocalIdentName;
|
|
134
138
|
}
|
|
135
139
|
if (isUseCssSourceMap(disableSourceMap)) {
|
|
136
|
-
var
|
|
137
|
-
(
|
|
140
|
+
var _output4;
|
|
141
|
+
(_output4 = output).sourceMap || (_output4.sourceMap = {});
|
|
138
142
|
output.sourceMap.css = true;
|
|
139
143
|
}
|
|
140
144
|
var _distPath;
|
|
@@ -146,8 +150,8 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
146
150
|
var _polyfill;
|
|
147
151
|
(_polyfill = (_output1 = output).polyfill) !== null && _polyfill !== void 0 ? _polyfill : _output1.polyfill = "entry";
|
|
148
152
|
if (disableCssModuleExtension) {
|
|
149
|
-
var
|
|
150
|
-
(
|
|
153
|
+
var _output5, _output_cssModules;
|
|
154
|
+
(_output5 = output).cssModules || (_output5.cssModules = {});
|
|
151
155
|
var _auto;
|
|
152
156
|
(_auto = (_output_cssModules = output.cssModules).auto) !== null && _auto !== void 0 ? _auto : _output_cssModules.auto = isLooseCssModules;
|
|
153
157
|
}
|
|
@@ -198,6 +202,25 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
198
202
|
...templateParametersByEntries[entryName] || {}
|
|
199
203
|
});
|
|
200
204
|
}
|
|
205
|
+
if (tags) {
|
|
206
|
+
html.tags = Array.isArray(tags) ? tags.filter((t) => typeof t !== "function").concat(tags.filter((t) => typeof t === "function")) : tags;
|
|
207
|
+
}
|
|
208
|
+
if (tagsByEntries) {
|
|
209
|
+
extraConfig.html.tags = [
|
|
210
|
+
(tags2, utils) => {
|
|
211
|
+
const entryTags = (0, import_shared.castArray)(tagsByEntries[utils.entryName]);
|
|
212
|
+
const handlers = [];
|
|
213
|
+
for (const tag of entryTags) {
|
|
214
|
+
if ((0, import_shared.isFunction)(tag)) {
|
|
215
|
+
handlers.push(tag);
|
|
216
|
+
} else {
|
|
217
|
+
tags2.push(tag);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return handlers.reduce((currentTags, handler) => handler(currentTags, utils) || currentTags, tags2);
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
}
|
|
201
224
|
var _tools;
|
|
202
225
|
(_tools = (_extraConfig1 = extraConfig).tools) !== null && _tools !== void 0 ? _tools : _extraConfig1.tools = {};
|
|
203
226
|
extraConfig.tools.htmlPlugin = (config) => {
|
|
@@ -268,7 +291,10 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
268
291
|
if (!disableSvgr) {
|
|
269
292
|
const { pluginSvgr } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-svgr")));
|
|
270
293
|
rsbuildPlugins.push(pluginSvgr({
|
|
271
|
-
|
|
294
|
+
mixedImport: true,
|
|
295
|
+
svgrOptions: {
|
|
296
|
+
exportType: svgDefaultExport === "component" ? "default" : "named"
|
|
297
|
+
}
|
|
272
298
|
}));
|
|
273
299
|
}
|
|
274
300
|
const pugOptions = (_uniBuilderConfig_tools = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools === void 0 ? void 0 : _uniBuilderConfig_tools.pug;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeEnv, MetaOptions, ServerConfig, ScriptInject, RsbuildTarget, ChainedConfig, ChainedConfigWithUtils, InlineChunkTest, DevConfig, RequestHandler, RsbuildEntry, PromiseOrNot, RsbuildPluginAPI } from '@rsbuild/shared';
|
|
1
|
+
import type { NodeEnv, MetaOptions, ServerConfig, ScriptInject, RsbuildTarget, ChainedConfig, ChainedConfigWithUtils, InlineChunkTest, DevConfig, RequestHandler, RsbuildEntry, PromiseOrNot, RsbuildPluginAPI, ArrayOrNot, HtmlTagDescriptor } from '@rsbuild/shared';
|
|
2
2
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
3
3
|
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
|
|
4
4
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
@@ -14,6 +14,7 @@ import type { PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
|
14
14
|
import type { AliasOption } from '@modern-js/utils';
|
|
15
15
|
import type { StartDevServerOptions, UniBuilderStartServerResult } from './shared/devServer';
|
|
16
16
|
import type { PluginSourceBuildOptions } from '@rsbuild/plugin-source-build';
|
|
17
|
+
import type TerserPlugin from 'terser-webpack-plugin';
|
|
17
18
|
export type CreateBuilderCommonOptions = {
|
|
18
19
|
entry?: RsbuildEntry;
|
|
19
20
|
frameworkConfigPath?: string;
|
|
@@ -56,6 +57,8 @@ export type ToolsDevServerConfig = ChainedConfig<{
|
|
|
56
57
|
setupMiddlewares?: DevConfig['setupMiddlewares'];
|
|
57
58
|
proxy?: ServerConfig['proxy'];
|
|
58
59
|
}>;
|
|
60
|
+
export type TerserPluginOptions = TerserPlugin.BasePluginOptions & TerserPlugin.DefinedDefaultMinimizerAndOptions<TerserPlugin.TerserOptions>;
|
|
61
|
+
export type ToolsTerserConfig = ChainedConfig<TerserPluginOptions>;
|
|
59
62
|
export type UniBuilderExtraConfig = {
|
|
60
63
|
tools?: {
|
|
61
64
|
styledComponents?: false | PluginStyledComponentsOptions;
|
|
@@ -86,6 +89,11 @@ export type UniBuilderExtraConfig = {
|
|
|
86
89
|
* Tips: this configuration is not yet supported in rspack
|
|
87
90
|
*/
|
|
88
91
|
tsLoader?: PluginTsLoaderOptions;
|
|
92
|
+
/**
|
|
93
|
+
* Modify the options of [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin).
|
|
94
|
+
* @requires webpack
|
|
95
|
+
*/
|
|
96
|
+
terser?: ToolsTerserConfig;
|
|
89
97
|
};
|
|
90
98
|
dev?: {
|
|
91
99
|
/**
|
|
@@ -123,6 +131,10 @@ export type UniBuilderExtraConfig = {
|
|
|
123
131
|
resolveExtensionPrefix?: string | Partial<Record<RsbuildTarget, string>>;
|
|
124
132
|
};
|
|
125
133
|
output?: {
|
|
134
|
+
/**
|
|
135
|
+
* Whether to disable code minification in production build.
|
|
136
|
+
*/
|
|
137
|
+
disableMinimize?: boolean;
|
|
126
138
|
/**
|
|
127
139
|
* @deprecated use `output.filenameHash` instead
|
|
128
140
|
*/
|
|
@@ -195,6 +207,10 @@ export type UniBuilderExtraConfig = {
|
|
|
195
207
|
* When this option is enabled, the generated HTML file path will change from `[name]/index.html` to `[name].html`.
|
|
196
208
|
*/
|
|
197
209
|
disableHtmlFolder?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* @deprecated use `html.tags` instead
|
|
212
|
+
*/
|
|
213
|
+
tagsByEntries?: Record<string, ArrayOrNot<HtmlTagDescriptor>>;
|
|
198
214
|
/**
|
|
199
215
|
* @deprecated use `html.meta` instead
|
|
200
216
|
*/
|
package/dist/webpack/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var import_moduleScopes = require("./plugins/moduleScopes");
|
|
|
39
39
|
var import_babel = require("./plugins/babel");
|
|
40
40
|
var import_react = require("./plugins/react");
|
|
41
41
|
async function parseConfig(uniBuilderConfig, options) {
|
|
42
|
-
var _uniBuilderConfig_tools, _uniBuilderConfig_performance, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2;
|
|
42
|
+
var _uniBuilderConfig_tools, _uniBuilderConfig_performance, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_output1, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2;
|
|
43
43
|
const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
|
|
44
44
|
var _uniBuilderConfig_performance_transformLodash;
|
|
45
45
|
rsbuildPlugins.push((0, import_babel.pluginBabel)({
|
|
@@ -56,6 +56,11 @@ async function parseConfig(uniBuilderConfig, options) {
|
|
|
56
56
|
const { pluginManifest } = await Promise.resolve().then(() => __toESM(require("./plugins/manifest")));
|
|
57
57
|
rsbuildPlugins.push(pluginManifest());
|
|
58
58
|
}
|
|
59
|
+
if (!((_uniBuilderConfig_output1 = uniBuilderConfig.output) === null || _uniBuilderConfig_output1 === void 0 ? void 0 : _uniBuilderConfig_output1.disableMinimize)) {
|
|
60
|
+
var _uniBuilderConfig_tools3;
|
|
61
|
+
const { pluginMinimize } = await Promise.resolve().then(() => __toESM(require("./plugins/minimize")));
|
|
62
|
+
rsbuildPlugins.push(pluginMinimize((_uniBuilderConfig_tools3 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools3 === void 0 ? void 0 : _uniBuilderConfig_tools3.terser));
|
|
63
|
+
}
|
|
59
64
|
if ((_uniBuilderConfig_security = uniBuilderConfig.security) === null || _uniBuilderConfig_security === void 0 ? void 0 : _uniBuilderConfig_security.sri) {
|
|
60
65
|
var _uniBuilderConfig_security1;
|
|
61
66
|
const { pluginSRI } = await Promise.resolve().then(() => __toESM(require("./plugins/sri")));
|
|
@@ -67,9 +72,9 @@ async function parseConfig(uniBuilderConfig, options) {
|
|
|
67
72
|
rsbuildPlugins.push(pluginLazyCompilation((_uniBuilderConfig_experiments1 = uniBuilderConfig.experiments) === null || _uniBuilderConfig_experiments1 === void 0 ? void 0 : _uniBuilderConfig_experiments1.lazyCompilation));
|
|
68
73
|
}
|
|
69
74
|
if (((_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.styledComponents) !== false) {
|
|
70
|
-
var
|
|
75
|
+
var _uniBuilderConfig_tools4;
|
|
71
76
|
const { pluginStyledComponents } = await Promise.resolve().then(() => __toESM(require("./plugins/styledComponents")));
|
|
72
|
-
rsbuildPlugins.push(pluginStyledComponents((
|
|
77
|
+
rsbuildPlugins.push(pluginStyledComponents((_uniBuilderConfig_tools4 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools4 === void 0 ? void 0 : _uniBuilderConfig_tools4.styledComponents));
|
|
73
78
|
}
|
|
74
79
|
return {
|
|
75
80
|
rsbuildConfig,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var minimize_exports = {};
|
|
30
|
+
__export(minimize_exports, {
|
|
31
|
+
pluginMinimize: () => pluginMinimize
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(minimize_exports);
|
|
34
|
+
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
36
|
+
const { default: TerserPlugin } = await Promise.resolve().then(() => __toESM(require("terser-webpack-plugin")));
|
|
37
|
+
const DEFAULT_OPTIONS = {
|
|
38
|
+
terserOptions: (0, import_shared.getTerserMinifyOptions)(config)
|
|
39
|
+
};
|
|
40
|
+
switch (config.output.legalComments) {
|
|
41
|
+
case "inline":
|
|
42
|
+
DEFAULT_OPTIONS.extractComments = false;
|
|
43
|
+
break;
|
|
44
|
+
case "linked":
|
|
45
|
+
DEFAULT_OPTIONS.extractComments = true;
|
|
46
|
+
break;
|
|
47
|
+
case "none":
|
|
48
|
+
DEFAULT_OPTIONS.terserOptions.format.comments = false;
|
|
49
|
+
DEFAULT_OPTIONS.extractComments = false;
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
const mergedOptions = (0, import_shared.mergeChainedOptions)({
|
|
55
|
+
defaults: DEFAULT_OPTIONS,
|
|
56
|
+
options: userTerserConfig
|
|
57
|
+
});
|
|
58
|
+
chain.optimization.minimizer(import_shared.CHAIN_ID.MINIMIZER.JS).use(TerserPlugin, [
|
|
59
|
+
// Due to terser-webpack-plugin has changed the type of class, which using a generic type in
|
|
60
|
+
// constructor, leading auto inference of parameters of plugin constructor is not possible, using any instead
|
|
61
|
+
mergedOptions
|
|
62
|
+
]).end();
|
|
63
|
+
}
|
|
64
|
+
const pluginMinimize = (userTerserConfig) => ({
|
|
65
|
+
name: "uni-builder:minimize",
|
|
66
|
+
setup(api) {
|
|
67
|
+
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
68
|
+
const config = api.getNormalizedConfig();
|
|
69
|
+
if ((0, import_shared.parseMinifyOptions)(config, isProd).minifyJs) {
|
|
70
|
+
await applyJSMinimizer(chain, config, userTerserConfig);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
pluginMinimize
|
|
78
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "2.48.
|
|
3
|
+
"version": "2.48.3",
|
|
4
4
|
"description": "Unified builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,23 +26,23 @@
|
|
|
26
26
|
"@babel/preset-react": "^7.22.15",
|
|
27
27
|
"@babel/types": "^7.23.0",
|
|
28
28
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
|
|
29
|
-
"@rsbuild/babel-preset": "0.
|
|
30
|
-
"@rsbuild/core": "0.
|
|
31
|
-
"@rsbuild/plugin-assets-retry": "0.
|
|
32
|
-
"@rsbuild/plugin-babel": "0.
|
|
33
|
-
"@rsbuild/plugin-check-syntax": "0.
|
|
34
|
-
"@rsbuild/plugin-css-minimizer": "0.
|
|
35
|
-
"@rsbuild/plugin-pug": "0.
|
|
36
|
-
"@rsbuild/plugin-react": "0.
|
|
37
|
-
"@rsbuild/plugin-rem": "0.
|
|
38
|
-
"@rsbuild/plugin-source-build": "0.
|
|
39
|
-
"@rsbuild/plugin-styled-components": "0.
|
|
40
|
-
"@rsbuild/plugin-svgr": "0.
|
|
41
|
-
"@rsbuild/plugin-type-check": "0.
|
|
42
|
-
"@rsbuild/plugin-toml": "0.
|
|
43
|
-
"@rsbuild/plugin-yaml": "0.
|
|
44
|
-
"@rsbuild/shared": "0.
|
|
45
|
-
"@rsbuild/webpack": "0.
|
|
29
|
+
"@rsbuild/babel-preset": "0.5.1",
|
|
30
|
+
"@rsbuild/core": "0.5.1",
|
|
31
|
+
"@rsbuild/plugin-assets-retry": "0.5.1",
|
|
32
|
+
"@rsbuild/plugin-babel": "0.5.1",
|
|
33
|
+
"@rsbuild/plugin-check-syntax": "0.5.1",
|
|
34
|
+
"@rsbuild/plugin-css-minimizer": "0.5.1",
|
|
35
|
+
"@rsbuild/plugin-pug": "0.5.1",
|
|
36
|
+
"@rsbuild/plugin-react": "0.5.1",
|
|
37
|
+
"@rsbuild/plugin-rem": "0.5.1",
|
|
38
|
+
"@rsbuild/plugin-source-build": "0.5.1",
|
|
39
|
+
"@rsbuild/plugin-styled-components": "0.5.1",
|
|
40
|
+
"@rsbuild/plugin-svgr": "0.5.1",
|
|
41
|
+
"@rsbuild/plugin-type-check": "0.5.1",
|
|
42
|
+
"@rsbuild/plugin-toml": "0.5.1",
|
|
43
|
+
"@rsbuild/plugin-yaml": "0.5.1",
|
|
44
|
+
"@rsbuild/shared": "0.5.1",
|
|
45
|
+
"@rsbuild/webpack": "0.5.1",
|
|
46
46
|
"@swc/helpers": "0.5.3",
|
|
47
47
|
"babel-loader": "9.1.3",
|
|
48
48
|
"babel-plugin-import": "1.13.5",
|
|
@@ -62,22 +62,23 @@
|
|
|
62
62
|
"postcss-page-break": "3.0.4",
|
|
63
63
|
"react-refresh": "^0.14.0",
|
|
64
64
|
"rspack-manifest-plugin": "5.0.0-alpha0",
|
|
65
|
+
"terser-webpack-plugin": "5.3.10",
|
|
65
66
|
"ts-loader": "9.4.4",
|
|
66
67
|
"webpack": "^5.89.0",
|
|
67
68
|
"webpack-manifest-plugin": "5.0.0",
|
|
68
69
|
"webpack-subresource-integrity": "5.1.0",
|
|
69
|
-
"@modern-js/
|
|
70
|
-
"@modern-js/
|
|
70
|
+
"@modern-js/server": "2.48.3",
|
|
71
|
+
"@modern-js/utils": "2.48.3"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
|
-
"@rsbuild/plugin-swc": "0.
|
|
74
|
+
"@rsbuild/plugin-swc": "0.5.1",
|
|
74
75
|
"@types/lodash": "^4.14.202",
|
|
75
76
|
"react": "^18.2.0",
|
|
76
77
|
"react-dom": "^18.2.0",
|
|
77
78
|
"typescript": "^5.3.0",
|
|
78
|
-
"@modern-js/prod-server": "2.48.
|
|
79
|
-
"@scripts/build": "2.48.
|
|
80
|
-
"@scripts/vitest-config": "2.48.
|
|
79
|
+
"@modern-js/prod-server": "2.48.3",
|
|
80
|
+
"@scripts/build": "2.48.3",
|
|
81
|
+
"@scripts/vitest-config": "2.48.3"
|
|
81
82
|
},
|
|
82
83
|
"publishConfig": {
|
|
83
84
|
"access": "public",
|