@rsbuild/core 0.7.6 → 0.7.8
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/compiled/css-loader/index.js +23 -23
- package/compiled/jiti/index.d.ts +1 -0
- package/compiled/jiti/index.js +391 -0
- package/compiled/jiti/license +21 -0
- package/compiled/jiti/package.json +1 -0
- package/compiled/postcss-load-config/index.js +11 -11
- package/compiled/postcss-loader/index.js +21 -21
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/compiled/semver/index.d.ts +1 -0
- package/compiled/semver/index.js +2585 -0
- package/compiled/semver/license +15 -0
- package/compiled/semver/package.json +1 -0
- package/compiled/style-loader/index.js +10 -10
- package/compiled/webpack-dev-middleware/index.js +311 -41
- package/compiled/ws/index.js +80 -57
- package/compiled/ws/package.json +1 -1
- package/dist/client/hmr.js +10 -6
- package/dist/client/overlay.js +1 -1
- package/dist/index.cjs +661 -574
- package/dist/index.js +451 -375
- package/dist-types/client/format.d.ts +1 -1
- package/dist-types/config.d.ts +2 -1
- package/dist-types/helpers.d.ts +2 -0
- package/dist-types/index.d.ts +2 -1
- package/dist-types/internal.d.ts +1 -1
- package/dist-types/server/helper.d.ts +1 -0
- package/dist-types/types.d.ts +1 -2
- package/package.json +7 -5
- package/types.d.ts +12 -0
- package/dist-types/server/index.d.ts +0 -2
package/dist/index.cjs
CHANGED
|
@@ -76,16 +76,16 @@ function hintUnknownFiles(message) {
|
|
|
76
76
|
}
|
|
77
77
|
return message;
|
|
78
78
|
}
|
|
79
|
-
function formatMessage(stats) {
|
|
79
|
+
function formatMessage(stats, verbose) {
|
|
80
80
|
let lines = [];
|
|
81
81
|
let message;
|
|
82
82
|
if (typeof stats === "object") {
|
|
83
83
|
const fileName = resolveFileName(stats);
|
|
84
84
|
const mainMessage = stats.message;
|
|
85
|
-
const details = stats.details ? `
|
|
85
|
+
const details = verbose && stats.details ? `
|
|
86
86
|
Details: ${stats.details}
|
|
87
87
|
` : "";
|
|
88
|
-
const stack = stats.stack ? `
|
|
88
|
+
const stack = verbose && stats.stack ? `
|
|
89
89
|
${stats.stack}` : "";
|
|
90
90
|
message = `${fileName}${mainMessage}${details}${stack}`;
|
|
91
91
|
} else {
|
|
@@ -97,11 +97,15 @@ ${stats.stack}` : "";
|
|
|
97
97
|
(line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
|
|
98
98
|
);
|
|
99
99
|
message = lines.join("\n");
|
|
100
|
+
const innerError = "-- inner error --";
|
|
101
|
+
if (!verbose && message.includes(innerError)) {
|
|
102
|
+
message = message.split(innerError)[0];
|
|
103
|
+
}
|
|
100
104
|
return message.trim();
|
|
101
105
|
}
|
|
102
|
-
function formatStatsMessages(stats) {
|
|
103
|
-
const formattedErrors = stats.errors?.map(formatMessage) || [];
|
|
104
|
-
const formattedWarnings = stats.warnings?.map(formatMessage) || [];
|
|
106
|
+
function formatStatsMessages(stats, verbose) {
|
|
107
|
+
const formattedErrors = stats.errors?.map((error) => formatMessage(error, verbose)) || [];
|
|
108
|
+
const formattedWarnings = stats.warnings?.map((warning) => formatMessage(warning, verbose)) || [];
|
|
105
109
|
return {
|
|
106
110
|
errors: formattedErrors,
|
|
107
111
|
warnings: formattedWarnings
|
|
@@ -202,10 +206,14 @@ function formatStats(stats, options = {}) {
|
|
|
202
206
|
...options
|
|
203
207
|
} : options
|
|
204
208
|
);
|
|
205
|
-
const { errors, warnings } = formatStatsMessages(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
+
const { errors, warnings } = formatStatsMessages(
|
|
210
|
+
{
|
|
211
|
+
errors: getAllStatsErrors(statsData),
|
|
212
|
+
warnings: getAllStatsWarnings(statsData)
|
|
213
|
+
},
|
|
214
|
+
// display verbose messages in prod build or debug mode
|
|
215
|
+
(0, import_shared.isProd)() || (0, import_shared.isDebug)()
|
|
216
|
+
);
|
|
209
217
|
if (stats.hasErrors()) {
|
|
210
218
|
return {
|
|
211
219
|
message: formatErrorMessage(errors),
|
|
@@ -229,7 +237,7 @@ function isEmptyDir(path13) {
|
|
|
229
237
|
async function isFileExists(file) {
|
|
230
238
|
return import_shared2.fse.promises.access(file, import_shared2.fse.constants.F_OK).then(() => true).catch(() => false);
|
|
231
239
|
}
|
|
232
|
-
var import_node_path2, import_shared, import_shared2, rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists;
|
|
240
|
+
var import_node_path2, import_shared, import_shared2, rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists, urlJoin, canParse, ensureAssetPrefix;
|
|
233
241
|
var init_helpers = __esm({
|
|
234
242
|
"src/helpers.ts"() {
|
|
235
243
|
"use strict";
|
|
@@ -373,6 +381,34 @@ ${import_shared.color.yellow(tips.join("\n"))}`;
|
|
|
373
381
|
}
|
|
374
382
|
return false;
|
|
375
383
|
};
|
|
384
|
+
urlJoin = (base, path13) => {
|
|
385
|
+
const fullUrl = new URL(base);
|
|
386
|
+
fullUrl.pathname = import_node_path2.posix.join(fullUrl.pathname, path13);
|
|
387
|
+
return fullUrl.toString();
|
|
388
|
+
};
|
|
389
|
+
canParse = (url2) => {
|
|
390
|
+
try {
|
|
391
|
+
new URL(url2);
|
|
392
|
+
return true;
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
ensureAssetPrefix = (url2, assetPrefix) => {
|
|
398
|
+
if (url2.startsWith("//")) {
|
|
399
|
+
return url2;
|
|
400
|
+
}
|
|
401
|
+
if (canParse(url2)) {
|
|
402
|
+
return url2;
|
|
403
|
+
}
|
|
404
|
+
if (assetPrefix.startsWith("http")) {
|
|
405
|
+
return urlJoin(assetPrefix, url2);
|
|
406
|
+
}
|
|
407
|
+
if (assetPrefix.startsWith("//")) {
|
|
408
|
+
return urlJoin(`https:${assetPrefix}`, url2).replace("https:", "");
|
|
409
|
+
}
|
|
410
|
+
return import_node_path2.posix.join(assetPrefix, url2);
|
|
411
|
+
};
|
|
376
412
|
}
|
|
377
413
|
});
|
|
378
414
|
|
|
@@ -536,7 +572,7 @@ async function loadConfig({
|
|
|
536
572
|
return config;
|
|
537
573
|
};
|
|
538
574
|
try {
|
|
539
|
-
const { default: jiti } = await import("
|
|
575
|
+
const { default: jiti } = await import("../compiled/jiti/index.js");
|
|
540
576
|
const loadConfig2 = jiti(__filename, {
|
|
541
577
|
esmResolve: true,
|
|
542
578
|
// disable require cache to support restart CLI and read the new config
|
|
@@ -625,7 +661,7 @@ async function stringifyConfig(config, verbose) {
|
|
|
625
661
|
const stringify = import_shared5.RspackChain.toString;
|
|
626
662
|
return stringify(config, { verbose });
|
|
627
663
|
}
|
|
628
|
-
var import_node_fs, import_node_path4, import_shared5, getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath;
|
|
664
|
+
var import_node_fs, import_node_path4, import_shared5, getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath, normalizePublicDirs;
|
|
629
665
|
var init_config = __esm({
|
|
630
666
|
"src/config.ts"() {
|
|
631
667
|
"use strict";
|
|
@@ -652,12 +688,7 @@ var init_config = __esm({
|
|
|
652
688
|
htmlFallback: "index",
|
|
653
689
|
compress: true,
|
|
654
690
|
printUrls: true,
|
|
655
|
-
strictPort: false
|
|
656
|
-
publicDir: {
|
|
657
|
-
name: "public",
|
|
658
|
-
copyOnBuild: true,
|
|
659
|
-
watch: false
|
|
660
|
-
}
|
|
691
|
+
strictPort: false
|
|
661
692
|
});
|
|
662
693
|
getDefaultSourceConfig = () => ({
|
|
663
694
|
alias: {},
|
|
@@ -798,6 +829,31 @@ var init_config = __esm({
|
|
|
798
829
|
}
|
|
799
830
|
return null;
|
|
800
831
|
};
|
|
832
|
+
normalizePublicDirs = (publicDir) => {
|
|
833
|
+
if (publicDir === false) {
|
|
834
|
+
return [];
|
|
835
|
+
}
|
|
836
|
+
const defaultConfig = {
|
|
837
|
+
name: "public",
|
|
838
|
+
copyOnBuild: true,
|
|
839
|
+
watch: false
|
|
840
|
+
};
|
|
841
|
+
if (publicDir === void 0) {
|
|
842
|
+
return [defaultConfig];
|
|
843
|
+
}
|
|
844
|
+
if (Array.isArray(publicDir)) {
|
|
845
|
+
return publicDir.map((options) => ({
|
|
846
|
+
...defaultConfig,
|
|
847
|
+
...options
|
|
848
|
+
}));
|
|
849
|
+
}
|
|
850
|
+
return [
|
|
851
|
+
{
|
|
852
|
+
...defaultConfig,
|
|
853
|
+
...publicDir
|
|
854
|
+
}
|
|
855
|
+
];
|
|
856
|
+
};
|
|
801
857
|
}
|
|
802
858
|
});
|
|
803
859
|
|
|
@@ -828,6 +884,7 @@ function loadEnv({
|
|
|
828
884
|
for (const key of Object.keys(process.env)) {
|
|
829
885
|
if (prefixes.some((prefix) => key.startsWith(prefix))) {
|
|
830
886
|
const val = process.env[key];
|
|
887
|
+
publicVars[`import.meta.env.${key}`] = JSON.stringify(val);
|
|
831
888
|
publicVars[`process.env.${key}`] = JSON.stringify(val);
|
|
832
889
|
}
|
|
833
890
|
}
|
|
@@ -1003,7 +1060,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
|
|
|
1003
1060
|
return {
|
|
1004
1061
|
entry: getEntryObject(config, "web"),
|
|
1005
1062
|
targets: config.output?.targets || [],
|
|
1006
|
-
version: "0.7.
|
|
1063
|
+
version: "0.7.8",
|
|
1007
1064
|
rootPath,
|
|
1008
1065
|
distPath,
|
|
1009
1066
|
cachePath,
|
|
@@ -2037,6 +2094,7 @@ var init_getDevMiddlewares = __esm({
|
|
|
2037
2094
|
import_node_path10 = require("path");
|
|
2038
2095
|
import_node_url2 = __toESM(require("url"));
|
|
2039
2096
|
import_shared19 = require("@rsbuild/shared");
|
|
2097
|
+
init_config();
|
|
2040
2098
|
init_middlewares();
|
|
2041
2099
|
applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
|
|
2042
2100
|
const setupMiddlewares = dev.setupMiddlewares || [];
|
|
@@ -2114,11 +2172,12 @@ var init_getDevMiddlewares = __esm({
|
|
|
2114
2172
|
}
|
|
2115
2173
|
});
|
|
2116
2174
|
}
|
|
2117
|
-
|
|
2175
|
+
const publicDirs = normalizePublicDirs(server?.publicDir);
|
|
2176
|
+
for (const publicDir of publicDirs) {
|
|
2118
2177
|
const { default: sirv } = await import("../compiled/sirv/index.js");
|
|
2119
|
-
const { name } =
|
|
2120
|
-
const
|
|
2121
|
-
const assetMiddleware = sirv(
|
|
2178
|
+
const { name } = publicDir;
|
|
2179
|
+
const normalizedPath = (0, import_node_path10.isAbsolute)(name) ? name : (0, import_node_path10.join)(pwd, name);
|
|
2180
|
+
const assetMiddleware = sirv(normalizedPath, {
|
|
2122
2181
|
etag: true,
|
|
2123
2182
|
dev: true
|
|
2124
2183
|
});
|
|
@@ -2182,7 +2241,7 @@ function getURLMessages(urls, routes) {
|
|
|
2182
2241
|
if (routes.length === 1) {
|
|
2183
2242
|
return urls.map(
|
|
2184
2243
|
({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${import_shared20.color.cyan(
|
|
2185
|
-
|
|
2244
|
+
normalizeUrl(`${url2}${routes[0].pathname}`)
|
|
2186
2245
|
)}
|
|
2187
2246
|
`
|
|
2188
2247
|
).join("");
|
|
@@ -2198,7 +2257,7 @@ function getURLMessages(urls, routes) {
|
|
|
2198
2257
|
for (const r of routes) {
|
|
2199
2258
|
message += ` ${import_shared20.color.dim("-")} ${import_shared20.color.dim(
|
|
2200
2259
|
r.entryName.padEnd(maxNameLength + 4)
|
|
2201
|
-
)}${import_shared20.color.cyan(
|
|
2260
|
+
)}${import_shared20.color.cyan(normalizeUrl(`${url2}${r.pathname}`))}
|
|
2202
2261
|
`;
|
|
2203
2262
|
}
|
|
2204
2263
|
});
|
|
@@ -2242,7 +2301,7 @@ function printServerURLs({
|
|
|
2242
2301
|
import_shared20.logger.log(message);
|
|
2243
2302
|
return message;
|
|
2244
2303
|
}
|
|
2245
|
-
var import_node_net, import_node_os, import_shared20, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
|
|
2304
|
+
var import_node_net, import_node_os, import_shared20, normalizeUrl, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
|
|
2246
2305
|
var init_helper = __esm({
|
|
2247
2306
|
"src/server/helper.ts"() {
|
|
2248
2307
|
"use strict";
|
|
@@ -2250,6 +2309,7 @@ var init_helper = __esm({
|
|
|
2250
2309
|
import_node_os = __toESM(require("os"));
|
|
2251
2310
|
import_shared20 = require("@rsbuild/shared");
|
|
2252
2311
|
init_constants();
|
|
2312
|
+
normalizeUrl = (url2) => url2.replace(/([^:]\/)\/+/g, "$1");
|
|
2253
2313
|
formatPrefix = (prefix) => {
|
|
2254
2314
|
if (!prefix) {
|
|
2255
2315
|
return "/";
|
|
@@ -2503,11 +2563,15 @@ async function watchDevFiles(devConfig, compileMiddlewareAPI) {
|
|
|
2503
2563
|
return startWatchFiles(watchOptions, compileMiddlewareAPI);
|
|
2504
2564
|
}
|
|
2505
2565
|
function watchServerFiles(serverConfig, compileMiddlewareAPI) {
|
|
2506
|
-
const
|
|
2507
|
-
if (!
|
|
2566
|
+
const publicDirs = normalizePublicDirs(serverConfig.publicDir);
|
|
2567
|
+
if (!publicDirs.length) {
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
const watchPaths = publicDirs.filter((item) => item.watch).map((item) => item.name);
|
|
2571
|
+
if (!watchPaths.length) {
|
|
2508
2572
|
return;
|
|
2509
2573
|
}
|
|
2510
|
-
const watchOptions = prepareWatchOptions(
|
|
2574
|
+
const watchOptions = prepareWatchOptions(watchPaths);
|
|
2511
2575
|
return startWatchFiles(watchOptions, compileMiddlewareAPI);
|
|
2512
2576
|
}
|
|
2513
2577
|
function prepareWatchOptions(paths, options = {}) {
|
|
@@ -2527,6 +2591,7 @@ async function startWatchFiles({ paths, options }, compileMiddlewareAPI) {
|
|
|
2527
2591
|
var init_watchFiles = __esm({
|
|
2528
2592
|
"src/server/watchFiles.ts"() {
|
|
2529
2593
|
"use strict";
|
|
2594
|
+
init_config();
|
|
2530
2595
|
}
|
|
2531
2596
|
});
|
|
2532
2597
|
|
|
@@ -2948,194 +3013,22 @@ var init_devServer = __esm({
|
|
|
2948
3013
|
}
|
|
2949
3014
|
});
|
|
2950
3015
|
|
|
2951
|
-
// src/server/prodServer.ts
|
|
2952
|
-
var prodServer_exports = {};
|
|
2953
|
-
__export(prodServer_exports, {
|
|
2954
|
-
RsbuildProdServer: () => RsbuildProdServer,
|
|
2955
|
-
startProdServer: () => startProdServer
|
|
2956
|
-
});
|
|
2957
|
-
async function startProdServer(context, config, { getPortSilently } = {}) {
|
|
2958
|
-
if (!(0, import_shared23.getNodeEnv)()) {
|
|
2959
|
-
(0, import_shared23.setNodeEnv)("production");
|
|
2960
|
-
}
|
|
2961
|
-
const { port, host, https } = await getServerConfig({
|
|
2962
|
-
config,
|
|
2963
|
-
getPortSilently
|
|
2964
|
-
});
|
|
2965
|
-
const { default: connect } = await import("../compiled/connect/index.js");
|
|
2966
|
-
const middlewares = connect();
|
|
2967
|
-
const serverConfig = config.server;
|
|
2968
|
-
const server = new RsbuildProdServer(
|
|
2969
|
-
{
|
|
2970
|
-
pwd: context.rootPath,
|
|
2971
|
-
output: {
|
|
2972
|
-
path: config.output.distPath.root || ROOT_DIST_DIR,
|
|
2973
|
-
assetPrefix: config.output.assetPrefix
|
|
2974
|
-
},
|
|
2975
|
-
serverConfig
|
|
2976
|
-
},
|
|
2977
|
-
middlewares
|
|
2978
|
-
);
|
|
2979
|
-
await context.hooks.onBeforeStartProdServer.call();
|
|
2980
|
-
const httpServer = await createHttpServer({
|
|
2981
|
-
serverConfig,
|
|
2982
|
-
middlewares: server.middlewares
|
|
2983
|
-
});
|
|
2984
|
-
await server.onInit(httpServer);
|
|
2985
|
-
return new Promise((resolve) => {
|
|
2986
|
-
httpServer.listen(
|
|
2987
|
-
{
|
|
2988
|
-
host,
|
|
2989
|
-
port
|
|
2990
|
-
},
|
|
2991
|
-
async () => {
|
|
2992
|
-
const routes = formatRoutes(
|
|
2993
|
-
context.entry,
|
|
2994
|
-
config.output.distPath.html,
|
|
2995
|
-
config.html.outputStructure
|
|
2996
|
-
);
|
|
2997
|
-
await context.hooks.onAfterStartProdServer.call({
|
|
2998
|
-
port,
|
|
2999
|
-
routes
|
|
3000
|
-
});
|
|
3001
|
-
const protocol = https ? "https" : "http";
|
|
3002
|
-
const urls = getAddressUrls({ protocol, port, host });
|
|
3003
|
-
printServerURLs({
|
|
3004
|
-
urls,
|
|
3005
|
-
port,
|
|
3006
|
-
routes,
|
|
3007
|
-
protocol,
|
|
3008
|
-
printUrls: serverConfig.printUrls
|
|
3009
|
-
});
|
|
3010
|
-
const onClose = () => {
|
|
3011
|
-
server.close();
|
|
3012
|
-
httpServer.close();
|
|
3013
|
-
};
|
|
3014
|
-
resolve({
|
|
3015
|
-
port,
|
|
3016
|
-
urls: urls.map((item) => item.url),
|
|
3017
|
-
server: {
|
|
3018
|
-
close: async () => {
|
|
3019
|
-
onClose();
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
});
|
|
3023
|
-
}
|
|
3024
|
-
);
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
var import_node_path11, import_shared23, RsbuildProdServer;
|
|
3028
|
-
var init_prodServer = __esm({
|
|
3029
|
-
"src/server/prodServer.ts"() {
|
|
3030
|
-
"use strict";
|
|
3031
|
-
import_node_path11 = require("path");
|
|
3032
|
-
import_shared23 = require("@rsbuild/shared");
|
|
3033
|
-
init_constants();
|
|
3034
|
-
init_helper();
|
|
3035
|
-
init_httpServer();
|
|
3036
|
-
init_middlewares();
|
|
3037
|
-
RsbuildProdServer = class {
|
|
3038
|
-
constructor(options, middlewares) {
|
|
3039
|
-
__publicField(this, "app");
|
|
3040
|
-
__publicField(this, "options");
|
|
3041
|
-
__publicField(this, "middlewares");
|
|
3042
|
-
this.options = options;
|
|
3043
|
-
this.middlewares = middlewares;
|
|
3044
|
-
}
|
|
3045
|
-
// Complete the preparation of services
|
|
3046
|
-
async onInit(app) {
|
|
3047
|
-
this.app = app;
|
|
3048
|
-
await this.applyDefaultMiddlewares();
|
|
3049
|
-
}
|
|
3050
|
-
async applyDefaultMiddlewares() {
|
|
3051
|
-
const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
|
|
3052
|
-
if ((0, import_shared23.isDebug)()) {
|
|
3053
|
-
this.middlewares.use(await getRequestLoggerMiddleware());
|
|
3054
|
-
}
|
|
3055
|
-
if (compress) {
|
|
3056
|
-
const { default: compression } = await import("../compiled/http-compression/index.js");
|
|
3057
|
-
this.middlewares.use((req, res, next) => {
|
|
3058
|
-
compression({
|
|
3059
|
-
gzip: true,
|
|
3060
|
-
brotli: false
|
|
3061
|
-
})(req, res, next);
|
|
3062
|
-
});
|
|
3063
|
-
}
|
|
3064
|
-
if (headers) {
|
|
3065
|
-
this.middlewares.use((_req, res, next) => {
|
|
3066
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
3067
|
-
res.setHeader(key, value);
|
|
3068
|
-
}
|
|
3069
|
-
next();
|
|
3070
|
-
});
|
|
3071
|
-
}
|
|
3072
|
-
if (proxy) {
|
|
3073
|
-
const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
|
|
3074
|
-
const { middlewares, upgrade } = createProxyMiddleware2(proxy);
|
|
3075
|
-
for (const middleware of middlewares) {
|
|
3076
|
-
this.middlewares.use(middleware);
|
|
3077
|
-
}
|
|
3078
|
-
this.app.on("upgrade", upgrade);
|
|
3079
|
-
}
|
|
3080
|
-
this.applyStaticAssetMiddleware();
|
|
3081
|
-
if (historyApiFallback) {
|
|
3082
|
-
const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
|
|
3083
|
-
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
3084
|
-
historyApiFallback === true ? {} : historyApiFallback
|
|
3085
|
-
);
|
|
3086
|
-
this.middlewares.use(historyApiFallbackMiddleware);
|
|
3087
|
-
await this.applyStaticAssetMiddleware();
|
|
3088
|
-
}
|
|
3089
|
-
this.middlewares.use(faviconFallbackMiddleware);
|
|
3090
|
-
}
|
|
3091
|
-
async applyStaticAssetMiddleware() {
|
|
3092
|
-
const {
|
|
3093
|
-
output: { path: path13, assetPrefix },
|
|
3094
|
-
serverConfig: { htmlFallback },
|
|
3095
|
-
pwd
|
|
3096
|
-
} = this.options;
|
|
3097
|
-
const { default: sirv } = await import("../compiled/sirv/index.js");
|
|
3098
|
-
const assetMiddleware = sirv((0, import_node_path11.join)(pwd, path13), {
|
|
3099
|
-
etag: true,
|
|
3100
|
-
dev: true,
|
|
3101
|
-
ignores: ["favicon.ico"],
|
|
3102
|
-
single: htmlFallback === "index"
|
|
3103
|
-
});
|
|
3104
|
-
this.middlewares.use((req, res, next) => {
|
|
3105
|
-
const url2 = req.url;
|
|
3106
|
-
if (assetPrefix && url2?.startsWith(assetPrefix)) {
|
|
3107
|
-
req.url = url2.slice(assetPrefix.length);
|
|
3108
|
-
assetMiddleware(req, res, (...args) => {
|
|
3109
|
-
req.url = url2;
|
|
3110
|
-
next(...args);
|
|
3111
|
-
});
|
|
3112
|
-
} else {
|
|
3113
|
-
assetMiddleware(req, res, next);
|
|
3114
|
-
}
|
|
3115
|
-
});
|
|
3116
|
-
}
|
|
3117
|
-
close() {
|
|
3118
|
-
}
|
|
3119
|
-
};
|
|
3120
|
-
}
|
|
3121
|
-
});
|
|
3122
|
-
|
|
3123
3016
|
// src/provider/build.ts
|
|
3124
3017
|
var build_exports = {};
|
|
3125
3018
|
__export(build_exports, {
|
|
3126
3019
|
build: () => build
|
|
3127
3020
|
});
|
|
3128
|
-
var
|
|
3021
|
+
var import_shared23, import_core4, build;
|
|
3129
3022
|
var init_build = __esm({
|
|
3130
3023
|
"src/provider/build.ts"() {
|
|
3131
3024
|
"use strict";
|
|
3132
|
-
|
|
3025
|
+
import_shared23 = require("@rsbuild/shared");
|
|
3133
3026
|
import_core4 = require("@rspack/core");
|
|
3134
3027
|
init_createCompiler();
|
|
3135
3028
|
init_initConfigs();
|
|
3136
3029
|
build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
|
|
3137
|
-
if (!(0,
|
|
3138
|
-
(0,
|
|
3030
|
+
if (!(0, import_shared23.getNodeEnv)()) {
|
|
3031
|
+
(0, import_shared23.setNodeEnv)(mode);
|
|
3139
3032
|
}
|
|
3140
3033
|
const { context } = initOptions;
|
|
3141
3034
|
let compiler;
|
|
@@ -3159,7 +3052,7 @@ var init_build = __esm({
|
|
|
3159
3052
|
isFirstCompile = false;
|
|
3160
3053
|
await p;
|
|
3161
3054
|
};
|
|
3162
|
-
(0,
|
|
3055
|
+
(0, import_shared23.onCompileDone)(
|
|
3163
3056
|
compiler,
|
|
3164
3057
|
onDone,
|
|
3165
3058
|
// @ts-expect-error type mismatch
|
|
@@ -3168,7 +3061,7 @@ var init_build = __esm({
|
|
|
3168
3061
|
if (watch) {
|
|
3169
3062
|
compiler.watch({}, (err) => {
|
|
3170
3063
|
if (err) {
|
|
3171
|
-
|
|
3064
|
+
import_shared23.logger.error(err);
|
|
3172
3065
|
}
|
|
3173
3066
|
});
|
|
3174
3067
|
return;
|
|
@@ -3181,7 +3074,7 @@ var init_build = __esm({
|
|
|
3181
3074
|
} else {
|
|
3182
3075
|
compiler.close((closeErr) => {
|
|
3183
3076
|
if (closeErr) {
|
|
3184
|
-
|
|
3077
|
+
import_shared23.logger.error(closeErr);
|
|
3185
3078
|
}
|
|
3186
3079
|
resolve({ stats });
|
|
3187
3080
|
});
|
|
@@ -3245,11 +3138,6 @@ var init_provider = __esm({
|
|
|
3245
3138
|
);
|
|
3246
3139
|
return server.listen();
|
|
3247
3140
|
},
|
|
3248
|
-
async preview(options) {
|
|
3249
|
-
const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
|
|
3250
|
-
const config = await initRsbuildConfig({ context, pluginManager });
|
|
3251
|
-
return startProdServer2(context, config, options);
|
|
3252
|
-
},
|
|
3253
3141
|
async build(options) {
|
|
3254
3142
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
3255
3143
|
return build2({ context, pluginManager, rsbuildOptions }, options);
|
|
@@ -3281,22 +3169,22 @@ var basic_exports = {};
|
|
|
3281
3169
|
__export(basic_exports, {
|
|
3282
3170
|
pluginBasic: () => pluginBasic
|
|
3283
3171
|
});
|
|
3284
|
-
var
|
|
3172
|
+
var import_node_path11, import_shared24, pluginBasic;
|
|
3285
3173
|
var init_basic = __esm({
|
|
3286
3174
|
"src/plugins/basic.ts"() {
|
|
3287
3175
|
"use strict";
|
|
3288
|
-
|
|
3289
|
-
|
|
3176
|
+
import_node_path11 = __toESM(require("path"));
|
|
3177
|
+
import_shared24 = require("@rsbuild/shared");
|
|
3290
3178
|
pluginBasic = () => ({
|
|
3291
3179
|
name: "rsbuild:basic",
|
|
3292
3180
|
setup(api) {
|
|
3293
3181
|
api.modifyBundlerChain(
|
|
3294
|
-
(chain, { env, isProd:
|
|
3182
|
+
(chain, { env, isProd: isProd6, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
|
|
3295
3183
|
const config = api.getNormalizedConfig();
|
|
3296
|
-
chain.name(
|
|
3297
|
-
chain.devtool((0,
|
|
3184
|
+
chain.name(import_shared24.TARGET_ID_MAP[target]);
|
|
3185
|
+
chain.devtool((0, import_shared24.getJsSourceMap)(config));
|
|
3298
3186
|
chain.context(api.context.rootPath);
|
|
3299
|
-
chain.mode(
|
|
3187
|
+
chain.mode(isProd6 ? "production" : "development");
|
|
3300
3188
|
chain.merge({
|
|
3301
3189
|
infrastructureLogging: {
|
|
3302
3190
|
// Using `error` level to avoid `cache.PackFileCacheStrategy` logs
|
|
@@ -3309,15 +3197,15 @@ var init_basic = __esm({
|
|
|
3309
3197
|
exportsPresence: "error"
|
|
3310
3198
|
}
|
|
3311
3199
|
});
|
|
3312
|
-
const isMinimize =
|
|
3200
|
+
const isMinimize = isProd6 && config.output.minify !== false;
|
|
3313
3201
|
chain.optimization.minimize(isMinimize);
|
|
3314
|
-
const usingHMR = (0,
|
|
3202
|
+
const usingHMR = (0, import_shared24.isUsingHMR)(config, { target, isProd: isProd6 });
|
|
3315
3203
|
if (usingHMR) {
|
|
3316
3204
|
chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
|
|
3317
3205
|
}
|
|
3318
3206
|
if (env === "development") {
|
|
3319
3207
|
chain.output.devtoolModuleFilenameTemplate(
|
|
3320
|
-
(info) =>
|
|
3208
|
+
(info) => import_node_path11.default.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
|
|
3321
3209
|
);
|
|
3322
3210
|
}
|
|
3323
3211
|
process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
|
|
@@ -3335,15 +3223,15 @@ __export(cache_exports, {
|
|
|
3335
3223
|
pluginCache: () => pluginCache
|
|
3336
3224
|
});
|
|
3337
3225
|
async function validateCache(cacheDirectory, buildDependencies) {
|
|
3338
|
-
const configFile = (0,
|
|
3226
|
+
const configFile = (0, import_node_path12.join)(cacheDirectory, "buildDependencies.json");
|
|
3339
3227
|
if (await isFileExists(configFile)) {
|
|
3340
|
-
const prevBuildDependencies = await
|
|
3228
|
+
const prevBuildDependencies = await import_shared25.fse.readJSON(configFile);
|
|
3341
3229
|
if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
|
|
3342
3230
|
return;
|
|
3343
3231
|
}
|
|
3344
|
-
await
|
|
3232
|
+
await import_shared25.fse.remove(cacheDirectory);
|
|
3345
3233
|
}
|
|
3346
|
-
await
|
|
3234
|
+
await import_shared25.fse.outputJSON(configFile, buildDependencies);
|
|
3347
3235
|
}
|
|
3348
3236
|
function getDigestHash(digest) {
|
|
3349
3237
|
const fsHash = import_node_crypto.default.createHash("md5");
|
|
@@ -3352,13 +3240,13 @@ function getDigestHash(digest) {
|
|
|
3352
3240
|
}
|
|
3353
3241
|
function getCacheDirectory({ cacheDirectory }, context) {
|
|
3354
3242
|
if (cacheDirectory) {
|
|
3355
|
-
return (0,
|
|
3243
|
+
return (0, import_node_path12.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, import_node_path12.join)(context.rootPath, cacheDirectory);
|
|
3356
3244
|
}
|
|
3357
|
-
return (0,
|
|
3245
|
+
return (0, import_node_path12.join)(context.cachePath, context.bundlerType);
|
|
3358
3246
|
}
|
|
3359
3247
|
async function getBuildDependencies(context, config) {
|
|
3360
|
-
const rootPackageJson = (0,
|
|
3361
|
-
const browserslistConfig = (0,
|
|
3248
|
+
const rootPackageJson = (0, import_node_path12.join)(context.rootPath, "package.json");
|
|
3249
|
+
const browserslistConfig = (0, import_node_path12.join)(context.rootPath, ".browserslistrc");
|
|
3362
3250
|
const buildDependencies = {};
|
|
3363
3251
|
if (await isFileExists(rootPackageJson)) {
|
|
3364
3252
|
buildDependencies.packageJson = [rootPackageJson];
|
|
@@ -3374,7 +3262,7 @@ async function getBuildDependencies(context, config) {
|
|
|
3374
3262
|
}
|
|
3375
3263
|
const tailwindExts = ["ts", "js", "cjs", "mjs"];
|
|
3376
3264
|
const configs = tailwindExts.map(
|
|
3377
|
-
(ext) => (0,
|
|
3265
|
+
(ext) => (0, import_node_path12.join)(context.rootPath, `tailwind.config.${ext}`)
|
|
3378
3266
|
);
|
|
3379
3267
|
const tailwindConfig = findExists(configs);
|
|
3380
3268
|
if (tailwindConfig) {
|
|
@@ -3382,13 +3270,13 @@ async function getBuildDependencies(context, config) {
|
|
|
3382
3270
|
}
|
|
3383
3271
|
return buildDependencies;
|
|
3384
3272
|
}
|
|
3385
|
-
var import_node_crypto,
|
|
3273
|
+
var import_node_crypto, import_node_path12, import_shared25, pluginCache;
|
|
3386
3274
|
var init_cache = __esm({
|
|
3387
3275
|
"src/plugins/cache.ts"() {
|
|
3388
3276
|
"use strict";
|
|
3389
3277
|
import_node_crypto = __toESM(require("crypto"));
|
|
3390
|
-
|
|
3391
|
-
|
|
3278
|
+
import_node_path12 = require("path");
|
|
3279
|
+
import_shared25 = require("@rsbuild/shared");
|
|
3392
3280
|
init_helpers();
|
|
3393
3281
|
pluginCache = () => ({
|
|
3394
3282
|
name: "rsbuild:cache",
|
|
@@ -3428,11 +3316,11 @@ var target_exports = {};
|
|
|
3428
3316
|
__export(target_exports, {
|
|
3429
3317
|
pluginTarget: () => pluginTarget
|
|
3430
3318
|
});
|
|
3431
|
-
var
|
|
3319
|
+
var import_shared26, pluginTarget;
|
|
3432
3320
|
var init_target = __esm({
|
|
3433
3321
|
"src/plugins/target.ts"() {
|
|
3434
3322
|
"use strict";
|
|
3435
|
-
|
|
3323
|
+
import_shared26 = require("@rsbuild/shared");
|
|
3436
3324
|
pluginTarget = () => ({
|
|
3437
3325
|
name: "rsbuild:target",
|
|
3438
3326
|
setup(api) {
|
|
@@ -3444,12 +3332,12 @@ var init_target = __esm({
|
|
|
3444
3332
|
return;
|
|
3445
3333
|
}
|
|
3446
3334
|
const config = api.getNormalizedConfig();
|
|
3447
|
-
const browserslist = await (0,
|
|
3335
|
+
const browserslist = await (0, import_shared26.getBrowserslistWithDefault)(
|
|
3448
3336
|
api.context.rootPath,
|
|
3449
3337
|
config,
|
|
3450
3338
|
target
|
|
3451
3339
|
);
|
|
3452
|
-
const esVersion = (0,
|
|
3340
|
+
const esVersion = (0, import_shared26.browserslistToESVersion)(browserslist);
|
|
3453
3341
|
if (target === "web-worker" || target === "service-worker") {
|
|
3454
3342
|
chain.target(["webworker", `es${esVersion}`]);
|
|
3455
3343
|
return;
|
|
@@ -3493,16 +3381,16 @@ async function applyCSSRule({
|
|
|
3493
3381
|
rule,
|
|
3494
3382
|
config,
|
|
3495
3383
|
context,
|
|
3496
|
-
utils: { target, isProd:
|
|
3384
|
+
utils: { target, isProd: isProd6, CHAIN_ID: CHAIN_ID3 },
|
|
3497
3385
|
importLoaders = 1
|
|
3498
3386
|
}) {
|
|
3499
|
-
const browserslist = await (0,
|
|
3387
|
+
const browserslist = await (0, import_shared27.getBrowserslistWithDefault)(
|
|
3500
3388
|
context.rootPath,
|
|
3501
3389
|
config,
|
|
3502
3390
|
target
|
|
3503
3391
|
);
|
|
3504
3392
|
const enableExtractCSS = isUseCssExtract(config, target);
|
|
3505
|
-
const localIdentName = getCSSModulesLocalIdentName(config,
|
|
3393
|
+
const localIdentName = getCSSModulesLocalIdentName(config, isProd6);
|
|
3506
3394
|
const cssLoaderOptions = getCSSLoaderOptions({
|
|
3507
3395
|
config,
|
|
3508
3396
|
importLoaders,
|
|
@@ -3513,14 +3401,14 @@ async function applyCSSRule({
|
|
|
3513
3401
|
if (enableExtractCSS) {
|
|
3514
3402
|
rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions).end();
|
|
3515
3403
|
} else {
|
|
3516
|
-
const styleLoaderOptions = (0,
|
|
3404
|
+
const styleLoaderOptions = (0, import_shared27.reduceConfigs)({
|
|
3517
3405
|
initial: {},
|
|
3518
3406
|
config: config.tools.styleLoader
|
|
3519
3407
|
});
|
|
3520
3408
|
rule.use(CHAIN_ID3.USE.STYLE).loader(getCompiledPath("style-loader")).options(styleLoaderOptions).end();
|
|
3521
3409
|
}
|
|
3522
3410
|
} else {
|
|
3523
|
-
rule.use(CHAIN_ID3.USE.IGNORE_CSS).loader(
|
|
3411
|
+
rule.use(CHAIN_ID3.USE.IGNORE_CSS).loader(import_node_path13.default.join(LOADER_PATH, "ignoreCssLoader.cjs")).end();
|
|
3524
3412
|
}
|
|
3525
3413
|
rule.use(CHAIN_ID3.USE.CSS).loader(getCompiledPath("css-loader")).options(cssLoaderOptions).end();
|
|
3526
3414
|
if (target === "web") {
|
|
@@ -3534,19 +3422,19 @@ async function applyCSSRule({
|
|
|
3534
3422
|
rule.merge({ sideEffects: true });
|
|
3535
3423
|
rule.resolve.preferRelative(true);
|
|
3536
3424
|
}
|
|
3537
|
-
var
|
|
3425
|
+
var import_node_path13, import_shared27, enableNativeCss, isUseCssExtract, getCSSModulesLocalIdentName, normalizeCssLoaderOptions, userPostcssrcCache, applyAutoprefixer, getPostcssLoaderOptions, getCSSLoaderOptions, pluginCss;
|
|
3538
3426
|
var init_css = __esm({
|
|
3539
3427
|
"src/plugins/css.ts"() {
|
|
3540
3428
|
"use strict";
|
|
3541
|
-
|
|
3542
|
-
|
|
3429
|
+
import_node_path13 = __toESM(require("path"));
|
|
3430
|
+
import_shared27 = require("@rsbuild/shared");
|
|
3543
3431
|
init_constants();
|
|
3544
3432
|
init_helpers();
|
|
3545
3433
|
init_pluginHelper();
|
|
3546
3434
|
enableNativeCss = (config) => !config.output.injectStyles;
|
|
3547
3435
|
isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
|
|
3548
|
-
getCSSModulesLocalIdentName = (config,
|
|
3549
|
-
(
|
|
3436
|
+
getCSSModulesLocalIdentName = (config, isProd6) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
|
|
3437
|
+
(isProd6 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
|
|
3550
3438
|
normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
|
|
3551
3439
|
if (options.modules && exportOnlyLocals) {
|
|
3552
3440
|
let { modules } = options;
|
|
@@ -3573,17 +3461,17 @@ var init_css = __esm({
|
|
|
3573
3461
|
userPostcssrcCache = /* @__PURE__ */ new Map();
|
|
3574
3462
|
applyAutoprefixer = async (plugins, browserslist, config) => {
|
|
3575
3463
|
const pluginObjects = plugins.map(
|
|
3576
|
-
(plugin) => (0,
|
|
3464
|
+
(plugin) => (0, import_shared27.isFunction)(plugin) ? plugin({}) : plugin
|
|
3577
3465
|
);
|
|
3578
3466
|
const hasAutoprefixer = pluginObjects.some((pluginObject) => {
|
|
3579
|
-
if ((0,
|
|
3467
|
+
if ((0, import_shared27.isPlainObject)(pluginObject) && "postcssPlugin" in pluginObject) {
|
|
3580
3468
|
return pluginObject.postcssPlugin === "autoprefixer";
|
|
3581
3469
|
}
|
|
3582
3470
|
return false;
|
|
3583
3471
|
});
|
|
3584
3472
|
if (!hasAutoprefixer) {
|
|
3585
3473
|
const { default: autoprefixer } = await import("@rsbuild/shared/autoprefixer");
|
|
3586
|
-
const autoprefixerOptions = (0,
|
|
3474
|
+
const autoprefixerOptions = (0, import_shared27.reduceConfigs)({
|
|
3587
3475
|
initial: {
|
|
3588
3476
|
flexbox: "no-2009",
|
|
3589
3477
|
overrideBrowserslist: browserslist
|
|
@@ -3623,7 +3511,7 @@ var init_css = __esm({
|
|
|
3623
3511
|
},
|
|
3624
3512
|
sourceMap: config.output.sourceMap.css
|
|
3625
3513
|
};
|
|
3626
|
-
const mergedConfig = (0,
|
|
3514
|
+
const mergedConfig = (0, import_shared27.reduceConfigsWithContext)({
|
|
3627
3515
|
initial: defaultPostcssConfig,
|
|
3628
3516
|
config: config.tools.postcss,
|
|
3629
3517
|
ctx: utils
|
|
@@ -3650,10 +3538,10 @@ var init_css = __esm({
|
|
|
3650
3538
|
},
|
|
3651
3539
|
sourceMap: config.output.sourceMap.css
|
|
3652
3540
|
};
|
|
3653
|
-
const mergedCssLoaderOptions = (0,
|
|
3541
|
+
const mergedCssLoaderOptions = (0, import_shared27.reduceConfigs)({
|
|
3654
3542
|
initial: defaultOptions2,
|
|
3655
3543
|
config: config.tools.cssLoader,
|
|
3656
|
-
mergeFn:
|
|
3544
|
+
mergeFn: import_shared27.deepmerge
|
|
3657
3545
|
});
|
|
3658
3546
|
const cssLoaderOptions = normalizeCssLoaderOptions(
|
|
3659
3547
|
mergedCssLoaderOptions,
|
|
@@ -3693,13 +3581,13 @@ __export(output_exports, {
|
|
|
3693
3581
|
pluginOutput: () => pluginOutput
|
|
3694
3582
|
});
|
|
3695
3583
|
function getPublicPath({
|
|
3696
|
-
isProd:
|
|
3584
|
+
isProd: isProd6,
|
|
3697
3585
|
config,
|
|
3698
3586
|
context
|
|
3699
3587
|
}) {
|
|
3700
3588
|
const { dev, output } = config;
|
|
3701
|
-
let publicPath =
|
|
3702
|
-
if (
|
|
3589
|
+
let publicPath = import_shared28.DEFAULT_ASSET_PREFIX;
|
|
3590
|
+
if (isProd6) {
|
|
3703
3591
|
if (typeof output.assetPrefix === "string") {
|
|
3704
3592
|
publicPath = output.assetPrefix;
|
|
3705
3593
|
}
|
|
@@ -3718,12 +3606,12 @@ function getPublicPath({
|
|
|
3718
3606
|
}
|
|
3719
3607
|
return formatPublicPath(publicPath);
|
|
3720
3608
|
}
|
|
3721
|
-
var
|
|
3609
|
+
var import_node_path14, import_shared28, import_core5, pluginOutput;
|
|
3722
3610
|
var init_output = __esm({
|
|
3723
3611
|
"src/plugins/output.ts"() {
|
|
3724
3612
|
"use strict";
|
|
3725
|
-
|
|
3726
|
-
|
|
3613
|
+
import_node_path14 = require("path");
|
|
3614
|
+
import_shared28 = require("@rsbuild/shared");
|
|
3727
3615
|
import_core5 = require("@rspack/core");
|
|
3728
3616
|
init_constants();
|
|
3729
3617
|
init_helpers();
|
|
@@ -3733,38 +3621,38 @@ var init_output = __esm({
|
|
|
3733
3621
|
name: "rsbuild:output",
|
|
3734
3622
|
setup(api) {
|
|
3735
3623
|
api.modifyBundlerChain(
|
|
3736
|
-
async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd:
|
|
3624
|
+
async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd6, isServer, isServiceWorker }) => {
|
|
3737
3625
|
const config = api.getNormalizedConfig();
|
|
3738
3626
|
const publicPath = getPublicPath({
|
|
3739
3627
|
config,
|
|
3740
|
-
isProd:
|
|
3628
|
+
isProd: isProd6,
|
|
3741
3629
|
context: api.context
|
|
3742
3630
|
});
|
|
3743
|
-
const jsPath = (0,
|
|
3744
|
-
const jsAsyncPath = (0,
|
|
3745
|
-
const jsFilename = (0,
|
|
3631
|
+
const jsPath = (0, import_shared28.getDistPath)(config, "js");
|
|
3632
|
+
const jsAsyncPath = (0, import_shared28.getDistPath)(config, "jsAsync");
|
|
3633
|
+
const jsFilename = (0, import_shared28.getFilename)(config, "js", isProd6);
|
|
3746
3634
|
const isJsFilenameFn = typeof jsFilename === "function";
|
|
3747
3635
|
chain.output.path(api.context.distPath).filename(
|
|
3748
3636
|
isJsFilenameFn ? (...args) => {
|
|
3749
3637
|
const name = jsFilename(...args);
|
|
3750
|
-
return
|
|
3751
|
-
} :
|
|
3638
|
+
return import_node_path14.posix.join(jsPath, name);
|
|
3639
|
+
} : import_node_path14.posix.join(jsPath, jsFilename)
|
|
3752
3640
|
).chunkFilename(
|
|
3753
3641
|
isJsFilenameFn ? (...args) => {
|
|
3754
3642
|
const name = jsFilename(...args);
|
|
3755
|
-
return
|
|
3756
|
-
} :
|
|
3643
|
+
return import_node_path14.posix.join(jsAsyncPath, name);
|
|
3644
|
+
} : import_node_path14.posix.join(jsAsyncPath, jsFilename)
|
|
3757
3645
|
).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
|
|
3758
3646
|
if (isServer) {
|
|
3759
|
-
const serverPath = (0,
|
|
3760
|
-
chain.output.path(
|
|
3647
|
+
const serverPath = (0, import_shared28.getDistPath)(config, "server");
|
|
3648
|
+
chain.output.path(import_node_path14.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
|
|
3761
3649
|
...chain.output.get("library") || {},
|
|
3762
3650
|
type: "commonjs2"
|
|
3763
3651
|
});
|
|
3764
3652
|
}
|
|
3765
3653
|
if (isServiceWorker) {
|
|
3766
|
-
const workerPath = (0,
|
|
3767
|
-
const filename =
|
|
3654
|
+
const workerPath = (0, import_shared28.getDistPath)(config, "worker");
|
|
3655
|
+
const filename = import_node_path14.posix.join(workerPath, "[name].js");
|
|
3768
3656
|
chain.output.filename(filename).chunkFilename(filename);
|
|
3769
3657
|
}
|
|
3770
3658
|
if (config.output.copy && api.context.bundlerType === "rspack") {
|
|
@@ -3774,13 +3662,13 @@ var init_output = __esm({
|
|
|
3774
3662
|
}
|
|
3775
3663
|
if (isUseCssExtract(config, target)) {
|
|
3776
3664
|
const extractPluginOptions = config.tools.cssExtract.pluginOptions;
|
|
3777
|
-
const cssPath = (0,
|
|
3778
|
-
const cssFilename = (0,
|
|
3779
|
-
const cssAsyncPath = (0,
|
|
3665
|
+
const cssPath = (0, import_shared28.getDistPath)(config, "css");
|
|
3666
|
+
const cssFilename = (0, import_shared28.getFilename)(config, "css", isProd6);
|
|
3667
|
+
const cssAsyncPath = (0, import_shared28.getDistPath)(config, "cssAsync");
|
|
3780
3668
|
chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
|
|
3781
3669
|
{
|
|
3782
|
-
filename:
|
|
3783
|
-
chunkFilename:
|
|
3670
|
+
filename: import_node_path14.posix.join(cssPath, cssFilename),
|
|
3671
|
+
chunkFilename: import_node_path14.posix.join(cssAsyncPath, cssFilename),
|
|
3784
3672
|
...extractPluginOptions
|
|
3785
3673
|
}
|
|
3786
3674
|
]);
|
|
@@ -3825,13 +3713,13 @@ function applyAlias({
|
|
|
3825
3713
|
if (!alias) {
|
|
3826
3714
|
return;
|
|
3827
3715
|
}
|
|
3828
|
-
const mergedAlias = (0,
|
|
3716
|
+
const mergedAlias = (0, import_shared29.reduceConfigsWithContext)({
|
|
3829
3717
|
initial: {},
|
|
3830
3718
|
config: alias,
|
|
3831
3719
|
ctx: { target }
|
|
3832
3720
|
});
|
|
3833
3721
|
for (const name of Object.keys(mergedAlias)) {
|
|
3834
|
-
const values = (0,
|
|
3722
|
+
const values = (0, import_shared29.castArray)(mergedAlias[name]);
|
|
3835
3723
|
const formattedValues = values.map((value) => {
|
|
3836
3724
|
if (typeof value === "string" && value.startsWith(".")) {
|
|
3837
3725
|
return ensureAbsolutePath(rootPath, value);
|
|
@@ -3844,11 +3732,11 @@ function applyAlias({
|
|
|
3844
3732
|
);
|
|
3845
3733
|
}
|
|
3846
3734
|
}
|
|
3847
|
-
var
|
|
3735
|
+
var import_shared29, pluginResolve;
|
|
3848
3736
|
var init_resolve = __esm({
|
|
3849
3737
|
"src/plugins/resolve.ts"() {
|
|
3850
3738
|
"use strict";
|
|
3851
|
-
|
|
3739
|
+
import_shared29 = require("@rsbuild/shared");
|
|
3852
3740
|
init_helpers();
|
|
3853
3741
|
pluginResolve = () => ({
|
|
3854
3742
|
name: "rsbuild:resolve",
|
|
@@ -3896,7 +3784,7 @@ async function printHeader(longestFileLength, longestLabelLength) {
|
|
|
3896
3784
|
}
|
|
3897
3785
|
return `${prev + curLabel} `;
|
|
3898
3786
|
}, " ");
|
|
3899
|
-
|
|
3787
|
+
import_shared31.logger.log(import_shared31.color.bold(import_shared31.color.blue(headerRow)));
|
|
3900
3788
|
}
|
|
3901
3789
|
async function printFileSizes(config, stats, rootPath) {
|
|
3902
3790
|
if (config.detail === false && config.total === false) {
|
|
@@ -3905,13 +3793,13 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3905
3793
|
const { default: gzipSize } = await import("@rsbuild/shared/gzip-size");
|
|
3906
3794
|
const formatAsset = (asset, distPath, distFolder) => {
|
|
3907
3795
|
const fileName = asset.name.split("?")[0];
|
|
3908
|
-
const contents =
|
|
3796
|
+
const contents = import_shared30.fse.readFileSync(import_node_path15.default.join(distPath, fileName));
|
|
3909
3797
|
const size = contents.length;
|
|
3910
3798
|
const gzippedSize = gzipSize.sync(contents);
|
|
3911
3799
|
return {
|
|
3912
3800
|
size,
|
|
3913
|
-
folder:
|
|
3914
|
-
name:
|
|
3801
|
+
folder: import_node_path15.default.join(distFolder, import_node_path15.default.dirname(fileName)),
|
|
3802
|
+
name: import_node_path15.default.basename(fileName),
|
|
3915
3803
|
gzippedSize,
|
|
3916
3804
|
sizeLabel: calcFileSize(size),
|
|
3917
3805
|
gzipSizeLabel: getAssetColor(gzippedSize)(calcFileSize(gzippedSize))
|
|
@@ -3938,7 +3826,7 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3938
3826
|
const filteredAssets = origin.assets.filter(
|
|
3939
3827
|
(asset) => filterAsset(asset.name)
|
|
3940
3828
|
);
|
|
3941
|
-
const distFolder =
|
|
3829
|
+
const distFolder = import_node_path15.default.relative(rootPath, distPath);
|
|
3942
3830
|
return filteredAssets.map(
|
|
3943
3831
|
(asset) => formatAsset(asset, distPath, distFolder)
|
|
3944
3832
|
);
|
|
@@ -3947,10 +3835,10 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3947
3835
|
return;
|
|
3948
3836
|
}
|
|
3949
3837
|
assets.sort((a, b) => a.size - b.size);
|
|
3950
|
-
|
|
3838
|
+
import_shared31.logger.info("Production file sizes:\n");
|
|
3951
3839
|
const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
|
|
3952
3840
|
const longestFileLength = Math.max(
|
|
3953
|
-
...assets.map((a) => (a.folder +
|
|
3841
|
+
...assets.map((a) => (a.folder + import_node_path15.default.sep + a.name).length)
|
|
3954
3842
|
);
|
|
3955
3843
|
if (config.detail !== false) {
|
|
3956
3844
|
printHeader(longestFileLength, longestLabelLength);
|
|
@@ -3960,7 +3848,7 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3960
3848
|
for (const asset of assets) {
|
|
3961
3849
|
let { sizeLabel } = asset;
|
|
3962
3850
|
const { name, folder, gzipSizeLabel } = asset;
|
|
3963
|
-
const fileNameLength = (folder +
|
|
3851
|
+
const fileNameLength = (folder + import_node_path15.default.sep + name).length;
|
|
3964
3852
|
const sizeLength = sizeLabel.length;
|
|
3965
3853
|
totalSize += asset.size;
|
|
3966
3854
|
totalGzipSize += asset.gzippedSize;
|
|
@@ -3969,60 +3857,60 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3969
3857
|
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
3970
3858
|
sizeLabel += rightPadding;
|
|
3971
3859
|
}
|
|
3972
|
-
let fileNameLabel =
|
|
3860
|
+
let fileNameLabel = import_shared31.color.dim(asset.folder + import_node_path15.default.sep) + coloringAssetName(asset.name);
|
|
3973
3861
|
if (fileNameLength < longestFileLength) {
|
|
3974
3862
|
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
3975
3863
|
fileNameLabel += rightPadding;
|
|
3976
3864
|
}
|
|
3977
|
-
|
|
3865
|
+
import_shared31.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
3978
3866
|
}
|
|
3979
3867
|
}
|
|
3980
3868
|
if (config.total !== false) {
|
|
3981
|
-
const totalSizeLabel = `${
|
|
3982
|
-
|
|
3869
|
+
const totalSizeLabel = `${import_shared31.color.bold(
|
|
3870
|
+
import_shared31.color.blue("Total size:")
|
|
3983
3871
|
)} ${calcFileSize(totalSize)}`;
|
|
3984
|
-
const gzippedSizeLabel = `${
|
|
3985
|
-
|
|
3872
|
+
const gzippedSizeLabel = `${import_shared31.color.bold(
|
|
3873
|
+
import_shared31.color.blue("Gzipped size:")
|
|
3986
3874
|
)} ${calcFileSize(totalGzipSize)}`;
|
|
3987
|
-
|
|
3875
|
+
import_shared31.logger.log(`
|
|
3988
3876
|
${totalSizeLabel}
|
|
3989
3877
|
${gzippedSizeLabel}
|
|
3990
3878
|
`);
|
|
3991
3879
|
}
|
|
3992
3880
|
}
|
|
3993
|
-
var
|
|
3881
|
+
var import_node_path15, import_shared30, import_shared31, filterAsset, getAssetColor, calcFileSize, coloringAssetName, pluginFileSize;
|
|
3994
3882
|
var init_fileSize = __esm({
|
|
3995
3883
|
"src/plugins/fileSize.ts"() {
|
|
3996
3884
|
"use strict";
|
|
3997
|
-
|
|
3885
|
+
import_node_path15 = __toESM(require("path"));
|
|
3886
|
+
import_shared30 = require("@rsbuild/shared");
|
|
3998
3887
|
import_shared31 = require("@rsbuild/shared");
|
|
3999
|
-
import_shared32 = require("@rsbuild/shared");
|
|
4000
3888
|
init_constants();
|
|
4001
3889
|
filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
4002
3890
|
getAssetColor = (size) => {
|
|
4003
3891
|
if (size > 300 * 1e3) {
|
|
4004
|
-
return
|
|
3892
|
+
return import_shared31.color.red;
|
|
4005
3893
|
}
|
|
4006
3894
|
if (size > 100 * 1e3) {
|
|
4007
|
-
return
|
|
3895
|
+
return import_shared31.color.yellow;
|
|
4008
3896
|
}
|
|
4009
|
-
return
|
|
3897
|
+
return import_shared31.color.green;
|
|
4010
3898
|
};
|
|
4011
3899
|
calcFileSize = (len) => {
|
|
4012
3900
|
const val = len / 1e3;
|
|
4013
3901
|
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
4014
3902
|
};
|
|
4015
3903
|
coloringAssetName = (assetName) => {
|
|
4016
|
-
if (
|
|
4017
|
-
return
|
|
3904
|
+
if (import_shared30.JS_REGEX.test(assetName)) {
|
|
3905
|
+
return import_shared31.color.cyan(assetName);
|
|
4018
3906
|
}
|
|
4019
3907
|
if (CSS_REGEX.test(assetName)) {
|
|
4020
|
-
return
|
|
3908
|
+
return import_shared31.color.yellow(assetName);
|
|
4021
3909
|
}
|
|
4022
3910
|
if (HTML_REGEX.test(assetName)) {
|
|
4023
|
-
return
|
|
3911
|
+
return import_shared31.color.green(assetName);
|
|
4024
3912
|
}
|
|
4025
|
-
return
|
|
3913
|
+
return import_shared31.color.magenta(assetName);
|
|
4026
3914
|
};
|
|
4027
3915
|
pluginFileSize = () => ({
|
|
4028
3916
|
name: "rsbuild:file-size",
|
|
@@ -4044,8 +3932,8 @@ var init_fileSize = __esm({
|
|
|
4044
3932
|
api.context.rootPath
|
|
4045
3933
|
);
|
|
4046
3934
|
} catch (err) {
|
|
4047
|
-
|
|
4048
|
-
|
|
3935
|
+
import_shared31.logger.warn("Failed to print file size.");
|
|
3936
|
+
import_shared31.logger.warn(err);
|
|
4049
3937
|
}
|
|
4050
3938
|
}
|
|
4051
3939
|
});
|
|
@@ -4059,18 +3947,18 @@ var cleanOutput_exports = {};
|
|
|
4059
3947
|
__export(cleanOutput_exports, {
|
|
4060
3948
|
pluginCleanOutput: () => pluginCleanOutput
|
|
4061
3949
|
});
|
|
4062
|
-
var
|
|
3950
|
+
var import_node_path16, import_shared32, emptyDir, addTrailingSep, isStrictSubdir, pluginCleanOutput;
|
|
4063
3951
|
var init_cleanOutput = __esm({
|
|
4064
3952
|
"src/plugins/cleanOutput.ts"() {
|
|
4065
3953
|
"use strict";
|
|
4066
|
-
|
|
4067
|
-
|
|
3954
|
+
import_node_path16 = require("path");
|
|
3955
|
+
import_shared32 = require("@rsbuild/shared");
|
|
4068
3956
|
emptyDir = async (dir) => {
|
|
4069
|
-
if (await
|
|
4070
|
-
await
|
|
3957
|
+
if (await import_shared32.fse.pathExists(dir)) {
|
|
3958
|
+
await import_shared32.fse.emptyDir(dir);
|
|
4071
3959
|
}
|
|
4072
3960
|
};
|
|
4073
|
-
addTrailingSep = (dir) => dir.endsWith(
|
|
3961
|
+
addTrailingSep = (dir) => dir.endsWith(import_node_path16.sep) ? dir : dir + import_node_path16.sep;
|
|
4074
3962
|
isStrictSubdir = (parent, child) => {
|
|
4075
3963
|
const parentDir = addTrailingSep(parent);
|
|
4076
3964
|
const childDir = addTrailingSep(child);
|
|
@@ -4086,14 +3974,14 @@ var init_cleanOutput = __esm({
|
|
|
4086
3974
|
if (cleanDistPath === void 0) {
|
|
4087
3975
|
cleanDistPath = isStrictSubdir(rootPath, distPath);
|
|
4088
3976
|
if (!cleanDistPath) {
|
|
4089
|
-
|
|
3977
|
+
import_shared32.logger.warn(
|
|
4090
3978
|
"The dist path is not a subdir of root path, Rsbuild will not empty it."
|
|
4091
3979
|
);
|
|
4092
|
-
|
|
4093
|
-
`Please set ${
|
|
3980
|
+
import_shared32.logger.warn(
|
|
3981
|
+
`Please set ${import_shared32.color.yellow("`output.cleanDistPath`")} config manually.`
|
|
4094
3982
|
);
|
|
4095
|
-
|
|
4096
|
-
|
|
3983
|
+
import_shared32.logger.warn(`Current root path: ${import_shared32.color.dim(rootPath)}`);
|
|
3984
|
+
import_shared32.logger.warn(`Current dist path: ${import_shared32.color.dim(distPath)}`);
|
|
4097
3985
|
}
|
|
4098
3986
|
}
|
|
4099
3987
|
if (cleanDistPath) {
|
|
@@ -4120,12 +4008,12 @@ function getRegExpForExts(exts) {
|
|
|
4120
4008
|
"i"
|
|
4121
4009
|
);
|
|
4122
4010
|
}
|
|
4123
|
-
var
|
|
4011
|
+
var import_node_path17, import_shared33, chainStaticAssetRule, pluginAsset;
|
|
4124
4012
|
var init_asset = __esm({
|
|
4125
4013
|
"src/plugins/asset.ts"() {
|
|
4126
4014
|
"use strict";
|
|
4127
|
-
|
|
4128
|
-
|
|
4015
|
+
import_node_path17 = __toESM(require("path"));
|
|
4016
|
+
import_shared33 = require("@rsbuild/shared");
|
|
4129
4017
|
init_constants();
|
|
4130
4018
|
chainStaticAssetRule = ({
|
|
4131
4019
|
emit,
|
|
@@ -4151,12 +4039,12 @@ var init_asset = __esm({
|
|
|
4151
4039
|
pluginAsset = () => ({
|
|
4152
4040
|
name: "rsbuild:asset",
|
|
4153
4041
|
setup(api) {
|
|
4154
|
-
api.modifyBundlerChain((chain, { isProd:
|
|
4042
|
+
api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
|
|
4155
4043
|
const config = api.getNormalizedConfig();
|
|
4156
4044
|
const createAssetRule = (assetType, exts, emit2) => {
|
|
4157
4045
|
const regExp = getRegExpForExts(exts);
|
|
4158
|
-
const distDir = (0,
|
|
4159
|
-
const filename = (0,
|
|
4046
|
+
const distDir = (0, import_shared33.getDistPath)(config, assetType);
|
|
4047
|
+
const filename = (0, import_shared33.getFilename)(config, assetType, isProd6);
|
|
4160
4048
|
const { dataUriLimit } = config.output;
|
|
4161
4049
|
const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
|
|
4162
4050
|
const rule = chain.module.rule(assetType).test(regExp);
|
|
@@ -4164,7 +4052,7 @@ var init_asset = __esm({
|
|
|
4164
4052
|
emit: emit2,
|
|
4165
4053
|
rule,
|
|
4166
4054
|
maxSize,
|
|
4167
|
-
filename:
|
|
4055
|
+
filename: import_node_path17.default.posix.join(distDir, filename),
|
|
4168
4056
|
assetType
|
|
4169
4057
|
});
|
|
4170
4058
|
};
|
|
@@ -4190,24 +4078,24 @@ __export(minimize_exports, {
|
|
|
4190
4078
|
parseMinifyOptions: () => parseMinifyOptions,
|
|
4191
4079
|
pluginMinimize: () => pluginMinimize
|
|
4192
4080
|
});
|
|
4193
|
-
var
|
|
4081
|
+
var import_shared34, import_core6, getSwcMinimizerOptions, parseMinifyOptions, pluginMinimize;
|
|
4194
4082
|
var init_minimize = __esm({
|
|
4195
4083
|
"src/plugins/minimize.ts"() {
|
|
4196
4084
|
"use strict";
|
|
4197
|
-
|
|
4085
|
+
import_shared34 = require("@rsbuild/shared");
|
|
4198
4086
|
import_core6 = require("@rspack/core");
|
|
4199
4087
|
getSwcMinimizerOptions = (config) => {
|
|
4200
4088
|
const options = {};
|
|
4201
4089
|
const { removeConsole } = config.performance;
|
|
4202
4090
|
if (removeConsole === true) {
|
|
4203
4091
|
options.compress = {
|
|
4204
|
-
...(0,
|
|
4092
|
+
...(0, import_shared34.isObject)(options.compress) ? options.compress : {},
|
|
4205
4093
|
drop_console: true
|
|
4206
4094
|
};
|
|
4207
4095
|
} else if (Array.isArray(removeConsole)) {
|
|
4208
4096
|
const pureFuncs = removeConsole.map((method) => `console.${method}`);
|
|
4209
4097
|
options.compress = {
|
|
4210
|
-
...(0,
|
|
4098
|
+
...(0, import_shared34.isObject)(options.compress) ? options.compress : {},
|
|
4211
4099
|
pure_funcs: pureFuncs
|
|
4212
4100
|
};
|
|
4213
4101
|
}
|
|
@@ -4230,13 +4118,13 @@ var init_minimize = __esm({
|
|
|
4230
4118
|
options.format.asciiOnly = config.output.charset === "ascii";
|
|
4231
4119
|
const jsOptions = parseMinifyOptions(config).jsOptions;
|
|
4232
4120
|
if (jsOptions) {
|
|
4233
|
-
return (0,
|
|
4121
|
+
return (0, import_shared34.deepmerge)(options, jsOptions);
|
|
4234
4122
|
}
|
|
4235
4123
|
return options;
|
|
4236
4124
|
};
|
|
4237
|
-
parseMinifyOptions = (config,
|
|
4125
|
+
parseMinifyOptions = (config, isProd6 = true) => {
|
|
4238
4126
|
const minify = config.output.minify;
|
|
4239
|
-
if (minify === false || !
|
|
4127
|
+
if (minify === false || !isProd6) {
|
|
4240
4128
|
return {
|
|
4241
4129
|
minifyJs: false,
|
|
4242
4130
|
minifyCss: false,
|
|
@@ -4268,19 +4156,19 @@ var init_minimize = __esm({
|
|
|
4268
4156
|
if (api.context.bundlerType === "webpack") {
|
|
4269
4157
|
return;
|
|
4270
4158
|
}
|
|
4271
|
-
api.modifyBundlerChain(async (chain, { isProd:
|
|
4159
|
+
api.modifyBundlerChain(async (chain, { isProd: isProd6 }) => {
|
|
4272
4160
|
const config = api.getNormalizedConfig();
|
|
4273
|
-
const isMinimize =
|
|
4161
|
+
const isMinimize = isProd6 && config.output.minify !== false;
|
|
4274
4162
|
if (!isMinimize) {
|
|
4275
4163
|
return;
|
|
4276
4164
|
}
|
|
4277
4165
|
const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } = import_core6.rspack;
|
|
4278
4166
|
const { minifyJs, minifyCss } = parseMinifyOptions(config);
|
|
4279
4167
|
if (minifyJs) {
|
|
4280
|
-
chain.optimization.minimizer(
|
|
4168
|
+
chain.optimization.minimizer(import_shared34.CHAIN_ID.MINIMIZER.JS).use(SwcJsMinimizerRspackPlugin, [getSwcMinimizerOptions(config)]).end();
|
|
4281
4169
|
}
|
|
4282
4170
|
if (minifyCss) {
|
|
4283
|
-
chain.optimization.minimizer(
|
|
4171
|
+
chain.optimization.minimizer(import_shared34.CHAIN_ID.MINIMIZER.CSS).use(SwcCssMinimizerRspackPlugin, []).end();
|
|
4284
4172
|
}
|
|
4285
4173
|
});
|
|
4286
4174
|
}
|
|
@@ -4297,11 +4185,12 @@ __export(HtmlBasicPlugin_exports, {
|
|
|
4297
4185
|
VOID_TAGS: () => VOID_TAGS,
|
|
4298
4186
|
hasTitle: () => hasTitle
|
|
4299
4187
|
});
|
|
4300
|
-
var
|
|
4188
|
+
var import_shared35, VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, addFavicon, HtmlBasicPlugin;
|
|
4301
4189
|
var init_HtmlBasicPlugin = __esm({
|
|
4302
4190
|
"src/rspack/HtmlBasicPlugin.ts"() {
|
|
4303
4191
|
"use strict";
|
|
4304
|
-
|
|
4192
|
+
import_shared35 = require("@rsbuild/shared");
|
|
4193
|
+
init_helpers();
|
|
4305
4194
|
init_pluginHelper();
|
|
4306
4195
|
VOID_TAGS = [
|
|
4307
4196
|
"area",
|
|
@@ -4376,9 +4265,9 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
4376
4265
|
if (typeof optPublicPath === "function") {
|
|
4377
4266
|
filename = optPublicPath(filename, data.publicPath);
|
|
4378
4267
|
} else if (typeof optPublicPath === "string") {
|
|
4379
|
-
filename = (
|
|
4268
|
+
filename = ensureAssetPrefix(filename, optPublicPath);
|
|
4380
4269
|
} else if (optPublicPath !== false) {
|
|
4381
|
-
filename = (
|
|
4270
|
+
filename = ensureAssetPrefix(filename, data.publicPath);
|
|
4382
4271
|
}
|
|
4383
4272
|
const optHash = tag.hash ?? tagConfig.hash;
|
|
4384
4273
|
if (typeof optHash === "function") {
|
|
@@ -4412,7 +4301,7 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
4412
4301
|
publicPath: data.publicPath
|
|
4413
4302
|
};
|
|
4414
4303
|
for (const item of tagConfig.tags) {
|
|
4415
|
-
if ((0,
|
|
4304
|
+
if ((0, import_shared35.isFunction)(item)) {
|
|
4416
4305
|
tags = item(tags, utils) || tags;
|
|
4417
4306
|
} else {
|
|
4418
4307
|
tags.push(item);
|
|
@@ -4421,7 +4310,7 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
4421
4310
|
(tag1, tag2) => getTagPriority(tag1, tagConfig) - getTagPriority(tag2, tagConfig)
|
|
4422
4311
|
);
|
|
4423
4312
|
}
|
|
4424
|
-
const [headTags, bodyTags] = (0,
|
|
4313
|
+
const [headTags, bodyTags] = (0, import_shared35.partition)(
|
|
4425
4314
|
tags,
|
|
4426
4315
|
(tag) => tag.head ?? HEAD_TAGS.includes(tag.tag)
|
|
4427
4316
|
);
|
|
@@ -4503,13 +4392,14 @@ var HtmlAppIconPlugin_exports = {};
|
|
|
4503
4392
|
__export(HtmlAppIconPlugin_exports, {
|
|
4504
4393
|
HtmlAppIconPlugin: () => HtmlAppIconPlugin
|
|
4505
4394
|
});
|
|
4506
|
-
var import_node_fs4,
|
|
4395
|
+
var import_node_fs4, import_node_path18, import_shared36, HtmlAppIconPlugin;
|
|
4507
4396
|
var init_HtmlAppIconPlugin = __esm({
|
|
4508
4397
|
"src/rspack/HtmlAppIconPlugin.ts"() {
|
|
4509
4398
|
"use strict";
|
|
4510
4399
|
import_node_fs4 = __toESM(require("fs"));
|
|
4511
|
-
|
|
4512
|
-
|
|
4400
|
+
import_node_path18 = require("path");
|
|
4401
|
+
import_shared36 = require("@rsbuild/shared");
|
|
4402
|
+
init_helpers();
|
|
4513
4403
|
init_pluginHelper();
|
|
4514
4404
|
HtmlAppIconPlugin = class {
|
|
4515
4405
|
constructor(options) {
|
|
@@ -4526,17 +4416,17 @@ var init_HtmlAppIconPlugin = __esm({
|
|
|
4526
4416
|
`[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
|
|
4527
4417
|
);
|
|
4528
4418
|
}
|
|
4529
|
-
const iconRelativePath =
|
|
4419
|
+
const iconRelativePath = import_node_path18.posix.join(this.distDir, (0, import_node_path18.basename)(this.iconPath));
|
|
4530
4420
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
4531
4421
|
getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
|
|
4532
|
-
const publicPath = (0,
|
|
4422
|
+
const publicPath = (0, import_shared36.getPublicPathFromCompiler)(compiler);
|
|
4533
4423
|
data.headTags.unshift({
|
|
4534
4424
|
tagName: "link",
|
|
4535
4425
|
voidTag: true,
|
|
4536
4426
|
attributes: {
|
|
4537
4427
|
rel: "apple-touch-icon",
|
|
4538
4428
|
sizes: "180*180",
|
|
4539
|
-
href: (
|
|
4429
|
+
href: ensureAssetPrefix(iconRelativePath, publicPath)
|
|
4540
4430
|
},
|
|
4541
4431
|
meta: {}
|
|
4542
4432
|
});
|
|
@@ -4609,8 +4499,8 @@ function getTerserMinifyOptions(config) {
|
|
|
4609
4499
|
const finalOptions = applyRemoveConsole(options, config);
|
|
4610
4500
|
return finalOptions;
|
|
4611
4501
|
}
|
|
4612
|
-
async function getHtmlMinifyOptions(
|
|
4613
|
-
if (!
|
|
4502
|
+
async function getHtmlMinifyOptions(isProd6, config) {
|
|
4503
|
+
if (!isProd6 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
|
|
4614
4504
|
return false;
|
|
4615
4505
|
}
|
|
4616
4506
|
const minifyJS = getTerserMinifyOptions(config);
|
|
@@ -4628,25 +4518,25 @@ async function getHtmlMinifyOptions(isProd5, config) {
|
|
|
4628
4518
|
minifyURLs: true
|
|
4629
4519
|
};
|
|
4630
4520
|
const htmlMinifyOptions = parseMinifyOptions(config).htmlOptions;
|
|
4631
|
-
return typeof htmlMinifyOptions === "object" ? (0,
|
|
4521
|
+
return typeof htmlMinifyOptions === "object" ? (0, import_shared37.deepmerge)(htmlMinifyDefaultOptions, htmlMinifyOptions) : htmlMinifyDefaultOptions;
|
|
4632
4522
|
}
|
|
4633
4523
|
function getTitle(entryName, config) {
|
|
4634
|
-
return (0,
|
|
4524
|
+
return (0, import_shared37.reduceConfigsMergeContext)({
|
|
4635
4525
|
initial: "",
|
|
4636
4526
|
config: config.html.title,
|
|
4637
4527
|
ctx: { entryName }
|
|
4638
4528
|
});
|
|
4639
4529
|
}
|
|
4640
4530
|
function getInject(entryName, config) {
|
|
4641
|
-
return (0,
|
|
4531
|
+
return (0, import_shared37.reduceConfigsMergeContext)({
|
|
4642
4532
|
initial: "head",
|
|
4643
4533
|
config: config.html.inject,
|
|
4644
4534
|
ctx: { entryName }
|
|
4645
4535
|
});
|
|
4646
4536
|
}
|
|
4647
4537
|
async function getTemplate(entryName, config, rootPath) {
|
|
4648
|
-
const DEFAULT_TEMPLATE =
|
|
4649
|
-
const templatePath = (0,
|
|
4538
|
+
const DEFAULT_TEMPLATE = import_node_path19.default.resolve(STATIC_PATH, "template.html");
|
|
4539
|
+
const templatePath = (0, import_shared37.reduceConfigsMergeContext)({
|
|
4650
4540
|
initial: DEFAULT_TEMPLATE,
|
|
4651
4541
|
config: config.html.template,
|
|
4652
4542
|
ctx: { entryName }
|
|
@@ -4656,32 +4546,32 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
4656
4546
|
templatePath
|
|
4657
4547
|
};
|
|
4658
4548
|
}
|
|
4659
|
-
const absolutePath = (0,
|
|
4549
|
+
const absolutePath = (0, import_node_path19.isAbsolute)(templatePath) ? templatePath : import_node_path19.default.resolve(rootPath, templatePath);
|
|
4660
4550
|
if (!existTemplatePath.includes(absolutePath)) {
|
|
4661
4551
|
if (!await isFileExists(absolutePath)) {
|
|
4662
4552
|
throw new Error(
|
|
4663
|
-
`Failed to resolve HTML template, please check if the file exists: ${
|
|
4553
|
+
`Failed to resolve HTML template, please check if the file exists: ${import_shared37.color.cyan(
|
|
4664
4554
|
absolutePath
|
|
4665
4555
|
)}`
|
|
4666
4556
|
);
|
|
4667
4557
|
}
|
|
4668
4558
|
existTemplatePath.push(absolutePath);
|
|
4669
4559
|
}
|
|
4670
|
-
const templateContent = await
|
|
4560
|
+
const templateContent = await import_shared37.fse.readFile(absolutePath, "utf-8");
|
|
4671
4561
|
return {
|
|
4672
4562
|
templatePath: absolutePath,
|
|
4673
4563
|
templateContent
|
|
4674
4564
|
};
|
|
4675
4565
|
}
|
|
4676
4566
|
function getFavicon(entryName, config) {
|
|
4677
|
-
return (0,
|
|
4567
|
+
return (0, import_shared37.reduceConfigsMergeContext)({
|
|
4678
4568
|
initial: "",
|
|
4679
4569
|
config: config.html.favicon,
|
|
4680
4570
|
ctx: { entryName }
|
|
4681
4571
|
});
|
|
4682
4572
|
}
|
|
4683
4573
|
function getMetaTags(entryName, config, templateContent) {
|
|
4684
|
-
const metaTags = (0,
|
|
4574
|
+
const metaTags = (0, import_shared37.reduceConfigsMergeContext)({
|
|
4685
4575
|
initial: {},
|
|
4686
4576
|
config: config.html.meta,
|
|
4687
4577
|
ctx: { entryName }
|
|
@@ -4709,7 +4599,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
|
|
|
4709
4599
|
options: pluginOptions
|
|
4710
4600
|
}
|
|
4711
4601
|
};
|
|
4712
|
-
return (0,
|
|
4602
|
+
return (0, import_shared37.reduceConfigsWithContext)({
|
|
4713
4603
|
initial: defaultOptions2,
|
|
4714
4604
|
config: templateParameters,
|
|
4715
4605
|
ctx: { entryName }
|
|
@@ -4719,7 +4609,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
|
|
|
4719
4609
|
function getChunks(entryName, entryValue) {
|
|
4720
4610
|
const chunks = [entryName];
|
|
4721
4611
|
for (const item of entryValue) {
|
|
4722
|
-
if (!(0,
|
|
4612
|
+
if (!(0, import_shared37.isPlainObject)(item)) {
|
|
4723
4613
|
continue;
|
|
4724
4614
|
}
|
|
4725
4615
|
const { dependOn } = item;
|
|
@@ -4734,19 +4624,19 @@ function getChunks(entryName, entryValue) {
|
|
|
4734
4624
|
}
|
|
4735
4625
|
return chunks;
|
|
4736
4626
|
}
|
|
4737
|
-
var
|
|
4627
|
+
var import_node_path19, import_shared37, existTemplatePath, getTagConfig, pluginHtml;
|
|
4738
4628
|
var init_html = __esm({
|
|
4739
4629
|
"src/plugins/html.ts"() {
|
|
4740
4630
|
"use strict";
|
|
4741
|
-
|
|
4742
|
-
|
|
4631
|
+
import_node_path19 = __toESM(require("path"));
|
|
4632
|
+
import_shared37 = require("@rsbuild/shared");
|
|
4743
4633
|
init_constants();
|
|
4744
4634
|
init_helpers();
|
|
4745
4635
|
init_minimize();
|
|
4746
4636
|
existTemplatePath = [];
|
|
4747
4637
|
getTagConfig = (api) => {
|
|
4748
4638
|
const config = api.getNormalizedConfig();
|
|
4749
|
-
const tags = (0,
|
|
4639
|
+
const tags = (0, import_shared37.castArray)(config.html.tags).filter(Boolean);
|
|
4750
4640
|
if (!tags.length) {
|
|
4751
4641
|
return void 0;
|
|
4752
4642
|
}
|
|
@@ -4761,12 +4651,12 @@ var init_html = __esm({
|
|
|
4761
4651
|
name: "rsbuild:html",
|
|
4762
4652
|
setup(api) {
|
|
4763
4653
|
api.modifyBundlerChain(
|
|
4764
|
-
async (chain, { HtmlPlugin, isProd:
|
|
4654
|
+
async (chain, { HtmlPlugin, isProd: isProd6, CHAIN_ID: CHAIN_ID3, target }) => {
|
|
4765
4655
|
const config = api.getNormalizedConfig();
|
|
4766
|
-
if ((0,
|
|
4656
|
+
if ((0, import_shared37.isHtmlDisabled)(config, target)) {
|
|
4767
4657
|
return;
|
|
4768
4658
|
}
|
|
4769
|
-
const minify = await getHtmlMinifyOptions(
|
|
4659
|
+
const minify = await getHtmlMinifyOptions(isProd6, config);
|
|
4770
4660
|
const assetPrefix = getPublicPathFromChain(chain, false);
|
|
4771
4661
|
const entries = chain.entryPoints.entries() || {};
|
|
4772
4662
|
const entryNames = Object.keys(entries);
|
|
@@ -4815,13 +4705,13 @@ var init_html = __esm({
|
|
|
4815
4705
|
pluginOptions.title = getTitle(entryName, config);
|
|
4816
4706
|
const favicon = getFavicon(entryName, config);
|
|
4817
4707
|
if (favicon) {
|
|
4818
|
-
if ((0,
|
|
4708
|
+
if ((0, import_shared37.isURL)(favicon)) {
|
|
4819
4709
|
htmlInfo.favicon = favicon;
|
|
4820
4710
|
} else {
|
|
4821
4711
|
pluginOptions.favicon = favicon;
|
|
4822
4712
|
}
|
|
4823
4713
|
}
|
|
4824
|
-
const finalOptions2 = (0,
|
|
4714
|
+
const finalOptions2 = (0, import_shared37.reduceConfigsWithContext)({
|
|
4825
4715
|
initial: pluginOptions,
|
|
4826
4716
|
config: typeof config.tools.htmlPlugin === "boolean" ? {} : config.tools.htmlPlugin,
|
|
4827
4717
|
ctx: { entryName, entryValue }
|
|
@@ -4842,8 +4732,8 @@ var init_html = __esm({
|
|
|
4842
4732
|
}
|
|
4843
4733
|
if (appIcon) {
|
|
4844
4734
|
const { HtmlAppIconPlugin: HtmlAppIconPlugin2 } = await Promise.resolve().then(() => (init_HtmlAppIconPlugin(), HtmlAppIconPlugin_exports));
|
|
4845
|
-
const distDir = (0,
|
|
4846
|
-
const iconPath =
|
|
4735
|
+
const distDir = (0, import_shared37.getDistPath)(config, "image");
|
|
4736
|
+
const iconPath = import_node_path19.default.isAbsolute(appIcon) ? appIcon : import_node_path19.default.join(api.context.rootPath, appIcon);
|
|
4847
4737
|
chain.plugin(CHAIN_ID3.PLUGIN.APP_ICON).use(HtmlAppIconPlugin2, [{ iconPath, distDir }]);
|
|
4848
4738
|
}
|
|
4849
4739
|
}
|
|
@@ -4877,23 +4767,23 @@ var wasm_exports = {};
|
|
|
4877
4767
|
__export(wasm_exports, {
|
|
4878
4768
|
pluginWasm: () => pluginWasm
|
|
4879
4769
|
});
|
|
4880
|
-
var
|
|
4770
|
+
var import_node_path20, import_shared38, pluginWasm;
|
|
4881
4771
|
var init_wasm = __esm({
|
|
4882
4772
|
"src/plugins/wasm.ts"() {
|
|
4883
4773
|
"use strict";
|
|
4884
|
-
|
|
4885
|
-
|
|
4774
|
+
import_node_path20 = require("path");
|
|
4775
|
+
import_shared38 = require("@rsbuild/shared");
|
|
4886
4776
|
pluginWasm = () => ({
|
|
4887
4777
|
name: "rsbuild:wasm",
|
|
4888
4778
|
setup(api) {
|
|
4889
4779
|
api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
|
|
4890
4780
|
const config = api.getNormalizedConfig();
|
|
4891
|
-
const distPath = (0,
|
|
4781
|
+
const distPath = (0, import_shared38.getDistPath)(config, "wasm");
|
|
4892
4782
|
chain.experiments({
|
|
4893
4783
|
...chain.get("experiments"),
|
|
4894
4784
|
asyncWebAssembly: true
|
|
4895
4785
|
});
|
|
4896
|
-
const wasmFilename =
|
|
4786
|
+
const wasmFilename = import_node_path20.posix.join(distPath, "[hash].module.wasm");
|
|
4897
4787
|
chain.output.merge({
|
|
4898
4788
|
webassemblyModuleFilename: wasmFilename
|
|
4899
4789
|
});
|
|
@@ -4941,15 +4831,15 @@ var nodeAddons_exports = {};
|
|
|
4941
4831
|
__export(nodeAddons_exports, {
|
|
4942
4832
|
pluginNodeAddons: () => pluginNodeAddons
|
|
4943
4833
|
});
|
|
4944
|
-
var
|
|
4834
|
+
var import_node_path21, getFilename3, pluginNodeAddons;
|
|
4945
4835
|
var init_nodeAddons = __esm({
|
|
4946
4836
|
"src/plugins/nodeAddons.ts"() {
|
|
4947
4837
|
"use strict";
|
|
4948
|
-
|
|
4838
|
+
import_node_path21 = __toESM(require("path"));
|
|
4949
4839
|
getFilename3 = (resourcePath) => {
|
|
4950
4840
|
let basename2 = "";
|
|
4951
4841
|
if (resourcePath) {
|
|
4952
|
-
const parsed =
|
|
4842
|
+
const parsed = import_node_path21.default.parse(resourcePath);
|
|
4953
4843
|
if (parsed.dir) {
|
|
4954
4844
|
basename2 = parsed.name;
|
|
4955
4845
|
}
|
|
@@ -4990,11 +4880,11 @@ var define_exports = {};
|
|
|
4990
4880
|
__export(define_exports, {
|
|
4991
4881
|
pluginDefine: () => pluginDefine
|
|
4992
4882
|
});
|
|
4993
|
-
var
|
|
4883
|
+
var import_shared39, pluginDefine;
|
|
4994
4884
|
var init_define = __esm({
|
|
4995
4885
|
"src/plugins/define.ts"() {
|
|
4996
4886
|
"use strict";
|
|
4997
|
-
|
|
4887
|
+
import_shared39 = require("@rsbuild/shared");
|
|
4998
4888
|
init_helpers();
|
|
4999
4889
|
pluginDefine = () => ({
|
|
5000
4890
|
name: "rsbuild:define",
|
|
@@ -5002,7 +4892,7 @@ var init_define = __esm({
|
|
|
5002
4892
|
api.modifyBundlerChain((chain, { CHAIN_ID: CHAIN_ID3, bundler }) => {
|
|
5003
4893
|
const config = api.getNormalizedConfig();
|
|
5004
4894
|
const builtinVars = {
|
|
5005
|
-
"process.env.NODE_ENV": JSON.stringify((0,
|
|
4895
|
+
"process.env.NODE_ENV": JSON.stringify((0, import_shared39.getNodeEnv)()),
|
|
5006
4896
|
"process.env.ASSET_PREFIX": JSON.stringify(
|
|
5007
4897
|
getPublicPathFromChain(chain, false)
|
|
5008
4898
|
)
|
|
@@ -5021,11 +4911,11 @@ var progress_exports = {};
|
|
|
5021
4911
|
__export(progress_exports, {
|
|
5022
4912
|
pluginProgress: () => pluginProgress
|
|
5023
4913
|
});
|
|
5024
|
-
var
|
|
4914
|
+
var import_shared40, import_core7, pluginProgress;
|
|
5025
4915
|
var init_progress = __esm({
|
|
5026
4916
|
"src/plugins/progress.ts"() {
|
|
5027
4917
|
"use strict";
|
|
5028
|
-
|
|
4918
|
+
import_shared40 = require("@rsbuild/shared");
|
|
5029
4919
|
import_core7 = require("@rspack/core");
|
|
5030
4920
|
pluginProgress = () => ({
|
|
5031
4921
|
name: "rsbuild:progress",
|
|
@@ -5036,11 +4926,11 @@ var init_progress = __esm({
|
|
|
5036
4926
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3 }) => {
|
|
5037
4927
|
const config = api.getNormalizedConfig();
|
|
5038
4928
|
const options = config.dev.progressBar ?? // enable progress bar in production by default
|
|
5039
|
-
(0,
|
|
4929
|
+
(0, import_shared40.isProd)();
|
|
5040
4930
|
if (!options) {
|
|
5041
4931
|
return;
|
|
5042
4932
|
}
|
|
5043
|
-
const prefix = options !== true && options.id !== void 0 ? options.id :
|
|
4933
|
+
const prefix = options !== true && options.id !== void 0 ? options.id : import_shared40.TARGET_ID_MAP[target];
|
|
5044
4934
|
chain.plugin(CHAIN_ID3.PLUGIN.PROGRESS).use(import_core7.rspack.ProgressPlugin, [
|
|
5045
4935
|
{
|
|
5046
4936
|
prefix,
|
|
@@ -5074,14 +4964,14 @@ async function getDefaultSwcConfig(config, rootPath, target) {
|
|
|
5074
4964
|
},
|
|
5075
4965
|
isModule: "unknown",
|
|
5076
4966
|
env: {
|
|
5077
|
-
targets: await (0,
|
|
4967
|
+
targets: await (0, import_shared41.getBrowserslistWithDefault)(rootPath, config, target)
|
|
5078
4968
|
}
|
|
5079
4969
|
};
|
|
5080
4970
|
}
|
|
5081
4971
|
async function applyCoreJs(swcConfig, polyfillMode) {
|
|
5082
4972
|
const coreJsPath = require.resolve("core-js/package.json");
|
|
5083
|
-
const version2 = (0,
|
|
5084
|
-
const coreJsDir =
|
|
4973
|
+
const version2 = (0, import_shared41.getCoreJsVersion)(coreJsPath);
|
|
4974
|
+
const coreJsDir = import_node_path22.default.dirname(coreJsPath);
|
|
5085
4975
|
swcConfig.env.coreJs = version2;
|
|
5086
4976
|
if (polyfillMode === "usage") {
|
|
5087
4977
|
swcConfig.env.shippedProposals = true;
|
|
@@ -5113,12 +5003,12 @@ function applySwcDecoratorConfig(swcConfig, config) {
|
|
|
5113
5003
|
throw new Error("Unknown decorators version: ${version}");
|
|
5114
5004
|
}
|
|
5115
5005
|
}
|
|
5116
|
-
var
|
|
5006
|
+
var import_node_path22, import_shared41, builtinSwcLoaderName, pluginSwc;
|
|
5117
5007
|
var init_swc = __esm({
|
|
5118
5008
|
"src/plugins/swc.ts"() {
|
|
5119
5009
|
"use strict";
|
|
5120
|
-
|
|
5121
|
-
|
|
5010
|
+
import_node_path22 = __toESM(require("path"));
|
|
5011
|
+
import_shared41 = require("@rsbuild/shared");
|
|
5122
5012
|
init_constants();
|
|
5123
5013
|
builtinSwcLoaderName = "builtin:swc-loader";
|
|
5124
5014
|
pluginSwc = () => ({
|
|
@@ -5131,11 +5021,11 @@ var init_swc = __esm({
|
|
|
5131
5021
|
order: "pre",
|
|
5132
5022
|
handler: async (chain, { CHAIN_ID: CHAIN_ID3, target }) => {
|
|
5133
5023
|
const config = api.getNormalizedConfig();
|
|
5134
|
-
const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(
|
|
5024
|
+
const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared41.SCRIPT_REGEX).type("javascript/auto");
|
|
5135
5025
|
const dataUriRule = chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
|
|
5136
5026
|
or: ["text/javascript", "application/javascript"]
|
|
5137
5027
|
});
|
|
5138
|
-
(0,
|
|
5028
|
+
(0, import_shared41.applyScriptCondition)({
|
|
5139
5029
|
rule,
|
|
5140
5030
|
chain,
|
|
5141
5031
|
config,
|
|
@@ -5153,10 +5043,10 @@ var init_swc = __esm({
|
|
|
5153
5043
|
if (swcConfig.jsc?.externalHelpers) {
|
|
5154
5044
|
chain.resolve.alias.set(
|
|
5155
5045
|
"@swc/helpers",
|
|
5156
|
-
|
|
5046
|
+
import_node_path22.default.dirname(require.resolve("@swc/helpers/package.json"))
|
|
5157
5047
|
);
|
|
5158
5048
|
}
|
|
5159
|
-
if ((0,
|
|
5049
|
+
if ((0, import_shared41.isWebTarget)(target)) {
|
|
5160
5050
|
const polyfillMode = config.output.polyfill;
|
|
5161
5051
|
if (polyfillMode === "off") {
|
|
5162
5052
|
swcConfig.env.mode = void 0;
|
|
@@ -5168,13 +5058,13 @@ var init_swc = __esm({
|
|
|
5168
5058
|
}
|
|
5169
5059
|
}
|
|
5170
5060
|
}
|
|
5171
|
-
const mergedSwcConfig = (0,
|
|
5061
|
+
const mergedSwcConfig = (0, import_shared41.reduceConfigs)({
|
|
5172
5062
|
initial: swcConfig,
|
|
5173
5063
|
config: config.tools.swc,
|
|
5174
|
-
mergeFn:
|
|
5064
|
+
mergeFn: import_shared41.deepmerge
|
|
5175
5065
|
});
|
|
5176
5066
|
rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
|
|
5177
|
-
dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0,
|
|
5067
|
+
dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared41.cloneDeep)(mergedSwcConfig));
|
|
5178
5068
|
}
|
|
5179
5069
|
});
|
|
5180
5070
|
}
|
|
@@ -5241,11 +5131,11 @@ function splitByExperience(ctx) {
|
|
|
5241
5131
|
const { override, polyfill, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
5242
5132
|
const experienceCacheGroup = {};
|
|
5243
5133
|
const packageRegExps = {
|
|
5244
|
-
lodash: (0,
|
|
5245
|
-
axios: (0,
|
|
5134
|
+
lodash: (0, import_shared42.createDependenciesRegExp)("lodash", "lodash-es"),
|
|
5135
|
+
axios: (0, import_shared42.createDependenciesRegExp)("axios", /axios-.+/)
|
|
5246
5136
|
};
|
|
5247
5137
|
if (polyfill === "entry" || polyfill === "usage") {
|
|
5248
|
-
packageRegExps.polyfill = (0,
|
|
5138
|
+
packageRegExps.polyfill = (0, import_shared42.createDependenciesRegExp)(
|
|
5249
5139
|
"tslib",
|
|
5250
5140
|
"core-js",
|
|
5251
5141
|
"@babel/runtime",
|
|
@@ -5294,7 +5184,7 @@ function splitByModule(ctx) {
|
|
|
5294
5184
|
// Core group
|
|
5295
5185
|
vendors: {
|
|
5296
5186
|
priority: -9,
|
|
5297
|
-
test:
|
|
5187
|
+
test: import_shared42.NODE_MODULES_REGEX,
|
|
5298
5188
|
name(module2) {
|
|
5299
5189
|
return module2 ? getPackageNameFromModulePath(module2.context) : void 0;
|
|
5300
5190
|
}
|
|
@@ -5337,7 +5227,7 @@ function singleVendor(ctx) {
|
|
|
5337
5227
|
const { override, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
5338
5228
|
const singleVendorCacheGroup = {
|
|
5339
5229
|
singleVendor: {
|
|
5340
|
-
test:
|
|
5230
|
+
test: import_shared42.NODE_MODULES_REGEX,
|
|
5341
5231
|
priority: 0,
|
|
5342
5232
|
chunks: "all",
|
|
5343
5233
|
name: "vendor",
|
|
@@ -5356,12 +5246,12 @@ function singleVendor(ctx) {
|
|
|
5356
5246
|
}
|
|
5357
5247
|
};
|
|
5358
5248
|
}
|
|
5359
|
-
var import_node_assert,
|
|
5249
|
+
var import_node_assert, import_shared42, MODULE_PATH_REGEX, SPLIT_STRATEGY_DISPATCHER, pluginSplitChunks;
|
|
5360
5250
|
var init_splitChunks = __esm({
|
|
5361
5251
|
"src/plugins/splitChunks.ts"() {
|
|
5362
5252
|
"use strict";
|
|
5363
5253
|
import_node_assert = __toESM(require("assert"));
|
|
5364
|
-
|
|
5254
|
+
import_shared42 = require("@rsbuild/shared");
|
|
5365
5255
|
MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/;
|
|
5366
5256
|
SPLIT_STRATEGY_DISPATCHER = {
|
|
5367
5257
|
"split-by-experience": splitByExperience,
|
|
@@ -5444,10 +5334,10 @@ async function openBrowser(url2) {
|
|
|
5444
5334
|
);
|
|
5445
5335
|
return true;
|
|
5446
5336
|
}
|
|
5447
|
-
(0,
|
|
5337
|
+
(0, import_shared43.debug)("Failed to find the target browser.");
|
|
5448
5338
|
} catch (err) {
|
|
5449
|
-
(0,
|
|
5450
|
-
|
|
5339
|
+
(0, import_shared43.debug)("Failed to open start URL with apple script.");
|
|
5340
|
+
import_shared43.logger.debug(err);
|
|
5451
5341
|
}
|
|
5452
5342
|
}
|
|
5453
5343
|
try {
|
|
@@ -5455,13 +5345,13 @@ async function openBrowser(url2) {
|
|
|
5455
5345
|
await open(url2);
|
|
5456
5346
|
return true;
|
|
5457
5347
|
} catch (err) {
|
|
5458
|
-
|
|
5459
|
-
|
|
5348
|
+
import_shared43.logger.error("Failed to open start URL.");
|
|
5349
|
+
import_shared43.logger.error(err);
|
|
5460
5350
|
return false;
|
|
5461
5351
|
}
|
|
5462
5352
|
}
|
|
5463
5353
|
function resolveUrl(str, base) {
|
|
5464
|
-
if (
|
|
5354
|
+
if (canParse(str)) {
|
|
5465
5355
|
return str;
|
|
5466
5356
|
}
|
|
5467
5357
|
try {
|
|
@@ -5519,14 +5409,15 @@ function pluginOpen() {
|
|
|
5519
5409
|
}
|
|
5520
5410
|
};
|
|
5521
5411
|
}
|
|
5522
|
-
var import_node_child_process, import_node_util,
|
|
5412
|
+
var import_node_child_process, import_node_util, import_shared43, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs, normalizeOpenConfig;
|
|
5523
5413
|
var init_open = __esm({
|
|
5524
5414
|
"src/plugins/open.ts"() {
|
|
5525
5415
|
"use strict";
|
|
5526
5416
|
import_node_child_process = require("child_process");
|
|
5527
5417
|
import_node_util = require("util");
|
|
5528
|
-
|
|
5418
|
+
import_shared43 = require("@rsbuild/shared");
|
|
5529
5419
|
init_constants();
|
|
5420
|
+
init_helpers();
|
|
5530
5421
|
execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
5531
5422
|
supportedChromiumBrowsers = [
|
|
5532
5423
|
"Google Chrome Canary",
|
|
@@ -5564,7 +5455,7 @@ var init_open = __esm({
|
|
|
5564
5455
|
return { targets: open, before: beforeStartUrl };
|
|
5565
5456
|
}
|
|
5566
5457
|
return {
|
|
5567
|
-
targets: open.target ? (0,
|
|
5458
|
+
targets: open.target ? (0, import_shared43.castArray)(open.target) : [],
|
|
5568
5459
|
before: open.before
|
|
5569
5460
|
};
|
|
5570
5461
|
};
|
|
@@ -5576,12 +5467,12 @@ var InlineChunkHtmlPlugin_exports = {};
|
|
|
5576
5467
|
__export(InlineChunkHtmlPlugin_exports, {
|
|
5577
5468
|
InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
|
|
5578
5469
|
});
|
|
5579
|
-
var
|
|
5470
|
+
var import_node_path23, import_shared44, InlineChunkHtmlPlugin;
|
|
5580
5471
|
var init_InlineChunkHtmlPlugin = __esm({
|
|
5581
5472
|
"src/rspack/InlineChunkHtmlPlugin.ts"() {
|
|
5582
5473
|
"use strict";
|
|
5583
|
-
|
|
5584
|
-
|
|
5474
|
+
import_node_path23 = require("path");
|
|
5475
|
+
import_shared44 = require("@rsbuild/shared");
|
|
5585
5476
|
init_pluginHelper();
|
|
5586
5477
|
InlineChunkHtmlPlugin = class {
|
|
5587
5478
|
constructor({
|
|
@@ -5614,8 +5505,8 @@ var init_InlineChunkHtmlPlugin = __esm({
|
|
|
5614
5505
|
const { devtool } = compilation.options;
|
|
5615
5506
|
if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
|
|
5616
5507
|
!devtool.includes("inline") && source.includes("# sourceMappingURL")) {
|
|
5617
|
-
const prefix = (0,
|
|
5618
|
-
(0,
|
|
5508
|
+
const prefix = (0, import_shared44.addTrailingSlash)(
|
|
5509
|
+
(0, import_node_path23.join)(publicPath, this.distPath[type] || "")
|
|
5619
5510
|
);
|
|
5620
5511
|
return source.replace(
|
|
5621
5512
|
/# sourceMappingURL=/,
|
|
@@ -5626,7 +5517,7 @@ var init_InlineChunkHtmlPlugin = __esm({
|
|
|
5626
5517
|
}
|
|
5627
5518
|
matchTests(name, source, tests) {
|
|
5628
5519
|
return tests.some((test) => {
|
|
5629
|
-
if ((0,
|
|
5520
|
+
if ((0, import_shared44.isFunction)(test)) {
|
|
5630
5521
|
const size = source.length;
|
|
5631
5522
|
return test({ name, size });
|
|
5632
5523
|
}
|
|
@@ -5712,7 +5603,7 @@ var init_InlineChunkHtmlPlugin = __esm({
|
|
|
5712
5603
|
}
|
|
5713
5604
|
apply(compiler) {
|
|
5714
5605
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
5715
|
-
const publicPath = (0,
|
|
5606
|
+
const publicPath = (0, import_shared44.getPublicPathFromCompiler)(compiler);
|
|
5716
5607
|
const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
|
|
5717
5608
|
const hooks = getHTMLPlugin().getHooks(compilation);
|
|
5718
5609
|
hooks.alterAssetTagGroups.tap(this.name, (assets) => {
|
|
@@ -5752,18 +5643,18 @@ var inlineChunk_exports = {};
|
|
|
5752
5643
|
__export(inlineChunk_exports, {
|
|
5753
5644
|
pluginInlineChunk: () => pluginInlineChunk
|
|
5754
5645
|
});
|
|
5755
|
-
var
|
|
5646
|
+
var import_shared45, pluginInlineChunk;
|
|
5756
5647
|
var init_inlineChunk = __esm({
|
|
5757
5648
|
"src/plugins/inlineChunk.ts"() {
|
|
5758
5649
|
"use strict";
|
|
5759
|
-
|
|
5650
|
+
import_shared45 = require("@rsbuild/shared");
|
|
5760
5651
|
init_constants();
|
|
5761
5652
|
pluginInlineChunk = () => ({
|
|
5762
5653
|
name: "rsbuild:inline-chunk",
|
|
5763
5654
|
setup(api) {
|
|
5764
5655
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3, isDev: isDev3 }) => {
|
|
5765
5656
|
const config = api.getNormalizedConfig();
|
|
5766
|
-
if ((0,
|
|
5657
|
+
if ((0, import_shared45.isHtmlDisabled)(config, target) || isDev3) {
|
|
5767
5658
|
return;
|
|
5768
5659
|
}
|
|
5769
5660
|
const { InlineChunkHtmlPlugin: InlineChunkHtmlPlugin2 } = await Promise.resolve().then(() => (init_InlineChunkHtmlPlugin(), InlineChunkHtmlPlugin_exports));
|
|
@@ -5771,7 +5662,7 @@ var init_inlineChunk = __esm({
|
|
|
5771
5662
|
const scriptTests = [];
|
|
5772
5663
|
const styleTests = [];
|
|
5773
5664
|
if (inlineScripts) {
|
|
5774
|
-
scriptTests.push(inlineScripts === true ?
|
|
5665
|
+
scriptTests.push(inlineScripts === true ? import_shared45.JS_REGEX : inlineScripts);
|
|
5775
5666
|
}
|
|
5776
5667
|
if (inlineStyles) {
|
|
5777
5668
|
styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
|
|
@@ -5783,7 +5674,7 @@ var init_inlineChunk = __esm({
|
|
|
5783
5674
|
{
|
|
5784
5675
|
styleTests,
|
|
5785
5676
|
scriptTests,
|
|
5786
|
-
distPath: (0,
|
|
5677
|
+
distPath: (0, import_shared45.pick)(config.output.distPath, ["js", "css"])
|
|
5787
5678
|
}
|
|
5788
5679
|
]);
|
|
5789
5680
|
});
|
|
@@ -5802,7 +5693,7 @@ function pluginBundleAnalyzer() {
|
|
|
5802
5693
|
name: "rsbuild:bundle-analyzer",
|
|
5803
5694
|
setup(api) {
|
|
5804
5695
|
api.modifyRsbuildConfig((config) => {
|
|
5805
|
-
if ((0,
|
|
5696
|
+
if ((0, import_shared46.isProd)() || !isUseAnalyzer(config)) {
|
|
5806
5697
|
return;
|
|
5807
5698
|
}
|
|
5808
5699
|
config.dev ||= {};
|
|
@@ -5827,11 +5718,11 @@ function pluginBundleAnalyzer() {
|
|
|
5827
5718
|
}
|
|
5828
5719
|
};
|
|
5829
5720
|
}
|
|
5830
|
-
var
|
|
5721
|
+
var import_shared46, isUseAnalyzer;
|
|
5831
5722
|
var init_bundleAnalyzer = __esm({
|
|
5832
5723
|
"src/plugins/bundleAnalyzer.ts"() {
|
|
5833
5724
|
"use strict";
|
|
5834
|
-
|
|
5725
|
+
import_shared46 = require("@rsbuild/shared");
|
|
5835
5726
|
isUseAnalyzer = (config) => process.env.BUNDLE_ANALYZE || config.performance?.bundleAnalyze;
|
|
5836
5727
|
}
|
|
5837
5728
|
});
|
|
@@ -5841,11 +5732,11 @@ var rsdoctor_exports = {};
|
|
|
5841
5732
|
__export(rsdoctor_exports, {
|
|
5842
5733
|
pluginRsdoctor: () => pluginRsdoctor
|
|
5843
5734
|
});
|
|
5844
|
-
var
|
|
5735
|
+
var import_shared47, pluginRsdoctor;
|
|
5845
5736
|
var init_rsdoctor = __esm({
|
|
5846
5737
|
"src/plugins/rsdoctor.ts"() {
|
|
5847
5738
|
"use strict";
|
|
5848
|
-
|
|
5739
|
+
import_shared47 = require("@rsbuild/shared");
|
|
5849
5740
|
pluginRsdoctor = () => ({
|
|
5850
5741
|
name: "rsbuild:rsdoctor",
|
|
5851
5742
|
setup(api) {
|
|
@@ -5862,8 +5753,8 @@ var init_rsdoctor = __esm({
|
|
|
5862
5753
|
});
|
|
5863
5754
|
module2 = await import(path13);
|
|
5864
5755
|
} catch (err) {
|
|
5865
|
-
|
|
5866
|
-
`\`process.env.RSDOCTOR\` enabled, please install ${
|
|
5756
|
+
import_shared47.logger.warn(
|
|
5757
|
+
`\`process.env.RSDOCTOR\` enabled, please install ${import_shared47.color.bold(import_shared47.color.yellow(packageName))} package.`
|
|
5867
5758
|
);
|
|
5868
5759
|
return;
|
|
5869
5760
|
}
|
|
@@ -5884,7 +5775,7 @@ var init_rsdoctor = __esm({
|
|
|
5884
5775
|
isAutoRegister = true;
|
|
5885
5776
|
}
|
|
5886
5777
|
if (isAutoRegister) {
|
|
5887
|
-
|
|
5778
|
+
import_shared47.logger.info(`${import_shared47.color.bold(import_shared47.color.yellow(packageName))} enabled.`);
|
|
5888
5779
|
}
|
|
5889
5780
|
});
|
|
5890
5781
|
}
|
|
@@ -5945,7 +5836,7 @@ function determineAsValue({
|
|
|
5945
5836
|
file
|
|
5946
5837
|
}) {
|
|
5947
5838
|
const url2 = new import_node_url3.URL(file || href, "https://example.com");
|
|
5948
|
-
const extension =
|
|
5839
|
+
const extension = import_node_path24.default.extname(url2.pathname).slice(1);
|
|
5949
5840
|
if (["css"].includes(extension)) {
|
|
5950
5841
|
return "style";
|
|
5951
5842
|
}
|
|
@@ -5966,11 +5857,11 @@ function determineAsValue({
|
|
|
5966
5857
|
}
|
|
5967
5858
|
return "script";
|
|
5968
5859
|
}
|
|
5969
|
-
var
|
|
5860
|
+
var import_node_path24, import_node_url3;
|
|
5970
5861
|
var init_determineAsValue = __esm({
|
|
5971
5862
|
"src/rspack/preload/helpers/determineAsValue.ts"() {
|
|
5972
5863
|
"use strict";
|
|
5973
|
-
|
|
5864
|
+
import_node_path24 = __toESM(require("path"));
|
|
5974
5865
|
import_node_url3 = require("url");
|
|
5975
5866
|
init_constants();
|
|
5976
5867
|
}
|
|
@@ -6080,10 +5971,10 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
|
|
|
6080
5971
|
);
|
|
6081
5972
|
const sortedFilteredFiles = filteredFiles.sort();
|
|
6082
5973
|
const links = [];
|
|
6083
|
-
const publicPath = (0,
|
|
5974
|
+
const publicPath = (0, import_shared48.getPublicPathFromCompiler)(compilation.compiler);
|
|
6084
5975
|
const { crossOriginLoading } = compilation.compiler.options.output;
|
|
6085
5976
|
for (const file of sortedFilteredFiles) {
|
|
6086
|
-
const href = (
|
|
5977
|
+
const href = ensureAssetPrefix(file, publicPath);
|
|
6087
5978
|
const attributes = {
|
|
6088
5979
|
href,
|
|
6089
5980
|
rel: type
|
|
@@ -6111,11 +6002,12 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
|
|
|
6111
6002
|
}
|
|
6112
6003
|
return links;
|
|
6113
6004
|
}
|
|
6114
|
-
var
|
|
6005
|
+
var import_shared48, defaultOptions, HtmlPreloadOrPrefetchPlugin;
|
|
6115
6006
|
var init_HtmlPreloadOrPrefetchPlugin = __esm({
|
|
6116
6007
|
"src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
|
|
6117
6008
|
"use strict";
|
|
6118
|
-
|
|
6009
|
+
import_shared48 = require("@rsbuild/shared");
|
|
6010
|
+
init_helpers();
|
|
6119
6011
|
init_pluginHelper();
|
|
6120
6012
|
init_helpers2();
|
|
6121
6013
|
defaultOptions = {
|
|
@@ -6137,7 +6029,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
|
|
|
6137
6029
|
apply(compiler) {
|
|
6138
6030
|
compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
|
|
6139
6031
|
getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
|
|
6140
|
-
`HTML${(0,
|
|
6032
|
+
`HTML${(0, import_shared48.upperFirst)(this.type)}Plugin`,
|
|
6141
6033
|
(htmlPluginData) => {
|
|
6142
6034
|
this.resourceHints = generateLinks(
|
|
6143
6035
|
this.options,
|
|
@@ -6150,7 +6042,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
|
|
|
6150
6042
|
}
|
|
6151
6043
|
);
|
|
6152
6044
|
getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
|
|
6153
|
-
`HTML${(0,
|
|
6045
|
+
`HTML${(0, import_shared48.upperFirst)(this.type)}Plugin`,
|
|
6154
6046
|
(htmlPluginData) => {
|
|
6155
6047
|
if (this.resourceHints) {
|
|
6156
6048
|
htmlPluginData.assetTags.styles = [
|
|
@@ -6175,11 +6067,11 @@ var resourceHints_exports = {};
|
|
|
6175
6067
|
__export(resourceHints_exports, {
|
|
6176
6068
|
pluginResourceHints: () => pluginResourceHints
|
|
6177
6069
|
});
|
|
6178
|
-
var
|
|
6070
|
+
var import_shared49, generateLinks2, pluginResourceHints;
|
|
6179
6071
|
var init_resourceHints = __esm({
|
|
6180
6072
|
"src/plugins/resourceHints.ts"() {
|
|
6181
6073
|
"use strict";
|
|
6182
|
-
|
|
6074
|
+
import_shared49 = require("@rsbuild/shared");
|
|
6183
6075
|
generateLinks2 = (options, rel) => options.map((option) => ({
|
|
6184
6076
|
tag: "link",
|
|
6185
6077
|
attrs: {
|
|
@@ -6214,7 +6106,7 @@ var init_resourceHints = __esm({
|
|
|
6214
6106
|
const {
|
|
6215
6107
|
performance: { preload, prefetch }
|
|
6216
6108
|
} = config;
|
|
6217
|
-
if ((0,
|
|
6109
|
+
if ((0, import_shared49.isHtmlDisabled)(config, target)) {
|
|
6218
6110
|
return;
|
|
6219
6111
|
}
|
|
6220
6112
|
const HTMLCount = chain.entryPoints.values().length;
|
|
@@ -6277,34 +6169,36 @@ var server_exports = {};
|
|
|
6277
6169
|
__export(server_exports, {
|
|
6278
6170
|
pluginServer: () => pluginServer
|
|
6279
6171
|
});
|
|
6280
|
-
var
|
|
6172
|
+
var import_node_path25, import_shared50, pluginServer;
|
|
6281
6173
|
var init_server = __esm({
|
|
6282
6174
|
"src/plugins/server.ts"() {
|
|
6283
6175
|
"use strict";
|
|
6284
|
-
|
|
6285
|
-
|
|
6176
|
+
import_node_path25 = require("path");
|
|
6177
|
+
import_shared50 = require("@rsbuild/shared");
|
|
6178
|
+
init_config();
|
|
6286
6179
|
pluginServer = () => ({
|
|
6287
6180
|
name: "rsbuild:server",
|
|
6288
6181
|
setup(api) {
|
|
6289
6182
|
api.onBeforeBuild(async () => {
|
|
6290
6183
|
const config = api.getNormalizedConfig();
|
|
6291
|
-
|
|
6292
|
-
|
|
6184
|
+
const publicDirs = normalizePublicDirs(config.server.publicDir);
|
|
6185
|
+
for (const publicDir of publicDirs) {
|
|
6186
|
+
const { name, copyOnBuild } = publicDir;
|
|
6293
6187
|
if (!copyOnBuild || !name) {
|
|
6294
|
-
|
|
6188
|
+
continue;
|
|
6295
6189
|
}
|
|
6296
|
-
const
|
|
6297
|
-
if (!
|
|
6298
|
-
|
|
6190
|
+
const normalizedPath = (0, import_node_path25.isAbsolute)(name) ? name : (0, import_node_path25.join)(api.context.rootPath, name);
|
|
6191
|
+
if (!import_shared50.fse.existsSync(normalizedPath)) {
|
|
6192
|
+
continue;
|
|
6299
6193
|
}
|
|
6300
6194
|
try {
|
|
6301
|
-
await
|
|
6195
|
+
await import_shared50.fse.copy(normalizedPath, api.context.distPath, {
|
|
6302
6196
|
// dereference symlinks
|
|
6303
6197
|
dereference: true
|
|
6304
6198
|
});
|
|
6305
6199
|
} catch (err) {
|
|
6306
6200
|
if (err instanceof Error) {
|
|
6307
|
-
err.message = `Copy public dir (${
|
|
6201
|
+
err.message = `Copy public dir (${normalizedPath}) to dist failed:
|
|
6308
6202
|
${err.message}`;
|
|
6309
6203
|
}
|
|
6310
6204
|
throw err;
|
|
@@ -6465,18 +6359,18 @@ function pluginModuleFederation() {
|
|
|
6465
6359
|
chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
|
|
6466
6360
|
}
|
|
6467
6361
|
const publicPath = chain.output.get("publicPath");
|
|
6468
|
-
if (publicPath ===
|
|
6362
|
+
if (publicPath === import_shared51.DEFAULT_ASSET_PREFIX) {
|
|
6469
6363
|
chain.output.set("publicPath", "auto");
|
|
6470
6364
|
}
|
|
6471
6365
|
});
|
|
6472
6366
|
}
|
|
6473
6367
|
};
|
|
6474
6368
|
}
|
|
6475
|
-
var
|
|
6369
|
+
var import_shared51, import_core8, PatchSplitChunksPlugin;
|
|
6476
6370
|
var init_moduleFederation = __esm({
|
|
6477
6371
|
"src/plugins/moduleFederation.ts"() {
|
|
6478
6372
|
"use strict";
|
|
6479
|
-
|
|
6373
|
+
import_shared51 = require("@rsbuild/shared");
|
|
6480
6374
|
import_core8 = require("@rspack/core");
|
|
6481
6375
|
PatchSplitChunksPlugin = class {
|
|
6482
6376
|
constructor(name) {
|
|
@@ -6544,14 +6438,14 @@ __export(rspackProfile_exports, {
|
|
|
6544
6438
|
pluginRspackProfile: () => pluginRspackProfile,
|
|
6545
6439
|
stopProfiler: () => stopProfiler
|
|
6546
6440
|
});
|
|
6547
|
-
var import_node_inspector,
|
|
6441
|
+
var import_node_inspector, import_node_path26, import_shared52, import_shared53, import_core9, stopProfiler, pluginRspackProfile;
|
|
6548
6442
|
var init_rspackProfile = __esm({
|
|
6549
6443
|
"src/plugins/rspackProfile.ts"() {
|
|
6550
6444
|
"use strict";
|
|
6551
6445
|
import_node_inspector = __toESM(require("inspector"));
|
|
6552
|
-
|
|
6446
|
+
import_node_path26 = __toESM(require("path"));
|
|
6447
|
+
import_shared52 = require("@rsbuild/shared");
|
|
6553
6448
|
import_shared53 = require("@rsbuild/shared");
|
|
6554
|
-
import_shared54 = require("@rsbuild/shared");
|
|
6555
6449
|
import_core9 = require("@rspack/core");
|
|
6556
6450
|
stopProfiler = (output, profileSession) => {
|
|
6557
6451
|
if (!profileSession) {
|
|
@@ -6559,10 +6453,10 @@ var init_rspackProfile = __esm({
|
|
|
6559
6453
|
}
|
|
6560
6454
|
profileSession.post("Profiler.stop", (error, param) => {
|
|
6561
6455
|
if (error) {
|
|
6562
|
-
|
|
6456
|
+
import_shared53.logger.error("Failed to generate JS CPU profile:", error);
|
|
6563
6457
|
return;
|
|
6564
6458
|
}
|
|
6565
|
-
|
|
6459
|
+
import_shared52.fse.writeFileSync(output, JSON.stringify(param.profile));
|
|
6566
6460
|
});
|
|
6567
6461
|
};
|
|
6568
6462
|
pluginRspackProfile = () => ({
|
|
@@ -6576,7 +6470,7 @@ var init_rspackProfile = __esm({
|
|
|
6576
6470
|
return;
|
|
6577
6471
|
}
|
|
6578
6472
|
const timestamp = Date.now();
|
|
6579
|
-
const profileDir =
|
|
6473
|
+
const profileDir = import_node_path26.default.join(
|
|
6580
6474
|
api.context.distPath,
|
|
6581
6475
|
`rspack-profile-${timestamp}`
|
|
6582
6476
|
);
|
|
@@ -6584,11 +6478,11 @@ var init_rspackProfile = __esm({
|
|
|
6584
6478
|
const enableProfileTrace = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("TRACE");
|
|
6585
6479
|
const enableCPUProfile = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("CPU");
|
|
6586
6480
|
const enableLogging = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("LOGGING");
|
|
6587
|
-
const traceFilePath =
|
|
6588
|
-
const cpuProfilePath =
|
|
6589
|
-
const loggingFilePath =
|
|
6481
|
+
const traceFilePath = import_node_path26.default.join(profileDir, "trace.json");
|
|
6482
|
+
const cpuProfilePath = import_node_path26.default.join(profileDir, "jscpuprofile.json");
|
|
6483
|
+
const loggingFilePath = import_node_path26.default.join(profileDir, "logging.json");
|
|
6590
6484
|
const onStart = () => {
|
|
6591
|
-
|
|
6485
|
+
import_shared52.fse.ensureDirSync(profileDir);
|
|
6592
6486
|
if (enableProfileTrace) {
|
|
6593
6487
|
import_core9.rspack.experimental_registerGlobalTrace(
|
|
6594
6488
|
"trace",
|
|
@@ -6612,7 +6506,7 @@ var init_rspackProfile = __esm({
|
|
|
6612
6506
|
logging: "verbose",
|
|
6613
6507
|
loggingTrace: true
|
|
6614
6508
|
});
|
|
6615
|
-
|
|
6509
|
+
import_shared52.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
|
|
6616
6510
|
}
|
|
6617
6511
|
});
|
|
6618
6512
|
api.onExit(() => {
|
|
@@ -6620,7 +6514,7 @@ var init_rspackProfile = __esm({
|
|
|
6620
6514
|
import_core9.rspack.experimental_cleanupGlobalTrace();
|
|
6621
6515
|
}
|
|
6622
6516
|
stopProfiler(cpuProfilePath, profileSession);
|
|
6623
|
-
|
|
6517
|
+
import_shared53.logger.info(`Saved Rspack profile file to ${profileDir}`);
|
|
6624
6518
|
});
|
|
6625
6519
|
}
|
|
6626
6520
|
});
|
|
@@ -6632,16 +6526,16 @@ var lazyCompilation_exports = {};
|
|
|
6632
6526
|
__export(lazyCompilation_exports, {
|
|
6633
6527
|
pluginLazyCompilation: () => pluginLazyCompilation
|
|
6634
6528
|
});
|
|
6635
|
-
var
|
|
6529
|
+
var import_shared54, pluginLazyCompilation;
|
|
6636
6530
|
var init_lazyCompilation = __esm({
|
|
6637
6531
|
"src/plugins/lazyCompilation.ts"() {
|
|
6638
6532
|
"use strict";
|
|
6639
|
-
|
|
6533
|
+
import_shared54 = require("@rsbuild/shared");
|
|
6640
6534
|
pluginLazyCompilation = () => ({
|
|
6641
6535
|
name: "rsbuild:lazy-compilation",
|
|
6642
6536
|
setup(api) {
|
|
6643
|
-
api.modifyBundlerChain((chain, { isProd:
|
|
6644
|
-
if (
|
|
6537
|
+
api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
|
|
6538
|
+
if (isProd6 || target !== "web") {
|
|
6645
6539
|
return;
|
|
6646
6540
|
}
|
|
6647
6541
|
const config = api.getNormalizedConfig();
|
|
@@ -6682,7 +6576,7 @@ var init_lazyCompilation = __esm({
|
|
|
6682
6576
|
if (!name || isExcludedModule(name)) {
|
|
6683
6577
|
return false;
|
|
6684
6578
|
}
|
|
6685
|
-
if ((0,
|
|
6579
|
+
if ((0, import_shared54.isRegExp)(test)) {
|
|
6686
6580
|
return name ? test.test(name) : false;
|
|
6687
6581
|
}
|
|
6688
6582
|
return test(module2);
|
|
@@ -6704,18 +6598,18 @@ var sri_exports = {};
|
|
|
6704
6598
|
__export(sri_exports, {
|
|
6705
6599
|
pluginSri: () => pluginSri
|
|
6706
6600
|
});
|
|
6707
|
-
var import_node_crypto2,
|
|
6601
|
+
var import_node_crypto2, import_shared55, getAssetName, pluginSri;
|
|
6708
6602
|
var init_sri = __esm({
|
|
6709
6603
|
"src/plugins/sri.ts"() {
|
|
6710
6604
|
"use strict";
|
|
6711
6605
|
import_node_crypto2 = __toESM(require("crypto"));
|
|
6712
|
-
|
|
6606
|
+
import_shared55 = require("@rsbuild/shared");
|
|
6713
6607
|
init_constants();
|
|
6714
6608
|
getAssetName = (url2, assetPrefix) => {
|
|
6715
6609
|
if (url2.startsWith(assetPrefix)) {
|
|
6716
|
-
return (0,
|
|
6610
|
+
return (0, import_shared55.removeLeadingSlash)(url2.replace(assetPrefix, ""));
|
|
6717
6611
|
}
|
|
6718
|
-
return (0,
|
|
6612
|
+
return (0, import_shared55.removeLeadingSlash)(url2);
|
|
6719
6613
|
};
|
|
6720
6614
|
pluginSri = () => ({
|
|
6721
6615
|
name: "rsbuild:sri",
|
|
@@ -6724,7 +6618,7 @@ var init_sri = __esm({
|
|
|
6724
6618
|
const getAlgorithm = () => {
|
|
6725
6619
|
const config = api.getNormalizedConfig();
|
|
6726
6620
|
const { sri } = config.security;
|
|
6727
|
-
const enable = sri.enable === "auto" ? (0,
|
|
6621
|
+
const enable = sri.enable === "auto" ? (0, import_shared55.isProd)() : sri.enable;
|
|
6728
6622
|
if (!enable) {
|
|
6729
6623
|
return null;
|
|
6730
6624
|
}
|
|
@@ -6791,7 +6685,7 @@ var init_sri = __esm({
|
|
|
6791
6685
|
`integrity="${integrity}"`
|
|
6792
6686
|
);
|
|
6793
6687
|
} else {
|
|
6794
|
-
|
|
6688
|
+
import_shared55.logger.debug(
|
|
6795
6689
|
`[rsbuild:sri] failed to generate integrity for ${assetName}.`
|
|
6796
6690
|
);
|
|
6797
6691
|
replacedHtml = replacedHtml.replace(
|
|
@@ -6844,7 +6738,7 @@ var init_sri = __esm({
|
|
|
6844
6738
|
}
|
|
6845
6739
|
api.modifyBundlerChain((chain, { target }) => {
|
|
6846
6740
|
const config = api.getNormalizedConfig();
|
|
6847
|
-
if ((0,
|
|
6741
|
+
if ((0, import_shared55.isHtmlDisabled)(config, target)) {
|
|
6848
6742
|
return;
|
|
6849
6743
|
}
|
|
6850
6744
|
const algorithm = getAlgorithm();
|
|
@@ -6863,11 +6757,11 @@ var nonce_exports = {};
|
|
|
6863
6757
|
__export(nonce_exports, {
|
|
6864
6758
|
pluginNonce: () => pluginNonce
|
|
6865
6759
|
});
|
|
6866
|
-
var
|
|
6760
|
+
var import_shared56, pluginNonce;
|
|
6867
6761
|
var init_nonce = __esm({
|
|
6868
6762
|
"src/plugins/nonce.ts"() {
|
|
6869
6763
|
"use strict";
|
|
6870
|
-
|
|
6764
|
+
import_shared56 = require("@rsbuild/shared");
|
|
6871
6765
|
pluginNonce = () => ({
|
|
6872
6766
|
name: "rsbuild:nonce",
|
|
6873
6767
|
setup(api) {
|
|
@@ -6876,7 +6770,7 @@ var init_nonce = __esm({
|
|
|
6876
6770
|
if (!nonce) {
|
|
6877
6771
|
return;
|
|
6878
6772
|
}
|
|
6879
|
-
(0,
|
|
6773
|
+
(0, import_shared56.applyToCompiler)(compiler, (compiler2) => {
|
|
6880
6774
|
const { plugins } = compiler2.options;
|
|
6881
6775
|
const hasHTML = plugins.some(
|
|
6882
6776
|
(plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
|
|
@@ -6884,7 +6778,7 @@ var init_nonce = __esm({
|
|
|
6884
6778
|
if (!hasHTML) {
|
|
6885
6779
|
return;
|
|
6886
6780
|
}
|
|
6887
|
-
const injectCode = (0,
|
|
6781
|
+
const injectCode = (0, import_shared56.createVirtualModule)(
|
|
6888
6782
|
`__webpack_nonce__ = "${nonce}";`
|
|
6889
6783
|
);
|
|
6890
6784
|
new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
|
|
@@ -6915,6 +6809,178 @@ var init_nonce = __esm({
|
|
|
6915
6809
|
}
|
|
6916
6810
|
});
|
|
6917
6811
|
|
|
6812
|
+
// src/server/prodServer.ts
|
|
6813
|
+
var prodServer_exports = {};
|
|
6814
|
+
__export(prodServer_exports, {
|
|
6815
|
+
RsbuildProdServer: () => RsbuildProdServer,
|
|
6816
|
+
startProdServer: () => startProdServer
|
|
6817
|
+
});
|
|
6818
|
+
async function startProdServer(context, config, { getPortSilently } = {}) {
|
|
6819
|
+
if (!(0, import_shared57.getNodeEnv)()) {
|
|
6820
|
+
(0, import_shared57.setNodeEnv)("production");
|
|
6821
|
+
}
|
|
6822
|
+
const { port, host, https } = await getServerConfig({
|
|
6823
|
+
config,
|
|
6824
|
+
getPortSilently
|
|
6825
|
+
});
|
|
6826
|
+
const { default: connect } = await import("../compiled/connect/index.js");
|
|
6827
|
+
const middlewares = connect();
|
|
6828
|
+
const serverConfig = config.server;
|
|
6829
|
+
const server = new RsbuildProdServer(
|
|
6830
|
+
{
|
|
6831
|
+
pwd: context.rootPath,
|
|
6832
|
+
output: {
|
|
6833
|
+
path: config.output.distPath.root || ROOT_DIST_DIR,
|
|
6834
|
+
assetPrefix: config.output.assetPrefix
|
|
6835
|
+
},
|
|
6836
|
+
serverConfig
|
|
6837
|
+
},
|
|
6838
|
+
middlewares
|
|
6839
|
+
);
|
|
6840
|
+
await context.hooks.onBeforeStartProdServer.call();
|
|
6841
|
+
const httpServer = await createHttpServer({
|
|
6842
|
+
serverConfig,
|
|
6843
|
+
middlewares: server.middlewares
|
|
6844
|
+
});
|
|
6845
|
+
await server.onInit(httpServer);
|
|
6846
|
+
return new Promise((resolve) => {
|
|
6847
|
+
httpServer.listen(
|
|
6848
|
+
{
|
|
6849
|
+
host,
|
|
6850
|
+
port
|
|
6851
|
+
},
|
|
6852
|
+
async () => {
|
|
6853
|
+
const routes = formatRoutes(
|
|
6854
|
+
context.entry,
|
|
6855
|
+
config.output.distPath.html,
|
|
6856
|
+
config.html.outputStructure
|
|
6857
|
+
);
|
|
6858
|
+
await context.hooks.onAfterStartProdServer.call({
|
|
6859
|
+
port,
|
|
6860
|
+
routes
|
|
6861
|
+
});
|
|
6862
|
+
const protocol = https ? "https" : "http";
|
|
6863
|
+
const urls = getAddressUrls({ protocol, port, host });
|
|
6864
|
+
printServerURLs({
|
|
6865
|
+
urls,
|
|
6866
|
+
port,
|
|
6867
|
+
routes,
|
|
6868
|
+
protocol,
|
|
6869
|
+
printUrls: serverConfig.printUrls
|
|
6870
|
+
});
|
|
6871
|
+
const onClose = () => {
|
|
6872
|
+
server.close();
|
|
6873
|
+
httpServer.close();
|
|
6874
|
+
};
|
|
6875
|
+
resolve({
|
|
6876
|
+
port,
|
|
6877
|
+
urls: urls.map((item) => item.url),
|
|
6878
|
+
server: {
|
|
6879
|
+
close: async () => {
|
|
6880
|
+
onClose();
|
|
6881
|
+
}
|
|
6882
|
+
}
|
|
6883
|
+
});
|
|
6884
|
+
}
|
|
6885
|
+
);
|
|
6886
|
+
});
|
|
6887
|
+
}
|
|
6888
|
+
var import_node_path27, import_shared57, RsbuildProdServer;
|
|
6889
|
+
var init_prodServer = __esm({
|
|
6890
|
+
"src/server/prodServer.ts"() {
|
|
6891
|
+
"use strict";
|
|
6892
|
+
import_node_path27 = require("path");
|
|
6893
|
+
import_shared57 = require("@rsbuild/shared");
|
|
6894
|
+
init_constants();
|
|
6895
|
+
init_helper();
|
|
6896
|
+
init_httpServer();
|
|
6897
|
+
init_middlewares();
|
|
6898
|
+
RsbuildProdServer = class {
|
|
6899
|
+
constructor(options, middlewares) {
|
|
6900
|
+
__publicField(this, "app");
|
|
6901
|
+
__publicField(this, "options");
|
|
6902
|
+
__publicField(this, "middlewares");
|
|
6903
|
+
this.options = options;
|
|
6904
|
+
this.middlewares = middlewares;
|
|
6905
|
+
}
|
|
6906
|
+
// Complete the preparation of services
|
|
6907
|
+
async onInit(app) {
|
|
6908
|
+
this.app = app;
|
|
6909
|
+
await this.applyDefaultMiddlewares();
|
|
6910
|
+
}
|
|
6911
|
+
async applyDefaultMiddlewares() {
|
|
6912
|
+
const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
|
|
6913
|
+
if ((0, import_shared57.isDebug)()) {
|
|
6914
|
+
this.middlewares.use(await getRequestLoggerMiddleware());
|
|
6915
|
+
}
|
|
6916
|
+
if (compress) {
|
|
6917
|
+
const { default: compression } = await import("../compiled/http-compression/index.js");
|
|
6918
|
+
this.middlewares.use((req, res, next) => {
|
|
6919
|
+
compression({
|
|
6920
|
+
gzip: true,
|
|
6921
|
+
brotli: false
|
|
6922
|
+
})(req, res, next);
|
|
6923
|
+
});
|
|
6924
|
+
}
|
|
6925
|
+
if (headers) {
|
|
6926
|
+
this.middlewares.use((_req, res, next) => {
|
|
6927
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
6928
|
+
res.setHeader(key, value);
|
|
6929
|
+
}
|
|
6930
|
+
next();
|
|
6931
|
+
});
|
|
6932
|
+
}
|
|
6933
|
+
if (proxy) {
|
|
6934
|
+
const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
|
|
6935
|
+
const { middlewares, upgrade } = createProxyMiddleware2(proxy);
|
|
6936
|
+
for (const middleware of middlewares) {
|
|
6937
|
+
this.middlewares.use(middleware);
|
|
6938
|
+
}
|
|
6939
|
+
this.app.on("upgrade", upgrade);
|
|
6940
|
+
}
|
|
6941
|
+
this.applyStaticAssetMiddleware();
|
|
6942
|
+
if (historyApiFallback) {
|
|
6943
|
+
const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
|
|
6944
|
+
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
6945
|
+
historyApiFallback === true ? {} : historyApiFallback
|
|
6946
|
+
);
|
|
6947
|
+
this.middlewares.use(historyApiFallbackMiddleware);
|
|
6948
|
+
await this.applyStaticAssetMiddleware();
|
|
6949
|
+
}
|
|
6950
|
+
this.middlewares.use(faviconFallbackMiddleware);
|
|
6951
|
+
}
|
|
6952
|
+
async applyStaticAssetMiddleware() {
|
|
6953
|
+
const {
|
|
6954
|
+
output: { path: path13, assetPrefix },
|
|
6955
|
+
serverConfig: { htmlFallback },
|
|
6956
|
+
pwd
|
|
6957
|
+
} = this.options;
|
|
6958
|
+
const { default: sirv } = await import("../compiled/sirv/index.js");
|
|
6959
|
+
const assetMiddleware = sirv((0, import_node_path27.join)(pwd, path13), {
|
|
6960
|
+
etag: true,
|
|
6961
|
+
dev: true,
|
|
6962
|
+
ignores: ["favicon.ico"],
|
|
6963
|
+
single: htmlFallback === "index"
|
|
6964
|
+
});
|
|
6965
|
+
this.middlewares.use((req, res, next) => {
|
|
6966
|
+
const url2 = req.url;
|
|
6967
|
+
if (assetPrefix && url2?.startsWith(assetPrefix)) {
|
|
6968
|
+
req.url = url2.slice(assetPrefix.length);
|
|
6969
|
+
assetMiddleware(req, res, (...args) => {
|
|
6970
|
+
req.url = url2;
|
|
6971
|
+
next(...args);
|
|
6972
|
+
});
|
|
6973
|
+
} else {
|
|
6974
|
+
assetMiddleware(req, res, next);
|
|
6975
|
+
}
|
|
6976
|
+
});
|
|
6977
|
+
}
|
|
6978
|
+
close() {
|
|
6979
|
+
}
|
|
6980
|
+
};
|
|
6981
|
+
}
|
|
6982
|
+
});
|
|
6983
|
+
|
|
6918
6984
|
// src/createRsbuild.ts
|
|
6919
6985
|
var createRsbuild_exports = {};
|
|
6920
6986
|
__export(createRsbuild_exports, {
|
|
@@ -7020,6 +7086,11 @@ async function createRsbuild(options = {}) {
|
|
|
7020
7086
|
rsbuildOptions,
|
|
7021
7087
|
setCssExtractPlugin
|
|
7022
7088
|
});
|
|
7089
|
+
const preview = async (options2) => {
|
|
7090
|
+
const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
|
|
7091
|
+
const config = await initRsbuildConfig({ context, pluginManager });
|
|
7092
|
+
return startProdServer2(context, config, options2);
|
|
7093
|
+
};
|
|
7023
7094
|
const rsbuild = {
|
|
7024
7095
|
...(0, import_shared58.pick)(pluginManager, [
|
|
7025
7096
|
"addPlugins",
|
|
@@ -7045,13 +7116,13 @@ async function createRsbuild(options = {}) {
|
|
|
7045
7116
|
]),
|
|
7046
7117
|
...(0, import_shared58.pick)(providerInstance, [
|
|
7047
7118
|
"build",
|
|
7048
|
-
"preview",
|
|
7049
7119
|
"initConfigs",
|
|
7050
7120
|
"inspectConfig",
|
|
7051
7121
|
"createCompiler",
|
|
7052
7122
|
"createDevServer",
|
|
7053
7123
|
"startDevServer"
|
|
7054
7124
|
]),
|
|
7125
|
+
preview,
|
|
7055
7126
|
context: pluginAPI.context
|
|
7056
7127
|
};
|
|
7057
7128
|
if (rsbuildConfig.plugins) {
|
|
@@ -7067,6 +7138,7 @@ var init_createRsbuild = __esm({
|
|
|
7067
7138
|
import_shared58 = require("@rsbuild/shared");
|
|
7068
7139
|
init_createContext();
|
|
7069
7140
|
init_initPlugins();
|
|
7141
|
+
init_internal();
|
|
7070
7142
|
init_pluginHelper();
|
|
7071
7143
|
init_pluginManager();
|
|
7072
7144
|
getRspackProvider = async () => {
|
|
@@ -7163,68 +7235,9 @@ var init_init = __esm({
|
|
|
7163
7235
|
}
|
|
7164
7236
|
});
|
|
7165
7237
|
|
|
7166
|
-
// src/index.ts
|
|
7167
|
-
var src_exports = {};
|
|
7168
|
-
__export(src_exports, {
|
|
7169
|
-
PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
|
|
7170
|
-
PLUGIN_SWC_NAME: () => PLUGIN_SWC_NAME,
|
|
7171
|
-
__internalHelper: () => internal_exports,
|
|
7172
|
-
createRsbuild: () => createRsbuild,
|
|
7173
|
-
defineConfig: () => defineConfig,
|
|
7174
|
-
loadConfig: () => loadConfig,
|
|
7175
|
-
loadEnv: () => loadEnv,
|
|
7176
|
-
logger: () => import_shared62.logger,
|
|
7177
|
-
mergeRsbuildConfig: () => mergeRsbuildConfig,
|
|
7178
|
-
rspack: () => import_core10.rspack,
|
|
7179
|
-
version: () => version
|
|
7180
|
-
});
|
|
7181
|
-
module.exports = __toCommonJS(src_exports);
|
|
7182
|
-
var import_core10 = require("@rspack/core");
|
|
7183
|
-
|
|
7184
|
-
// src/internal.ts
|
|
7185
|
-
var internal_exports = {};
|
|
7186
|
-
__export(internal_exports, {
|
|
7187
|
-
applySwcDecoratorConfig: () => applySwcDecoratorConfig,
|
|
7188
|
-
createDevServer: () => createDevServer,
|
|
7189
|
-
createPluginManager: () => createPluginManager,
|
|
7190
|
-
formatStats: () => formatStats,
|
|
7191
|
-
getChainUtils: () => getChainUtils,
|
|
7192
|
-
getDevMiddleware: () => getDevMiddleware,
|
|
7193
|
-
getHTMLPlugin: () => getHTMLPlugin,
|
|
7194
|
-
getStatsOptions: () => getStatsOptions,
|
|
7195
|
-
getSwcMinimizerOptions: () => getSwcMinimizerOptions,
|
|
7196
|
-
initHooks: () => initHooks,
|
|
7197
|
-
initPlugins: () => initPlugins,
|
|
7198
|
-
initRsbuildConfig: () => initRsbuildConfig,
|
|
7199
|
-
outputInspectConfigFiles: () => outputInspectConfigFiles,
|
|
7200
|
-
prepareCli: () => prepareCli,
|
|
7201
|
-
runCli: () => runCli,
|
|
7202
|
-
setHTMLPlugin: () => setHTMLPlugin,
|
|
7203
|
-
startProdServer: () => startProdServer,
|
|
7204
|
-
stringifyConfig: () => stringifyConfig
|
|
7205
|
-
});
|
|
7206
|
-
|
|
7207
7238
|
// src/cli/commands.ts
|
|
7208
|
-
var import_node_fs5 = require("fs");
|
|
7209
|
-
var import_node_path28 = require("path");
|
|
7210
|
-
var import_shared60 = require("@rsbuild/shared");
|
|
7211
|
-
var import_commander = require("../compiled/commander/index.js");
|
|
7212
|
-
init_helpers();
|
|
7213
|
-
init_init();
|
|
7214
|
-
var applyCommonOptions = (command) => {
|
|
7215
|
-
command.option(
|
|
7216
|
-
"-c --config <config>",
|
|
7217
|
-
"specify the configuration file, can be a relative or absolute path"
|
|
7218
|
-
).option(
|
|
7219
|
-
"--env-mode <mode>",
|
|
7220
|
-
"specify the env mode to load the `.env.[mode]` file"
|
|
7221
|
-
);
|
|
7222
|
-
};
|
|
7223
|
-
var applyServerOptions = (command) => {
|
|
7224
|
-
command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
|
|
7225
|
-
};
|
|
7226
7239
|
function runCli() {
|
|
7227
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.
|
|
7240
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.8");
|
|
7228
7241
|
const devCommand = import_commander.program.command("dev");
|
|
7229
7242
|
const buildCommand = import_commander.program.command("build");
|
|
7230
7243
|
const previewCommand = import_commander.program.command("preview");
|
|
@@ -7299,9 +7312,32 @@ function runCli() {
|
|
|
7299
7312
|
});
|
|
7300
7313
|
import_commander.program.parse();
|
|
7301
7314
|
}
|
|
7315
|
+
var import_node_fs5, import_node_path28, import_shared60, import_commander, applyCommonOptions, applyServerOptions;
|
|
7316
|
+
var init_commands = __esm({
|
|
7317
|
+
"src/cli/commands.ts"() {
|
|
7318
|
+
"use strict";
|
|
7319
|
+
import_node_fs5 = require("fs");
|
|
7320
|
+
import_node_path28 = require("path");
|
|
7321
|
+
import_shared60 = require("@rsbuild/shared");
|
|
7322
|
+
import_commander = require("../compiled/commander/index.js");
|
|
7323
|
+
init_helpers();
|
|
7324
|
+
init_init();
|
|
7325
|
+
applyCommonOptions = (command) => {
|
|
7326
|
+
command.option(
|
|
7327
|
+
"-c --config <config>",
|
|
7328
|
+
"specify the configuration file, can be a relative or absolute path"
|
|
7329
|
+
).option(
|
|
7330
|
+
"--env-mode <mode>",
|
|
7331
|
+
"specify the env mode to load the `.env.[mode]` file"
|
|
7332
|
+
);
|
|
7333
|
+
};
|
|
7334
|
+
applyServerOptions = (command) => {
|
|
7335
|
+
command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
|
|
7336
|
+
};
|
|
7337
|
+
}
|
|
7338
|
+
});
|
|
7302
7339
|
|
|
7303
7340
|
// src/cli/prepare.ts
|
|
7304
|
-
var import_shared61 = require("@rsbuild/shared");
|
|
7305
7341
|
function initNodeEnv() {
|
|
7306
7342
|
if (!process.env.NODE_ENV) {
|
|
7307
7343
|
const command = process.argv[2];
|
|
@@ -7314,34 +7350,84 @@ function prepareCli() {
|
|
|
7314
7350
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
|
|
7315
7351
|
console.log();
|
|
7316
7352
|
}
|
|
7317
|
-
import_shared61.logger.greet(` ${`Rsbuild v${"0.7.
|
|
7353
|
+
import_shared61.logger.greet(` ${`Rsbuild v${"0.7.8"}`}
|
|
7318
7354
|
`);
|
|
7319
7355
|
}
|
|
7356
|
+
var import_shared61;
|
|
7357
|
+
var init_prepare = __esm({
|
|
7358
|
+
"src/cli/prepare.ts"() {
|
|
7359
|
+
"use strict";
|
|
7360
|
+
import_shared61 = require("@rsbuild/shared");
|
|
7361
|
+
}
|
|
7362
|
+
});
|
|
7320
7363
|
|
|
7321
7364
|
// src/internal.ts
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7365
|
+
var internal_exports = {};
|
|
7366
|
+
__export(internal_exports, {
|
|
7367
|
+
applySwcDecoratorConfig: () => applySwcDecoratorConfig,
|
|
7368
|
+
createDevServer: () => createDevServer,
|
|
7369
|
+
createPluginManager: () => createPluginManager,
|
|
7370
|
+
formatStats: () => formatStats,
|
|
7371
|
+
getChainUtils: () => getChainUtils,
|
|
7372
|
+
getDevMiddleware: () => getDevMiddleware,
|
|
7373
|
+
getHTMLPlugin: () => getHTMLPlugin,
|
|
7374
|
+
getStatsOptions: () => getStatsOptions,
|
|
7375
|
+
getSwcMinimizerOptions: () => getSwcMinimizerOptions,
|
|
7376
|
+
initHooks: () => initHooks,
|
|
7377
|
+
initPlugins: () => initPlugins,
|
|
7378
|
+
initRsbuildConfig: () => initRsbuildConfig,
|
|
7379
|
+
outputInspectConfigFiles: () => outputInspectConfigFiles,
|
|
7380
|
+
prepareCli: () => prepareCli,
|
|
7381
|
+
runCli: () => runCli,
|
|
7382
|
+
setHTMLPlugin: () => setHTMLPlugin,
|
|
7383
|
+
stringifyConfig: () => stringifyConfig
|
|
7384
|
+
});
|
|
7385
|
+
var init_internal = __esm({
|
|
7386
|
+
"src/internal.ts"() {
|
|
7387
|
+
"use strict";
|
|
7388
|
+
init_commands();
|
|
7389
|
+
init_prepare();
|
|
7390
|
+
init_pluginManager();
|
|
7391
|
+
init_initHooks();
|
|
7392
|
+
init_initConfigs();
|
|
7393
|
+
init_config();
|
|
7394
|
+
init_pluginHelper();
|
|
7395
|
+
init_helpers();
|
|
7396
|
+
init_rspackConfig();
|
|
7397
|
+
init_swc();
|
|
7398
|
+
init_minimize();
|
|
7399
|
+
init_devMiddleware();
|
|
7400
|
+
init_devServer();
|
|
7401
|
+
}
|
|
7402
|
+
});
|
|
7336
7403
|
|
|
7337
7404
|
// src/index.ts
|
|
7405
|
+
var src_exports = {};
|
|
7406
|
+
__export(src_exports, {
|
|
7407
|
+
PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
|
|
7408
|
+
PLUGIN_SWC_NAME: () => PLUGIN_SWC_NAME,
|
|
7409
|
+
__internalHelper: () => internal_exports,
|
|
7410
|
+
createRsbuild: () => createRsbuild,
|
|
7411
|
+
defineConfig: () => defineConfig,
|
|
7412
|
+
ensureAssetPrefix: () => ensureAssetPrefix,
|
|
7413
|
+
loadConfig: () => loadConfig,
|
|
7414
|
+
loadEnv: () => loadEnv,
|
|
7415
|
+
logger: () => import_shared62.logger,
|
|
7416
|
+
mergeRsbuildConfig: () => mergeRsbuildConfig,
|
|
7417
|
+
rspack: () => import_core10.rspack,
|
|
7418
|
+
version: () => version
|
|
7419
|
+
});
|
|
7420
|
+
module.exports = __toCommonJS(src_exports);
|
|
7421
|
+
var import_core10 = require("@rspack/core");
|
|
7422
|
+
init_internal();
|
|
7338
7423
|
init_loadEnv();
|
|
7339
7424
|
init_createRsbuild();
|
|
7340
7425
|
init_config();
|
|
7341
7426
|
var import_shared62 = require("@rsbuild/shared");
|
|
7342
7427
|
init_mergeConfig();
|
|
7428
|
+
init_helpers();
|
|
7343
7429
|
init_constants();
|
|
7344
|
-
var version = "0.7.
|
|
7430
|
+
var version = "0.7.8";
|
|
7345
7431
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7346
7432
|
0 && (module.exports = {
|
|
7347
7433
|
PLUGIN_CSS_NAME,
|
|
@@ -7349,6 +7435,7 @@ var version = "0.7.6";
|
|
|
7349
7435
|
__internalHelper,
|
|
7350
7436
|
createRsbuild,
|
|
7351
7437
|
defineConfig,
|
|
7438
|
+
ensureAssetPrefix,
|
|
7352
7439
|
loadConfig,
|
|
7353
7440
|
loadEnv,
|
|
7354
7441
|
logger,
|