@modern-js/uni-builder 2.48.1 → 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 +7 -4
- package/dist/shared/devServer.js +87 -40
- package/dist/shared/parseCommonConfig.js +39 -42
- package/dist/types.d.ts +34 -17
- 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
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { StartDevServerOptions as RsbuildStartDevServerOptions, StartServerResult, RsbuildInstance } from '@rsbuild/shared';
|
|
1
|
+
import { StartDevServerOptions as RsbuildStartDevServerOptions, StartServerResult, RsbuildInstance, DevConfig, ServerConfig } from '@rsbuild/shared';
|
|
2
2
|
import type { Server, ModernDevServerOptionsNew } from '@modern-js/server';
|
|
3
|
-
import { UniBuilderConfig } from '../types';
|
|
3
|
+
import type { UniBuilderConfig, ToolsDevServerConfig } from '../types';
|
|
4
4
|
type ServerOptions = Partial<Omit<ModernDevServerOptionsNew, 'config'>> & {
|
|
5
5
|
config?: Partial<ModernDevServerOptionsNew['config']>;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export declare const transformToRsbuildServerOptions: (dev: NonNullable<UniBuilderConfig['dev']>, devServer: ToolsDevServerConfig) => {
|
|
8
|
+
dev: DevConfig;
|
|
9
|
+
server: ServerConfig;
|
|
10
|
+
};
|
|
11
|
+
export type StartDevServerOptions = RsbuildStartDevServerOptions & {
|
|
8
12
|
apiOnly?: boolean;
|
|
9
|
-
defaultPort?: number;
|
|
10
13
|
serverOptions?: ServerOptions;
|
|
11
14
|
};
|
|
12
15
|
export type UniBuilderStartServerResult = Omit<StartServerResult, 'server'> & {
|
package/dist/shared/devServer.js
CHANGED
|
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var devServer_exports = {};
|
|
30
30
|
__export(devServer_exports, {
|
|
31
|
-
startDevServer: () => startDevServer
|
|
31
|
+
startDevServer: () => startDevServer,
|
|
32
|
+
transformToRsbuildServerOptions: () => transformToRsbuildServerOptions
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(devServer_exports);
|
|
34
35
|
var import_shared = require("@rsbuild/shared");
|
|
@@ -52,55 +53,108 @@ const getServerOptions = (builderConfig) => {
|
|
|
52
53
|
bff: {}
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
|
-
const
|
|
56
|
-
var
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
57
|
+
var _newDevServerConfig_devMiddleware, _newDevServerConfig_before, _newDevServerConfig_after;
|
|
58
|
+
const { port, host, https, ...devConfig } = dev;
|
|
59
|
+
var _dev_hmr;
|
|
60
|
+
const newDevServerConfig = (0, import_shared.mergeChainedOptions)({
|
|
61
|
+
defaults: {
|
|
62
|
+
devMiddleware: {
|
|
63
|
+
writeToDisk: (file) => !file.includes(".hot-update.")
|
|
64
|
+
},
|
|
65
|
+
hot: (_dev_hmr = dev === null || dev === void 0 ? void 0 : dev.hmr) !== null && _dev_hmr !== void 0 ? _dev_hmr : true,
|
|
66
|
+
liveReload: true,
|
|
67
|
+
client: {
|
|
68
|
+
path: "/webpack-hmr"
|
|
69
|
+
}
|
|
62
70
|
},
|
|
63
|
-
|
|
64
|
-
serverOptions.dev || {}
|
|
65
|
-
);
|
|
66
|
-
const devConfig = (0, import_shared.mergeChainedOptions)({
|
|
67
|
-
defaults: defaultDevConfig,
|
|
68
|
-
options: (_builderConfig_tools = builderConfig.tools) === null || _builderConfig_tools === void 0 ? void 0 : _builderConfig_tools.devServer,
|
|
71
|
+
options: devServer,
|
|
69
72
|
mergeFn: import_shared.deepmerge
|
|
70
73
|
});
|
|
74
|
+
const rsbuildDev = {
|
|
75
|
+
...devConfig,
|
|
76
|
+
writeToDisk: (_newDevServerConfig_devMiddleware = newDevServerConfig.devMiddleware) === null || _newDevServerConfig_devMiddleware === void 0 ? void 0 : _newDevServerConfig_devMiddleware.writeToDisk,
|
|
77
|
+
hmr: newDevServerConfig.hot,
|
|
78
|
+
client: newDevServerConfig.client,
|
|
79
|
+
liveReload: newDevServerConfig.liveReload
|
|
80
|
+
};
|
|
81
|
+
if (dev.progressBar === void 0) {
|
|
82
|
+
rsbuildDev.progressBar = true;
|
|
83
|
+
}
|
|
84
|
+
if (((_newDevServerConfig_before = newDevServerConfig.before) === null || _newDevServerConfig_before === void 0 ? void 0 : _newDevServerConfig_before.length) || ((_newDevServerConfig_after = newDevServerConfig.after) === null || _newDevServerConfig_after === void 0 ? void 0 : _newDevServerConfig_after.length)) {
|
|
85
|
+
rsbuildDev.setupMiddlewares = [
|
|
86
|
+
...newDevServerConfig.setupMiddlewares || [],
|
|
87
|
+
(middlewares) => {
|
|
88
|
+
middlewares.unshift(...newDevServerConfig.before || []);
|
|
89
|
+
middlewares.push(...newDevServerConfig.after || []);
|
|
90
|
+
}
|
|
91
|
+
];
|
|
92
|
+
} else if (newDevServerConfig.setupMiddlewares) {
|
|
93
|
+
rsbuildDev.setupMiddlewares = newDevServerConfig.setupMiddlewares;
|
|
94
|
+
}
|
|
95
|
+
const server = (0, import_shared.isProd)() ? {
|
|
96
|
+
publicDir: false,
|
|
97
|
+
htmlFallback: false,
|
|
98
|
+
printUrls: false
|
|
99
|
+
} : {
|
|
100
|
+
publicDir: false,
|
|
101
|
+
htmlFallback: false,
|
|
102
|
+
printUrls: false,
|
|
103
|
+
compress: newDevServerConfig.compress,
|
|
104
|
+
headers: newDevServerConfig.headers,
|
|
105
|
+
historyApiFallback: newDevServerConfig.historyApiFallback,
|
|
106
|
+
proxy: newDevServerConfig.proxy,
|
|
107
|
+
port,
|
|
108
|
+
host,
|
|
109
|
+
https: https ? https : void 0
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
dev: rsbuildDev,
|
|
113
|
+
server
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const getDevServerOptions = async ({ builderConfig, serverOptions }) => {
|
|
71
117
|
const defaultConfig = getServerOptions(builderConfig);
|
|
72
118
|
const config = serverOptions.config ? (0, import_shared.deepmerge)(defaultConfig, serverOptions.config) : defaultConfig;
|
|
73
119
|
return {
|
|
74
|
-
config
|
|
75
|
-
devConfig
|
|
120
|
+
config
|
|
76
121
|
};
|
|
77
122
|
};
|
|
78
123
|
async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
79
|
-
|
|
124
|
+
var _serverOptions_dev, _serverOptions_dev1;
|
|
80
125
|
const { ServerForRsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/server")));
|
|
81
|
-
const rsbuildServer = await rsbuild.
|
|
126
|
+
const rsbuildServer = await rsbuild.createDevServer({
|
|
127
|
+
...options,
|
|
128
|
+
runCompile: !options.apiOnly
|
|
129
|
+
});
|
|
82
130
|
const { serverOptions = {} } = options;
|
|
83
|
-
const { config
|
|
131
|
+
const { config } = await getDevServerOptions({
|
|
84
132
|
builderConfig,
|
|
85
|
-
serverOptions
|
|
86
|
-
port: rsbuildServer.config.port
|
|
133
|
+
serverOptions
|
|
87
134
|
});
|
|
88
|
-
const
|
|
135
|
+
const rsbuildConfig = rsbuild.getNormalizedConfig();
|
|
136
|
+
var _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;
|
|
140
|
+
var _serverOptions_dev_watch;
|
|
89
141
|
const server = new ServerForRsbuild({
|
|
90
142
|
pwd: rsbuild.context.rootPath,
|
|
91
143
|
...serverOptions,
|
|
92
144
|
rsbuild,
|
|
93
|
-
getMiddlewares: (
|
|
94
|
-
|
|
95
|
-
|
|
145
|
+
getMiddlewares: () => ({
|
|
146
|
+
middlewares: rsbuildServer.middlewares,
|
|
147
|
+
close: rsbuildServer.close,
|
|
148
|
+
onHTTPUpgrade: rsbuildServer.onHTTPUpgrade
|
|
96
149
|
}),
|
|
97
|
-
dev:
|
|
150
|
+
dev: {
|
|
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,
|
|
152
|
+
https,
|
|
153
|
+
writeToDisk
|
|
154
|
+
},
|
|
98
155
|
config
|
|
99
156
|
});
|
|
100
|
-
const
|
|
101
|
-
(0, import_shared.debug)("create dev server done");
|
|
102
|
-
await rsbuildServer.beforeStart();
|
|
103
|
-
const protocol = devConfig.https ? "https" : "http";
|
|
157
|
+
const protocol = https ? "https" : "http";
|
|
104
158
|
const urls = (0, import_shared.getAddressUrls)({
|
|
105
159
|
protocol,
|
|
106
160
|
port,
|
|
@@ -117,15 +171,7 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
117
171
|
throw err;
|
|
118
172
|
}
|
|
119
173
|
(0, import_shared.debug)("listen dev server done");
|
|
120
|
-
await rsbuildServer.
|
|
121
|
-
port,
|
|
122
|
-
routes: [
|
|
123
|
-
{
|
|
124
|
-
pathname: "/",
|
|
125
|
-
entryName: "index"
|
|
126
|
-
}
|
|
127
|
-
]
|
|
128
|
-
});
|
|
174
|
+
await rsbuildServer.afterListen();
|
|
129
175
|
resolve({
|
|
130
176
|
port,
|
|
131
177
|
urls: urls.map((item) => item.url),
|
|
@@ -136,5 +182,6 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
136
182
|
}
|
|
137
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
138
184
|
0 && (module.exports = {
|
|
139
|
-
startDevServer
|
|
185
|
+
startDevServer,
|
|
186
|
+
transformToRsbuildServerOptions
|
|
140
187
|
});
|
|
@@ -47,6 +47,7 @@ var import_devtools = require("./plugins/devtools");
|
|
|
47
47
|
var import_emitRouteFile = require("./plugins/emitRouteFile");
|
|
48
48
|
var import_antd = require("./plugins/antd");
|
|
49
49
|
var import_arco = require("./plugins/arco");
|
|
50
|
+
var import_devServer = require("./devServer");
|
|
50
51
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
51
52
|
const isLooseCssModules = (path) => {
|
|
52
53
|
if (import_shared.NODE_MODULES_REGEX.test(path)) {
|
|
@@ -104,10 +105,10 @@ const isUseCssSourceMap = (disableSourceMap = {}) => {
|
|
|
104
105
|
return !disableSourceMap.css;
|
|
105
106
|
};
|
|
106
107
|
async function parseCommonConfig(uniBuilderConfig, options) {
|
|
107
|
-
var
|
|
108
|
+
var _uniBuilderConfig_output, _uniBuilderConfig_tools;
|
|
108
109
|
var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
|
|
109
110
|
const { cwd, frameworkConfigPath, entry, target } = options;
|
|
110
|
-
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
|
|
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;
|
|
111
112
|
const rsbuildConfig = {
|
|
112
113
|
plugins,
|
|
113
114
|
output: outputConfig,
|
|
@@ -118,23 +119,26 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
118
119
|
performance: performanceConfig,
|
|
119
120
|
html: htmlConfig,
|
|
120
121
|
tools: toolsConfig,
|
|
121
|
-
dev: devConfig,
|
|
122
122
|
security: securityConfig
|
|
123
123
|
};
|
|
124
|
-
const {
|
|
124
|
+
const { html = {}, output = {}, source = {} } = rsbuildConfig;
|
|
125
125
|
if (enableLatestDecorators) {
|
|
126
126
|
source.decorators = {
|
|
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) => {
|
|
@@ -213,38 +236,9 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
213
236
|
};
|
|
214
237
|
}
|
|
215
238
|
};
|
|
216
|
-
|
|
217
|
-
dev.progressBar = true;
|
|
218
|
-
}
|
|
219
|
-
var _dev_hmr;
|
|
220
|
-
const newDevServerConfig = (0, import_shared.mergeChainedOptions)({
|
|
221
|
-
defaults: {
|
|
222
|
-
devMiddleware: {
|
|
223
|
-
writeToDisk: (file) => !file.includes(".hot-update.")
|
|
224
|
-
},
|
|
225
|
-
hot: (_dev_hmr = dev === null || dev === void 0 ? void 0 : dev.hmr) !== null && _dev_hmr !== void 0 ? _dev_hmr : true,
|
|
226
|
-
liveReload: true,
|
|
227
|
-
client: {
|
|
228
|
-
path: "/webpack-hmr"
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
options: devServer,
|
|
232
|
-
mergeFn: import_shared.deepmerge
|
|
233
|
-
});
|
|
234
|
-
dev.writeToDisk = (_newDevServerConfig_devMiddleware = newDevServerConfig.devMiddleware) === null || _newDevServerConfig_devMiddleware === void 0 ? void 0 : _newDevServerConfig_devMiddleware.writeToDisk;
|
|
235
|
-
dev.hmr = newDevServerConfig.hot;
|
|
236
|
-
dev.client = newDevServerConfig.client;
|
|
237
|
-
dev.liveReload = newDevServerConfig.liveReload;
|
|
238
|
-
const server = (0, import_shared.isProd)() ? {
|
|
239
|
-
publicDir: false
|
|
240
|
-
} : {
|
|
241
|
-
publicDir: false,
|
|
242
|
-
port,
|
|
243
|
-
host,
|
|
244
|
-
https: https ? https : void 0
|
|
245
|
-
};
|
|
239
|
+
const { dev: RsbuildDev, server } = (0, import_devServer.transformToRsbuildServerOptions)(dev || {}, devServer || {});
|
|
246
240
|
rsbuildConfig.server = removeUndefinedKey(server);
|
|
247
|
-
rsbuildConfig.dev = removeUndefinedKey(
|
|
241
|
+
rsbuildConfig.dev = removeUndefinedKey(RsbuildDev);
|
|
248
242
|
rsbuildConfig.html = html;
|
|
249
243
|
rsbuildConfig.output = output;
|
|
250
244
|
if (entry) {
|
|
@@ -297,7 +291,10 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
297
291
|
if (!disableSvgr) {
|
|
298
292
|
const { pluginSvgr } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-svgr")));
|
|
299
293
|
rsbuildPlugins.push(pluginSvgr({
|
|
300
|
-
|
|
294
|
+
mixedImport: true,
|
|
295
|
+
svgrOptions: {
|
|
296
|
+
exportType: svgDefaultExport === "component" ? "default" : "named"
|
|
297
|
+
}
|
|
301
298
|
}));
|
|
302
299
|
}
|
|
303
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;
|
|
@@ -40,25 +41,28 @@ export type DisableSourceMapOption = boolean | {
|
|
|
40
41
|
js?: boolean;
|
|
41
42
|
css?: boolean;
|
|
42
43
|
};
|
|
44
|
+
export type ToolsDevServerConfig = ChainedConfig<{
|
|
45
|
+
before?: RequestHandler[];
|
|
46
|
+
after?: RequestHandler[];
|
|
47
|
+
client?: DevConfig['client'];
|
|
48
|
+
compress?: ServerConfig['compress'];
|
|
49
|
+
devMiddleware?: {
|
|
50
|
+
writeToDisk?: DevConfig['writeToDisk'];
|
|
51
|
+
};
|
|
52
|
+
liveReload?: boolean;
|
|
53
|
+
headers?: ServerConfig['headers'];
|
|
54
|
+
historyApiFallback?: ServerConfig['historyApiFallback'];
|
|
55
|
+
hot?: boolean;
|
|
56
|
+
https?: DevServerHttpsOptions;
|
|
57
|
+
setupMiddlewares?: DevConfig['setupMiddlewares'];
|
|
58
|
+
proxy?: ServerConfig['proxy'];
|
|
59
|
+
}>;
|
|
60
|
+
export type TerserPluginOptions = TerserPlugin.BasePluginOptions & TerserPlugin.DefinedDefaultMinimizerAndOptions<TerserPlugin.TerserOptions>;
|
|
61
|
+
export type ToolsTerserConfig = ChainedConfig<TerserPluginOptions>;
|
|
43
62
|
export type UniBuilderExtraConfig = {
|
|
44
63
|
tools?: {
|
|
45
64
|
styledComponents?: false | PluginStyledComponentsOptions;
|
|
46
|
-
devServer?:
|
|
47
|
-
before?: RequestHandler[];
|
|
48
|
-
after?: RequestHandler[];
|
|
49
|
-
client?: DevConfig['client'];
|
|
50
|
-
compress?: ServerConfig['compress'];
|
|
51
|
-
devMiddleware?: {
|
|
52
|
-
writeToDisk?: DevConfig['writeToDisk'];
|
|
53
|
-
};
|
|
54
|
-
liveReload?: boolean;
|
|
55
|
-
headers?: ServerConfig['headers'];
|
|
56
|
-
historyApiFallback?: ServerConfig['historyApiFallback'];
|
|
57
|
-
hot?: boolean;
|
|
58
|
-
https?: DevServerHttpsOptions;
|
|
59
|
-
setupMiddlewares?: DevConfig['setupMiddlewares'];
|
|
60
|
-
proxy?: ServerConfig['proxy'];
|
|
61
|
-
}>;
|
|
65
|
+
devServer?: ToolsDevServerConfig;
|
|
62
66
|
/**
|
|
63
67
|
* Configure the [Pug](https://pugjs.org/) template engine.
|
|
64
68
|
*/
|
|
@@ -85,6 +89,11 @@ export type UniBuilderExtraConfig = {
|
|
|
85
89
|
* Tips: this configuration is not yet supported in rspack
|
|
86
90
|
*/
|
|
87
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;
|
|
88
97
|
};
|
|
89
98
|
dev?: {
|
|
90
99
|
/**
|
|
@@ -122,6 +131,10 @@ export type UniBuilderExtraConfig = {
|
|
|
122
131
|
resolveExtensionPrefix?: string | Partial<Record<RsbuildTarget, string>>;
|
|
123
132
|
};
|
|
124
133
|
output?: {
|
|
134
|
+
/**
|
|
135
|
+
* Whether to disable code minification in production build.
|
|
136
|
+
*/
|
|
137
|
+
disableMinimize?: boolean;
|
|
125
138
|
/**
|
|
126
139
|
* @deprecated use `output.filenameHash` instead
|
|
127
140
|
*/
|
|
@@ -194,6 +207,10 @@ export type UniBuilderExtraConfig = {
|
|
|
194
207
|
* When this option is enabled, the generated HTML file path will change from `[name]/index.html` to `[name].html`.
|
|
195
208
|
*/
|
|
196
209
|
disableHtmlFolder?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* @deprecated use `html.tags` instead
|
|
212
|
+
*/
|
|
213
|
+
tagsByEntries?: Record<string, ArrayOrNot<HtmlTagDescriptor>>;
|
|
197
214
|
/**
|
|
198
215
|
* @deprecated use `html.meta` instead
|
|
199
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",
|