@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/dist/index.js CHANGED
@@ -23,12 +23,12 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
 
26
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
26
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.5.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
27
27
  import { fileURLToPath } from "url";
28
28
  import path from "path";
29
29
  var getFilename, getDirname, __dirname, __filename;
30
30
  var init_esm = __esm({
31
- "../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
31
+ "../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.5.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
32
32
  "use strict";
33
33
  getFilename = () => fileURLToPath(import.meta.url);
34
34
  getDirname = () => path.dirname(getFilename());
@@ -78,16 +78,16 @@ function hintUnknownFiles(message) {
78
78
  }
79
79
  return message;
80
80
  }
81
- function formatMessage(stats) {
81
+ function formatMessage(stats, verbose) {
82
82
  let lines = [];
83
83
  let message;
84
84
  if (typeof stats === "object") {
85
85
  const fileName = resolveFileName(stats);
86
86
  const mainMessage = stats.message;
87
- const details = stats.details ? `
87
+ const details = verbose && stats.details ? `
88
88
  Details: ${stats.details}
89
89
  ` : "";
90
- const stack = stats.stack ? `
90
+ const stack = verbose && stats.stack ? `
91
91
  ${stats.stack}` : "";
92
92
  message = `${fileName}${mainMessage}${details}${stack}`;
93
93
  } else {
@@ -99,11 +99,15 @@ ${stats.stack}` : "";
99
99
  (line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
100
100
  );
101
101
  message = lines.join("\n");
102
+ const innerError = "-- inner error --";
103
+ if (!verbose && message.includes(innerError)) {
104
+ message = message.split(innerError)[0];
105
+ }
102
106
  return message.trim();
103
107
  }
104
- function formatStatsMessages(stats) {
105
- const formattedErrors = stats.errors?.map(formatMessage) || [];
106
- const formattedWarnings = stats.warnings?.map(formatMessage) || [];
108
+ function formatStatsMessages(stats, verbose) {
109
+ const formattedErrors = stats.errors?.map((error) => formatMessage(error, verbose)) || [];
110
+ const formattedWarnings = stats.warnings?.map((warning) => formatMessage(warning, verbose)) || [];
107
111
  return {
108
112
  errors: formattedErrors,
109
113
  warnings: formattedWarnings
@@ -169,12 +173,14 @@ var init_constants = __esm({
169
173
  });
170
174
 
171
175
  // src/helpers.ts
172
- import path2 from "path";
176
+ import path2, { posix } from "path";
173
177
  import {
174
178
  DEFAULT_ASSET_PREFIX,
175
179
  addTrailingSlash,
176
180
  color,
181
+ isDebug,
177
182
  isMultiCompiler,
183
+ isProd,
178
184
  removeTailingSlash
179
185
  } from "@rsbuild/shared";
180
186
  import { fse } from "@rsbuild/shared";
@@ -215,10 +221,14 @@ function formatStats(stats, options = {}) {
215
221
  ...options
216
222
  } : options
217
223
  );
218
- const { errors, warnings } = formatStatsMessages({
219
- errors: getAllStatsErrors(statsData),
220
- warnings: getAllStatsWarnings(statsData)
221
- });
224
+ const { errors, warnings } = formatStatsMessages(
225
+ {
226
+ errors: getAllStatsErrors(statsData),
227
+ warnings: getAllStatsWarnings(statsData)
228
+ },
229
+ // display verbose messages in prod build or debug mode
230
+ isProd() || isDebug()
231
+ );
222
232
  if (stats.hasErrors()) {
223
233
  return {
224
234
  message: formatErrorMessage(errors),
@@ -242,7 +252,7 @@ function isEmptyDir(path14) {
242
252
  async function isFileExists(file) {
243
253
  return fse.promises.access(file, fse.constants.F_OK).then(() => true).catch(() => false);
244
254
  }
245
- var rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists;
255
+ var rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists, urlJoin, canParse, ensureAssetPrefix;
246
256
  var init_helpers = __esm({
247
257
  "src/helpers.ts"() {
248
258
  "use strict";
@@ -384,6 +394,34 @@ ${color.yellow(tips.join("\n"))}`;
384
394
  }
385
395
  return false;
386
396
  };
397
+ urlJoin = (base, path14) => {
398
+ const fullUrl = new URL(base);
399
+ fullUrl.pathname = posix.join(fullUrl.pathname, path14);
400
+ return fullUrl.toString();
401
+ };
402
+ canParse = (url2) => {
403
+ try {
404
+ new URL(url2);
405
+ return true;
406
+ } catch {
407
+ return false;
408
+ }
409
+ };
410
+ ensureAssetPrefix = (url2, assetPrefix) => {
411
+ if (url2.startsWith("//")) {
412
+ return url2;
413
+ }
414
+ if (canParse(url2)) {
415
+ return url2;
416
+ }
417
+ if (assetPrefix.startsWith("http")) {
418
+ return urlJoin(assetPrefix, url2);
419
+ }
420
+ if (assetPrefix.startsWith("//")) {
421
+ return urlJoin(`https:${assetPrefix}`, url2).replace("https:", "");
422
+ }
423
+ return posix.join(assetPrefix, url2);
424
+ };
387
425
  }
388
426
  });
389
427
 
@@ -566,7 +604,7 @@ async function loadConfig({
566
604
  return config;
567
605
  };
568
606
  try {
569
- const { default: jiti } = await import("@rsbuild/shared/jiti");
607
+ const { default: jiti } = await import("../compiled/jiti/index.js");
570
608
  const loadConfig2 = jiti(__filename, {
571
609
  esmResolve: true,
572
610
  // disable require cache to support restart CLI and read the new config
@@ -655,7 +693,7 @@ async function stringifyConfig(config, verbose) {
655
693
  const stringify = RspackChain.toString;
656
694
  return stringify(config, { verbose });
657
695
  }
658
- var getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath;
696
+ var getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath, normalizePublicDirs;
659
697
  var init_config = __esm({
660
698
  "src/config.ts"() {
661
699
  "use strict";
@@ -680,12 +718,7 @@ var init_config = __esm({
680
718
  htmlFallback: "index",
681
719
  compress: true,
682
720
  printUrls: true,
683
- strictPort: false,
684
- publicDir: {
685
- name: "public",
686
- copyOnBuild: true,
687
- watch: false
688
- }
721
+ strictPort: false
689
722
  });
690
723
  getDefaultSourceConfig = () => ({
691
724
  alias: {},
@@ -826,6 +859,31 @@ var init_config = __esm({
826
859
  }
827
860
  return null;
828
861
  };
862
+ normalizePublicDirs = (publicDir) => {
863
+ if (publicDir === false) {
864
+ return [];
865
+ }
866
+ const defaultConfig = {
867
+ name: "public",
868
+ copyOnBuild: true,
869
+ watch: false
870
+ };
871
+ if (publicDir === void 0) {
872
+ return [defaultConfig];
873
+ }
874
+ if (Array.isArray(publicDir)) {
875
+ return publicDir.map((options) => ({
876
+ ...defaultConfig,
877
+ ...options
878
+ }));
879
+ }
880
+ return [
881
+ {
882
+ ...defaultConfig,
883
+ ...publicDir
884
+ }
885
+ ];
886
+ };
829
887
  }
830
888
  });
831
889
 
@@ -861,6 +919,7 @@ function loadEnv({
861
919
  for (const key of Object.keys(process.env)) {
862
920
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
863
921
  const val = process.env[key];
922
+ publicVars[`import.meta.env.${key}`] = JSON.stringify(val);
864
923
  publicVars[`process.env.${key}`] = JSON.stringify(val);
865
924
  }
866
925
  }
@@ -1042,7 +1101,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
1042
1101
  return {
1043
1102
  entry: getEntryObject(config, "web"),
1044
1103
  targets: config.output?.targets || [],
1045
- version: "0.7.6",
1104
+ version: "0.7.8",
1046
1105
  rootPath,
1047
1106
  distPath,
1048
1107
  cachePath,
@@ -1632,7 +1691,7 @@ var init_rspackConfig = __esm({
1632
1691
  // src/provider/initConfigs.ts
1633
1692
  import {
1634
1693
  debug as debug3,
1635
- isDebug
1694
+ isDebug as isDebug2
1636
1695
  } from "@rsbuild/shared";
1637
1696
  async function modifyRsbuildConfig(context) {
1638
1697
  debug3("modify Rsbuild config");
@@ -1669,7 +1728,7 @@ async function initConfigs({
1669
1728
  const rspackConfigs = await Promise.all(
1670
1729
  targets.map((target) => generateRspackConfig({ target, context }))
1671
1730
  );
1672
- if (isDebug()) {
1731
+ if (isDebug2()) {
1673
1732
  const inspect = () => {
1674
1733
  const inspectOptions = {
1675
1734
  verbose: true,
@@ -1780,7 +1839,7 @@ import {
1780
1839
  color as color6,
1781
1840
  debug as debug4,
1782
1841
  isDev,
1783
- isProd,
1842
+ isProd as isProd2,
1784
1843
  logger as logger5,
1785
1844
  onCompileDone,
1786
1845
  prettyTime
@@ -1818,7 +1877,7 @@ async function createCompiler({
1818
1877
  }
1819
1878
  isCompiling = true;
1820
1879
  });
1821
- if (isProd()) {
1880
+ if (isProd2()) {
1822
1881
  compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
1823
1882
  }
1824
1883
  const done = async (stats) => {
@@ -1901,7 +1960,7 @@ import { parse as parse2 } from "url";
1901
1960
  import {
1902
1961
  color as color7,
1903
1962
  debug as debug5,
1904
- isDebug as isDebug2,
1963
+ isDebug as isDebug3,
1905
1964
  logger as logger6
1906
1965
  } from "@rsbuild/shared";
1907
1966
  var faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
@@ -1986,7 +2045,7 @@ var init_middlewares = __esm({
1986
2045
  });
1987
2046
  };
1988
2047
  const rewrite = (newUrl, isFallback = false) => {
1989
- if (isFallback && isDebug2()) {
2048
+ if (isFallback && isDebug3()) {
1990
2049
  debug5(
1991
2050
  `${req.method} ${color7.gray(
1992
2051
  `${req.url} ${color7.yellow("fallback")} to ${newUrl}`
@@ -2113,12 +2172,13 @@ var init_proxy = __esm({
2113
2172
  // src/server/getDevMiddlewares.ts
2114
2173
  import { isAbsolute as isAbsolute4, join as join7 } from "path";
2115
2174
  import url from "url";
2116
- import { isDebug as isDebug3 } from "@rsbuild/shared";
2175
+ import { isDebug as isDebug4 } from "@rsbuild/shared";
2117
2176
  var applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
2118
2177
  var init_getDevMiddlewares = __esm({
2119
2178
  "src/server/getDevMiddlewares.ts"() {
2120
2179
  "use strict";
2121
2180
  init_esm();
2181
+ init_config();
2122
2182
  init_middlewares();
2123
2183
  applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
2124
2184
  const setupMiddlewares = dev.setupMiddlewares || [];
@@ -2196,11 +2256,12 @@ var init_getDevMiddlewares = __esm({
2196
2256
  }
2197
2257
  });
2198
2258
  }
2199
- if (server.publicDir !== false && server.publicDir?.name) {
2259
+ const publicDirs = normalizePublicDirs(server?.publicDir);
2260
+ for (const publicDir of publicDirs) {
2200
2261
  const { default: sirv } = await import("../compiled/sirv/index.js");
2201
- const { name } = server.publicDir;
2202
- const publicDir = isAbsolute4(name) ? name : join7(pwd, name);
2203
- const assetMiddleware = sirv(publicDir, {
2262
+ const { name } = publicDir;
2263
+ const normalizedPath = isAbsolute4(name) ? name : join7(pwd, name);
2264
+ const assetMiddleware = sirv(normalizedPath, {
2204
2265
  etag: true,
2205
2266
  dev: true
2206
2267
  });
@@ -2235,7 +2296,7 @@ var init_getDevMiddlewares = __esm({
2235
2296
  getMiddlewares = async (options) => {
2236
2297
  const middlewares = [];
2237
2298
  const { compileMiddlewareAPI } = options;
2238
- if (isDebug3()) {
2299
+ if (isDebug4()) {
2239
2300
  middlewares.push(await getRequestLoggerMiddleware());
2240
2301
  }
2241
2302
  const { before, after } = applySetupMiddlewares(
@@ -2262,13 +2323,7 @@ var init_getDevMiddlewares = __esm({
2262
2323
  // src/server/helper.ts
2263
2324
  import net from "net";
2264
2325
  import os from "os";
2265
- import {
2266
- color as color8,
2267
- deepmerge,
2268
- isFunction as isFunction4,
2269
- logger as logger8,
2270
- normalizeUrl
2271
- } from "@rsbuild/shared";
2326
+ import { color as color8, deepmerge, isFunction as isFunction4, logger as logger8 } from "@rsbuild/shared";
2272
2327
  function getURLMessages(urls, routes) {
2273
2328
  if (routes.length === 1) {
2274
2329
  return urls.map(
@@ -2333,12 +2388,13 @@ function printServerURLs({
2333
2388
  logger8.log(message);
2334
2389
  return message;
2335
2390
  }
2336
- var formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
2391
+ var normalizeUrl, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
2337
2392
  var init_helper = __esm({
2338
2393
  "src/server/helper.ts"() {
2339
2394
  "use strict";
2340
2395
  init_esm();
2341
2396
  init_constants();
2397
+ normalizeUrl = (url2) => url2.replace(/([^:]\/)\/+/g, "$1");
2342
2398
  formatPrefix = (prefix) => {
2343
2399
  if (!prefix) {
2344
2400
  return "/";
@@ -2593,11 +2649,15 @@ async function watchDevFiles(devConfig, compileMiddlewareAPI) {
2593
2649
  return startWatchFiles(watchOptions, compileMiddlewareAPI);
2594
2650
  }
2595
2651
  function watchServerFiles(serverConfig, compileMiddlewareAPI) {
2596
- const { publicDir } = serverConfig;
2597
- if (!publicDir || !publicDir.watch || !publicDir.name) {
2652
+ const publicDirs = normalizePublicDirs(serverConfig.publicDir);
2653
+ if (!publicDirs.length) {
2654
+ return;
2655
+ }
2656
+ const watchPaths = publicDirs.filter((item) => item.watch).map((item) => item.name);
2657
+ if (!watchPaths.length) {
2598
2658
  return;
2599
2659
  }
2600
- const watchOptions = prepareWatchOptions(publicDir.name);
2660
+ const watchOptions = prepareWatchOptions(watchPaths);
2601
2661
  return startWatchFiles(watchOptions, compileMiddlewareAPI);
2602
2662
  }
2603
2663
  function prepareWatchOptions(paths, options = {}) {
@@ -2618,6 +2678,7 @@ var init_watchFiles = __esm({
2618
2678
  "src/server/watchFiles.ts"() {
2619
2679
  "use strict";
2620
2680
  init_esm();
2681
+ init_config();
2621
2682
  }
2622
2683
  });
2623
2684
 
@@ -3047,189 +3108,12 @@ var init_devServer = __esm({
3047
3108
  }
3048
3109
  });
3049
3110
 
3050
- // src/server/prodServer.ts
3051
- var prodServer_exports = {};
3052
- __export(prodServer_exports, {
3053
- RsbuildProdServer: () => RsbuildProdServer,
3054
- startProdServer: () => startProdServer
3055
- });
3056
- import { join as join8 } from "path";
3057
- import {
3058
- getNodeEnv as getNodeEnv6,
3059
- isDebug as isDebug4,
3060
- setNodeEnv as setNodeEnv3
3061
- } from "@rsbuild/shared";
3062
- async function startProdServer(context, config, { getPortSilently } = {}) {
3063
- if (!getNodeEnv6()) {
3064
- setNodeEnv3("production");
3065
- }
3066
- const { port, host, https } = await getServerConfig({
3067
- config,
3068
- getPortSilently
3069
- });
3070
- const { default: connect } = await import("../compiled/connect/index.js");
3071
- const middlewares = connect();
3072
- const serverConfig = config.server;
3073
- const server = new RsbuildProdServer(
3074
- {
3075
- pwd: context.rootPath,
3076
- output: {
3077
- path: config.output.distPath.root || ROOT_DIST_DIR,
3078
- assetPrefix: config.output.assetPrefix
3079
- },
3080
- serverConfig
3081
- },
3082
- middlewares
3083
- );
3084
- await context.hooks.onBeforeStartProdServer.call();
3085
- const httpServer = await createHttpServer({
3086
- serverConfig,
3087
- middlewares: server.middlewares
3088
- });
3089
- await server.onInit(httpServer);
3090
- return new Promise((resolve) => {
3091
- httpServer.listen(
3092
- {
3093
- host,
3094
- port
3095
- },
3096
- async () => {
3097
- const routes = formatRoutes(
3098
- context.entry,
3099
- config.output.distPath.html,
3100
- config.html.outputStructure
3101
- );
3102
- await context.hooks.onAfterStartProdServer.call({
3103
- port,
3104
- routes
3105
- });
3106
- const protocol = https ? "https" : "http";
3107
- const urls = getAddressUrls({ protocol, port, host });
3108
- printServerURLs({
3109
- urls,
3110
- port,
3111
- routes,
3112
- protocol,
3113
- printUrls: serverConfig.printUrls
3114
- });
3115
- const onClose = () => {
3116
- server.close();
3117
- httpServer.close();
3118
- };
3119
- resolve({
3120
- port,
3121
- urls: urls.map((item) => item.url),
3122
- server: {
3123
- close: async () => {
3124
- onClose();
3125
- }
3126
- }
3127
- });
3128
- }
3129
- );
3130
- });
3131
- }
3132
- var RsbuildProdServer;
3133
- var init_prodServer = __esm({
3134
- "src/server/prodServer.ts"() {
3135
- "use strict";
3136
- init_esm();
3137
- init_constants();
3138
- init_helper();
3139
- init_httpServer();
3140
- init_middlewares();
3141
- RsbuildProdServer = class {
3142
- constructor(options, middlewares) {
3143
- __publicField(this, "app");
3144
- __publicField(this, "options");
3145
- __publicField(this, "middlewares");
3146
- this.options = options;
3147
- this.middlewares = middlewares;
3148
- }
3149
- // Complete the preparation of services
3150
- async onInit(app) {
3151
- this.app = app;
3152
- await this.applyDefaultMiddlewares();
3153
- }
3154
- async applyDefaultMiddlewares() {
3155
- const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
3156
- if (isDebug4()) {
3157
- this.middlewares.use(await getRequestLoggerMiddleware());
3158
- }
3159
- if (compress) {
3160
- const { default: compression } = await import("../compiled/http-compression/index.js");
3161
- this.middlewares.use((req, res, next) => {
3162
- compression({
3163
- gzip: true,
3164
- brotli: false
3165
- })(req, res, next);
3166
- });
3167
- }
3168
- if (headers) {
3169
- this.middlewares.use((_req, res, next) => {
3170
- for (const [key, value] of Object.entries(headers)) {
3171
- res.setHeader(key, value);
3172
- }
3173
- next();
3174
- });
3175
- }
3176
- if (proxy) {
3177
- const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
3178
- const { middlewares, upgrade } = createProxyMiddleware2(proxy);
3179
- for (const middleware of middlewares) {
3180
- this.middlewares.use(middleware);
3181
- }
3182
- this.app.on("upgrade", upgrade);
3183
- }
3184
- this.applyStaticAssetMiddleware();
3185
- if (historyApiFallback) {
3186
- const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
3187
- const historyApiFallbackMiddleware = connectHistoryApiFallback(
3188
- historyApiFallback === true ? {} : historyApiFallback
3189
- );
3190
- this.middlewares.use(historyApiFallbackMiddleware);
3191
- await this.applyStaticAssetMiddleware();
3192
- }
3193
- this.middlewares.use(faviconFallbackMiddleware);
3194
- }
3195
- async applyStaticAssetMiddleware() {
3196
- const {
3197
- output: { path: path14, assetPrefix },
3198
- serverConfig: { htmlFallback },
3199
- pwd
3200
- } = this.options;
3201
- const { default: sirv } = await import("../compiled/sirv/index.js");
3202
- const assetMiddleware = sirv(join8(pwd, path14), {
3203
- etag: true,
3204
- dev: true,
3205
- ignores: ["favicon.ico"],
3206
- single: htmlFallback === "index"
3207
- });
3208
- this.middlewares.use((req, res, next) => {
3209
- const url2 = req.url;
3210
- if (assetPrefix && url2?.startsWith(assetPrefix)) {
3211
- req.url = url2.slice(assetPrefix.length);
3212
- assetMiddleware(req, res, (...args) => {
3213
- req.url = url2;
3214
- next(...args);
3215
- });
3216
- } else {
3217
- assetMiddleware(req, res, next);
3218
- }
3219
- });
3220
- }
3221
- close() {
3222
- }
3223
- };
3224
- }
3225
- });
3226
-
3227
3111
  // src/provider/build.ts
3228
3112
  var build_exports = {};
3229
3113
  __export(build_exports, {
3230
3114
  build: () => build
3231
3115
  });
3232
- import { getNodeEnv as getNodeEnv7, logger as logger10, onCompileDone as onCompileDone2, setNodeEnv as setNodeEnv4 } from "@rsbuild/shared";
3116
+ import { getNodeEnv as getNodeEnv6, logger as logger10, onCompileDone as onCompileDone2, setNodeEnv as setNodeEnv3 } from "@rsbuild/shared";
3233
3117
  import { rspack as rspack4 } from "@rspack/core";
3234
3118
  var build;
3235
3119
  var init_build = __esm({
@@ -3239,8 +3123,8 @@ var init_build = __esm({
3239
3123
  init_createCompiler();
3240
3124
  init_initConfigs();
3241
3125
  build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
3242
- if (!getNodeEnv7()) {
3243
- setNodeEnv4(mode);
3126
+ if (!getNodeEnv6()) {
3127
+ setNodeEnv3(mode);
3244
3128
  }
3245
3129
  const { context } = initOptions;
3246
3130
  let compiler;
@@ -3351,11 +3235,6 @@ var init_provider = __esm({
3351
3235
  );
3352
3236
  return server.listen();
3353
3237
  },
3354
- async preview(options) {
3355
- const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
3356
- const config = await initRsbuildConfig({ context, pluginManager });
3357
- return startProdServer2(context, config, options);
3358
- },
3359
3238
  async build(options) {
3360
3239
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
3361
3240
  return build2({ context, pluginManager, rsbuildOptions }, options);
@@ -3398,12 +3277,12 @@ var init_basic = __esm({
3398
3277
  name: "rsbuild:basic",
3399
3278
  setup(api) {
3400
3279
  api.modifyBundlerChain(
3401
- (chain, { env, isProd: isProd5, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3280
+ (chain, { env, isProd: isProd6, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3402
3281
  const config = api.getNormalizedConfig();
3403
3282
  chain.name(TARGET_ID_MAP2[target]);
3404
3283
  chain.devtool(getJsSourceMap(config));
3405
3284
  chain.context(api.context.rootPath);
3406
- chain.mode(isProd5 ? "production" : "development");
3285
+ chain.mode(isProd6 ? "production" : "development");
3407
3286
  chain.merge({
3408
3287
  infrastructureLogging: {
3409
3288
  // Using `error` level to avoid `cache.PackFileCacheStrategy` logs
@@ -3416,9 +3295,9 @@ var init_basic = __esm({
3416
3295
  exportsPresence: "error"
3417
3296
  }
3418
3297
  });
3419
- const isMinimize = isProd5 && config.output.minify !== false;
3298
+ const isMinimize = isProd6 && config.output.minify !== false;
3420
3299
  chain.optimization.minimize(isMinimize);
3421
- const usingHMR = isUsingHMR(config, { target, isProd: isProd5 });
3300
+ const usingHMR = isUsingHMR(config, { target, isProd: isProd6 });
3422
3301
  if (usingHMR) {
3423
3302
  chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
3424
3303
  }
@@ -3442,10 +3321,10 @@ __export(cache_exports, {
3442
3321
  pluginCache: () => pluginCache
3443
3322
  });
3444
3323
  import crypto from "crypto";
3445
- import { isAbsolute as isAbsolute5, join as join9 } from "path";
3324
+ import { isAbsolute as isAbsolute5, join as join8 } from "path";
3446
3325
  import { fse as fse3 } from "@rsbuild/shared";
3447
3326
  async function validateCache(cacheDirectory, buildDependencies) {
3448
- const configFile = join9(cacheDirectory, "buildDependencies.json");
3327
+ const configFile = join8(cacheDirectory, "buildDependencies.json");
3449
3328
  if (await isFileExists(configFile)) {
3450
3329
  const prevBuildDependencies = await fse3.readJSON(configFile);
3451
3330
  if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
@@ -3462,13 +3341,13 @@ function getDigestHash(digest) {
3462
3341
  }
3463
3342
  function getCacheDirectory({ cacheDirectory }, context) {
3464
3343
  if (cacheDirectory) {
3465
- return isAbsolute5(cacheDirectory) ? cacheDirectory : join9(context.rootPath, cacheDirectory);
3344
+ return isAbsolute5(cacheDirectory) ? cacheDirectory : join8(context.rootPath, cacheDirectory);
3466
3345
  }
3467
- return join9(context.cachePath, context.bundlerType);
3346
+ return join8(context.cachePath, context.bundlerType);
3468
3347
  }
3469
3348
  async function getBuildDependencies(context, config) {
3470
- const rootPackageJson = join9(context.rootPath, "package.json");
3471
- const browserslistConfig = join9(context.rootPath, ".browserslistrc");
3349
+ const rootPackageJson = join8(context.rootPath, "package.json");
3350
+ const browserslistConfig = join8(context.rootPath, ".browserslistrc");
3472
3351
  const buildDependencies = {};
3473
3352
  if (await isFileExists(rootPackageJson)) {
3474
3353
  buildDependencies.packageJson = [rootPackageJson];
@@ -3484,7 +3363,7 @@ async function getBuildDependencies(context, config) {
3484
3363
  }
3485
3364
  const tailwindExts = ["ts", "js", "cjs", "mjs"];
3486
3365
  const configs = tailwindExts.map(
3487
- (ext) => join9(context.rootPath, `tailwind.config.${ext}`)
3366
+ (ext) => join8(context.rootPath, `tailwind.config.${ext}`)
3488
3367
  );
3489
3368
  const tailwindConfig = findExists(configs);
3490
3369
  if (tailwindConfig) {
@@ -3614,7 +3493,7 @@ async function applyCSSRule({
3614
3493
  rule,
3615
3494
  config,
3616
3495
  context,
3617
- utils: { target, isProd: isProd5, CHAIN_ID: CHAIN_ID3 },
3496
+ utils: { target, isProd: isProd6, CHAIN_ID: CHAIN_ID3 },
3618
3497
  importLoaders = 1
3619
3498
  }) {
3620
3499
  const browserslist = await getBrowserslistWithDefault2(
@@ -3623,7 +3502,7 @@ async function applyCSSRule({
3623
3502
  target
3624
3503
  );
3625
3504
  const enableExtractCSS = isUseCssExtract(config, target);
3626
- const localIdentName = getCSSModulesLocalIdentName(config, isProd5);
3505
+ const localIdentName = getCSSModulesLocalIdentName(config, isProd6);
3627
3506
  const cssLoaderOptions = getCSSLoaderOptions({
3628
3507
  config,
3629
3508
  importLoaders,
@@ -3665,8 +3544,8 @@ var init_css = __esm({
3665
3544
  init_pluginHelper();
3666
3545
  enableNativeCss = (config) => !config.output.injectStyles;
3667
3546
  isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
3668
- getCSSModulesLocalIdentName = (config, isProd5) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3669
- (isProd5 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
3547
+ getCSSModulesLocalIdentName = (config, isProd6) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3548
+ (isProd6 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
3670
3549
  normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
3671
3550
  if (options.modules && exportOnlyLocals) {
3672
3551
  let { modules } = options;
@@ -3812,7 +3691,7 @@ var output_exports = {};
3812
3691
  __export(output_exports, {
3813
3692
  pluginOutput: () => pluginOutput
3814
3693
  });
3815
- import { posix } from "path";
3694
+ import { posix as posix2 } from "path";
3816
3695
  import {
3817
3696
  DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX3,
3818
3697
  getDistPath as getDistPath3,
@@ -3820,13 +3699,13 @@ import {
3820
3699
  } from "@rsbuild/shared";
3821
3700
  import { rspack as rspack5 } from "@rspack/core";
3822
3701
  function getPublicPath({
3823
- isProd: isProd5,
3702
+ isProd: isProd6,
3824
3703
  config,
3825
3704
  context
3826
3705
  }) {
3827
3706
  const { dev, output } = config;
3828
3707
  let publicPath = DEFAULT_ASSET_PREFIX3;
3829
- if (isProd5) {
3708
+ if (isProd6) {
3830
3709
  if (typeof output.assetPrefix === "string") {
3831
3710
  publicPath = output.assetPrefix;
3832
3711
  }
@@ -3858,38 +3737,38 @@ var init_output = __esm({
3858
3737
  name: "rsbuild:output",
3859
3738
  setup(api) {
3860
3739
  api.modifyBundlerChain(
3861
- async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd5, isServer, isServiceWorker }) => {
3740
+ async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd6, isServer, isServiceWorker }) => {
3862
3741
  const config = api.getNormalizedConfig();
3863
3742
  const publicPath = getPublicPath({
3864
3743
  config,
3865
- isProd: isProd5,
3744
+ isProd: isProd6,
3866
3745
  context: api.context
3867
3746
  });
3868
3747
  const jsPath = getDistPath3(config, "js");
3869
3748
  const jsAsyncPath = getDistPath3(config, "jsAsync");
3870
- const jsFilename = getFilename2(config, "js", isProd5);
3749
+ const jsFilename = getFilename2(config, "js", isProd6);
3871
3750
  const isJsFilenameFn = typeof jsFilename === "function";
3872
3751
  chain.output.path(api.context.distPath).filename(
3873
3752
  isJsFilenameFn ? (...args) => {
3874
3753
  const name = jsFilename(...args);
3875
- return posix.join(jsPath, name);
3876
- } : posix.join(jsPath, jsFilename)
3754
+ return posix2.join(jsPath, name);
3755
+ } : posix2.join(jsPath, jsFilename)
3877
3756
  ).chunkFilename(
3878
3757
  isJsFilenameFn ? (...args) => {
3879
3758
  const name = jsFilename(...args);
3880
- return posix.join(jsAsyncPath, name);
3881
- } : posix.join(jsAsyncPath, jsFilename)
3759
+ return posix2.join(jsAsyncPath, name);
3760
+ } : posix2.join(jsAsyncPath, jsFilename)
3882
3761
  ).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3883
3762
  if (isServer) {
3884
3763
  const serverPath = getDistPath3(config, "server");
3885
- chain.output.path(posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3764
+ chain.output.path(posix2.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3886
3765
  ...chain.output.get("library") || {},
3887
3766
  type: "commonjs2"
3888
3767
  });
3889
3768
  }
3890
3769
  if (isServiceWorker) {
3891
3770
  const workerPath = getDistPath3(config, "worker");
3892
- const filename = posix.join(workerPath, "[name].js");
3771
+ const filename = posix2.join(workerPath, "[name].js");
3893
3772
  chain.output.filename(filename).chunkFilename(filename);
3894
3773
  }
3895
3774
  if (config.output.copy && api.context.bundlerType === "rspack") {
@@ -3900,12 +3779,12 @@ var init_output = __esm({
3900
3779
  if (isUseCssExtract(config, target)) {
3901
3780
  const extractPluginOptions = config.tools.cssExtract.pluginOptions;
3902
3781
  const cssPath = getDistPath3(config, "css");
3903
- const cssFilename = getFilename2(config, "css", isProd5);
3782
+ const cssFilename = getFilename2(config, "css", isProd6);
3904
3783
  const cssAsyncPath = getDistPath3(config, "cssAsync");
3905
3784
  chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
3906
3785
  {
3907
- filename: posix.join(cssPath, cssFilename),
3908
- chunkFilename: posix.join(cssAsyncPath, cssFilename),
3786
+ filename: posix2.join(cssPath, cssFilename),
3787
+ chunkFilename: posix2.join(cssAsyncPath, cssFilename),
3909
3788
  ...extractPluginOptions
3910
3789
  }
3911
3790
  ]);
@@ -4283,12 +4162,12 @@ var init_asset = __esm({
4283
4162
  pluginAsset = () => ({
4284
4163
  name: "rsbuild:asset",
4285
4164
  setup(api) {
4286
- api.modifyBundlerChain((chain, { isProd: isProd5, target }) => {
4165
+ api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
4287
4166
  const config = api.getNormalizedConfig();
4288
4167
  const createAssetRule = (assetType, exts, emit2) => {
4289
4168
  const regExp = getRegExpForExts(exts);
4290
4169
  const distDir = getDistPath4(config, assetType);
4291
- const filename = getFilename3(config, assetType, isProd5);
4170
+ const filename = getFilename3(config, assetType, isProd6);
4292
4171
  const { dataUriLimit } = config.output;
4293
4172
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
4294
4173
  const rule = chain.module.rule(assetType).test(regExp);
@@ -4371,9 +4250,9 @@ var init_minimize = __esm({
4371
4250
  }
4372
4251
  return options;
4373
4252
  };
4374
- parseMinifyOptions = (config, isProd5 = true) => {
4253
+ parseMinifyOptions = (config, isProd6 = true) => {
4375
4254
  const minify = config.output.minify;
4376
- if (minify === false || !isProd5) {
4255
+ if (minify === false || !isProd6) {
4377
4256
  return {
4378
4257
  minifyJs: false,
4379
4258
  minifyCss: false,
@@ -4405,9 +4284,9 @@ var init_minimize = __esm({
4405
4284
  if (api.context.bundlerType === "webpack") {
4406
4285
  return;
4407
4286
  }
4408
- api.modifyBundlerChain(async (chain, { isProd: isProd5 }) => {
4287
+ api.modifyBundlerChain(async (chain, { isProd: isProd6 }) => {
4409
4288
  const config = api.getNormalizedConfig();
4410
- const isMinimize = isProd5 && config.output.minify !== false;
4289
+ const isMinimize = isProd6 && config.output.minify !== false;
4411
4290
  if (!isMinimize) {
4412
4291
  return;
4413
4292
  }
@@ -4436,14 +4315,14 @@ __export(HtmlBasicPlugin_exports, {
4436
4315
  });
4437
4316
  import {
4438
4317
  isFunction as isFunction6,
4439
- partition,
4440
- withPublicPath
4318
+ partition
4441
4319
  } from "@rsbuild/shared";
4442
4320
  var VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, addFavicon, HtmlBasicPlugin;
4443
4321
  var init_HtmlBasicPlugin = __esm({
4444
4322
  "src/rspack/HtmlBasicPlugin.ts"() {
4445
4323
  "use strict";
4446
4324
  init_esm();
4325
+ init_helpers();
4447
4326
  init_pluginHelper();
4448
4327
  VOID_TAGS = [
4449
4328
  "area",
@@ -4518,9 +4397,9 @@ var init_HtmlBasicPlugin = __esm({
4518
4397
  if (typeof optPublicPath === "function") {
4519
4398
  filename = optPublicPath(filename, data.publicPath);
4520
4399
  } else if (typeof optPublicPath === "string") {
4521
- filename = withPublicPath(filename, optPublicPath);
4400
+ filename = ensureAssetPrefix(filename, optPublicPath);
4522
4401
  } else if (optPublicPath !== false) {
4523
- filename = withPublicPath(filename, data.publicPath);
4402
+ filename = ensureAssetPrefix(filename, data.publicPath);
4524
4403
  }
4525
4404
  const optHash = tag.hash ?? tagConfig.hash;
4526
4405
  if (typeof optHash === "function") {
@@ -4646,13 +4525,14 @@ __export(HtmlAppIconPlugin_exports, {
4646
4525
  HtmlAppIconPlugin: () => HtmlAppIconPlugin
4647
4526
  });
4648
4527
  import fs4 from "fs";
4649
- import { basename, posix as posix2 } from "path";
4650
- import { getPublicPathFromCompiler as getPublicPathFromCompiler2, withPublicPath as withPublicPath2 } from "@rsbuild/shared";
4528
+ import { basename, posix as posix3 } from "path";
4529
+ import { getPublicPathFromCompiler as getPublicPathFromCompiler2 } from "@rsbuild/shared";
4651
4530
  var HtmlAppIconPlugin;
4652
4531
  var init_HtmlAppIconPlugin = __esm({
4653
4532
  "src/rspack/HtmlAppIconPlugin.ts"() {
4654
4533
  "use strict";
4655
4534
  init_esm();
4535
+ init_helpers();
4656
4536
  init_pluginHelper();
4657
4537
  HtmlAppIconPlugin = class {
4658
4538
  constructor(options) {
@@ -4669,7 +4549,7 @@ var init_HtmlAppIconPlugin = __esm({
4669
4549
  `[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
4670
4550
  );
4671
4551
  }
4672
- const iconRelativePath = posix2.join(this.distDir, basename(this.iconPath));
4552
+ const iconRelativePath = posix3.join(this.distDir, basename(this.iconPath));
4673
4553
  compiler.hooks.compilation.tap(this.name, (compilation) => {
4674
4554
  getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
4675
4555
  const publicPath = getPublicPathFromCompiler2(compiler);
@@ -4679,7 +4559,7 @@ var init_HtmlAppIconPlugin = __esm({
4679
4559
  attributes: {
4680
4560
  rel: "apple-touch-icon",
4681
4561
  sizes: "180*180",
4682
- href: withPublicPath2(iconRelativePath, publicPath)
4562
+ href: ensureAssetPrefix(iconRelativePath, publicPath)
4683
4563
  },
4684
4564
  meta: {}
4685
4565
  });
@@ -4765,8 +4645,8 @@ function getTerserMinifyOptions(config) {
4765
4645
  const finalOptions = applyRemoveConsole(options, config);
4766
4646
  return finalOptions;
4767
4647
  }
4768
- async function getHtmlMinifyOptions(isProd5, config) {
4769
- if (!isProd5 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4648
+ async function getHtmlMinifyOptions(isProd6, config) {
4649
+ if (!isProd6 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4770
4650
  return false;
4771
4651
  }
4772
4652
  const minifyJS = getTerserMinifyOptions(config);
@@ -4916,12 +4796,12 @@ var init_html = __esm({
4916
4796
  name: "rsbuild:html",
4917
4797
  setup(api) {
4918
4798
  api.modifyBundlerChain(
4919
- async (chain, { HtmlPlugin, isProd: isProd5, CHAIN_ID: CHAIN_ID3, target }) => {
4799
+ async (chain, { HtmlPlugin, isProd: isProd6, CHAIN_ID: CHAIN_ID3, target }) => {
4920
4800
  const config = api.getNormalizedConfig();
4921
4801
  if (isHtmlDisabled(config, target)) {
4922
4802
  return;
4923
4803
  }
4924
- const minify = await getHtmlMinifyOptions(isProd5, config);
4804
+ const minify = await getHtmlMinifyOptions(isProd6, config);
4925
4805
  const assetPrefix = getPublicPathFromChain(chain, false);
4926
4806
  const entries = chain.entryPoints.entries() || {};
4927
4807
  const entryNames = Object.keys(entries);
@@ -5032,7 +4912,7 @@ var wasm_exports = {};
5032
4912
  __export(wasm_exports, {
5033
4913
  pluginWasm: () => pluginWasm
5034
4914
  });
5035
- import { posix as posix3 } from "path";
4915
+ import { posix as posix4 } from "path";
5036
4916
  import { getDistPath as getDistPath6 } from "@rsbuild/shared";
5037
4917
  var pluginWasm;
5038
4918
  var init_wasm = __esm({
@@ -5049,7 +4929,7 @@ var init_wasm = __esm({
5049
4929
  ...chain.get("experiments"),
5050
4930
  asyncWebAssembly: true
5051
4931
  });
5052
- const wasmFilename = posix3.join(distPath, "[hash].module.wasm");
4932
+ const wasmFilename = posix4.join(distPath, "[hash].module.wasm");
5053
4933
  chain.output.merge({
5054
4934
  webassemblyModuleFilename: wasmFilename
5055
4935
  });
@@ -5148,7 +5028,7 @@ var define_exports = {};
5148
5028
  __export(define_exports, {
5149
5029
  pluginDefine: () => pluginDefine
5150
5030
  });
5151
- import { getNodeEnv as getNodeEnv8 } from "@rsbuild/shared";
5031
+ import { getNodeEnv as getNodeEnv7 } from "@rsbuild/shared";
5152
5032
  var pluginDefine;
5153
5033
  var init_define = __esm({
5154
5034
  "src/plugins/define.ts"() {
@@ -5161,7 +5041,7 @@ var init_define = __esm({
5161
5041
  api.modifyBundlerChain((chain, { CHAIN_ID: CHAIN_ID3, bundler }) => {
5162
5042
  const config = api.getNormalizedConfig();
5163
5043
  const builtinVars = {
5164
- "process.env.NODE_ENV": JSON.stringify(getNodeEnv8()),
5044
+ "process.env.NODE_ENV": JSON.stringify(getNodeEnv7()),
5165
5045
  "process.env.ASSET_PREFIX": JSON.stringify(
5166
5046
  getPublicPathFromChain(chain, false)
5167
5047
  )
@@ -5180,7 +5060,7 @@ var progress_exports = {};
5180
5060
  __export(progress_exports, {
5181
5061
  pluginProgress: () => pluginProgress
5182
5062
  });
5183
- import { TARGET_ID_MAP as TARGET_ID_MAP3, isProd as isProd2 } from "@rsbuild/shared";
5063
+ import { TARGET_ID_MAP as TARGET_ID_MAP3, isProd as isProd3 } from "@rsbuild/shared";
5184
5064
  import { rspack as rspack7 } from "@rspack/core";
5185
5065
  var pluginProgress;
5186
5066
  var init_progress = __esm({
@@ -5196,7 +5076,7 @@ var init_progress = __esm({
5196
5076
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3 }) => {
5197
5077
  const config = api.getNormalizedConfig();
5198
5078
  const options = config.dev.progressBar ?? // enable progress bar in production by default
5199
- isProd2();
5079
+ isProd3();
5200
5080
  if (!options) {
5201
5081
  return;
5202
5082
  }
@@ -5605,12 +5485,7 @@ __export(open_exports, {
5605
5485
  });
5606
5486
  import { exec } from "child_process";
5607
5487
  import { promisify } from "util";
5608
- import {
5609
- canParse,
5610
- castArray as castArray6,
5611
- debug as debug7,
5612
- logger as logger13
5613
- } from "@rsbuild/shared";
5488
+ import { castArray as castArray6, debug as debug7, logger as logger13 } from "@rsbuild/shared";
5614
5489
  async function openBrowser(url2) {
5615
5490
  const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
5616
5491
  if (shouldTryOpenChromeWithAppleScript) {
@@ -5708,6 +5583,7 @@ var init_open = __esm({
5708
5583
  "use strict";
5709
5584
  init_esm();
5710
5585
  init_constants();
5586
+ init_helpers();
5711
5587
  execAsync = promisify(exec);
5712
5588
  supportedChromiumBrowsers = [
5713
5589
  "Google Chrome Canary",
@@ -5757,7 +5633,7 @@ var InlineChunkHtmlPlugin_exports = {};
5757
5633
  __export(InlineChunkHtmlPlugin_exports, {
5758
5634
  InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
5759
5635
  });
5760
- import { join as join10 } from "path";
5636
+ import { join as join9 } from "path";
5761
5637
  import {
5762
5638
  addTrailingSlash as addTrailingSlash2,
5763
5639
  getPublicPathFromCompiler as getPublicPathFromCompiler3,
@@ -5801,7 +5677,7 @@ var init_InlineChunkHtmlPlugin = __esm({
5801
5677
  if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
5802
5678
  !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
5803
5679
  const prefix = addTrailingSlash2(
5804
- join10(publicPath, this.distPath[type] || "")
5680
+ join9(publicPath, this.distPath[type] || "")
5805
5681
  );
5806
5682
  return source.replace(
5807
5683
  /# sourceMappingURL=/,
@@ -5988,13 +5864,13 @@ var bundleAnalyzer_exports = {};
5988
5864
  __export(bundleAnalyzer_exports, {
5989
5865
  pluginBundleAnalyzer: () => pluginBundleAnalyzer
5990
5866
  });
5991
- import { isProd as isProd3 } from "@rsbuild/shared";
5867
+ import { isProd as isProd4 } from "@rsbuild/shared";
5992
5868
  function pluginBundleAnalyzer() {
5993
5869
  return {
5994
5870
  name: "rsbuild:bundle-analyzer",
5995
5871
  setup(api) {
5996
5872
  api.modifyRsbuildConfig((config) => {
5997
- if (isProd3() || !isUseAnalyzer(config)) {
5873
+ if (isProd4() || !isUseAnalyzer(config)) {
5998
5874
  return;
5999
5875
  }
6000
5876
  config.dev ||= {};
@@ -6237,8 +6113,7 @@ __export(HtmlPreloadOrPrefetchPlugin_exports, {
6237
6113
  });
6238
6114
  import {
6239
6115
  getPublicPathFromCompiler as getPublicPathFromCompiler4,
6240
- upperFirst as upperFirst2,
6241
- withPublicPath as withPublicPath3
6116
+ upperFirst as upperFirst2
6242
6117
  } from "@rsbuild/shared";
6243
6118
  function filterResourceHints(resourceHints, scripts) {
6244
6119
  return resourceHints.filter(
@@ -6285,7 +6160,7 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
6285
6160
  const publicPath = getPublicPathFromCompiler4(compilation.compiler);
6286
6161
  const { crossOriginLoading } = compilation.compiler.options.output;
6287
6162
  for (const file of sortedFilteredFiles) {
6288
- const href = withPublicPath3(file, publicPath);
6163
+ const href = ensureAssetPrefix(file, publicPath);
6289
6164
  const attributes = {
6290
6165
  href,
6291
6166
  rel: type
@@ -6318,6 +6193,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6318
6193
  "src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
6319
6194
  "use strict";
6320
6195
  init_esm();
6196
+ init_helpers();
6321
6197
  init_pluginHelper();
6322
6198
  init_helpers2();
6323
6199
  defaultOptions = {
@@ -6483,35 +6359,37 @@ var server_exports = {};
6483
6359
  __export(server_exports, {
6484
6360
  pluginServer: () => pluginServer
6485
6361
  });
6486
- import { isAbsolute as isAbsolute7, join as join11 } from "path";
6362
+ import { isAbsolute as isAbsolute7, join as join10 } from "path";
6487
6363
  import { fse as fse7 } from "@rsbuild/shared";
6488
6364
  var pluginServer;
6489
6365
  var init_server = __esm({
6490
6366
  "src/plugins/server.ts"() {
6491
6367
  "use strict";
6492
6368
  init_esm();
6369
+ init_config();
6493
6370
  pluginServer = () => ({
6494
6371
  name: "rsbuild:server",
6495
6372
  setup(api) {
6496
6373
  api.onBeforeBuild(async () => {
6497
6374
  const config = api.getNormalizedConfig();
6498
- if (config.server?.publicDir) {
6499
- const { name, copyOnBuild } = config.server.publicDir;
6375
+ const publicDirs = normalizePublicDirs(config.server.publicDir);
6376
+ for (const publicDir of publicDirs) {
6377
+ const { name, copyOnBuild } = publicDir;
6500
6378
  if (!copyOnBuild || !name) {
6501
- return;
6379
+ continue;
6502
6380
  }
6503
- const publicDir = isAbsolute7(name) ? name : join11(api.context.rootPath, name);
6504
- if (!fse7.existsSync(publicDir)) {
6505
- return;
6381
+ const normalizedPath = isAbsolute7(name) ? name : join10(api.context.rootPath, name);
6382
+ if (!fse7.existsSync(normalizedPath)) {
6383
+ continue;
6506
6384
  }
6507
6385
  try {
6508
- await fse7.copy(publicDir, api.context.distPath, {
6386
+ await fse7.copy(normalizedPath, api.context.distPath, {
6509
6387
  // dereference symlinks
6510
6388
  dereference: true
6511
6389
  });
6512
6390
  } catch (err) {
6513
6391
  if (err instanceof Error) {
6514
- err.message = `Copy public dir (${publicDir}) to dist failed:
6392
+ err.message = `Copy public dir (${normalizedPath}) to dist failed:
6515
6393
  ${err.message}`;
6516
6394
  }
6517
6395
  throw err;
@@ -6853,8 +6731,8 @@ var init_lazyCompilation = __esm({
6853
6731
  pluginLazyCompilation = () => ({
6854
6732
  name: "rsbuild:lazy-compilation",
6855
6733
  setup(api) {
6856
- api.modifyBundlerChain((chain, { isProd: isProd5, target }) => {
6857
- if (isProd5 || target !== "web") {
6734
+ api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
6735
+ if (isProd6 || target !== "web") {
6858
6736
  return;
6859
6737
  }
6860
6738
  const config = api.getNormalizedConfig();
@@ -6920,7 +6798,7 @@ __export(sri_exports, {
6920
6798
  import crypto2 from "crypto";
6921
6799
  import {
6922
6800
  isHtmlDisabled as isHtmlDisabled4,
6923
- isProd as isProd4,
6801
+ isProd as isProd5,
6924
6802
  logger as logger16,
6925
6803
  removeLeadingSlash as removeLeadingSlash2
6926
6804
  } from "@rsbuild/shared";
@@ -6943,7 +6821,7 @@ var init_sri = __esm({
6943
6821
  const getAlgorithm = () => {
6944
6822
  const config = api.getNormalizedConfig();
6945
6823
  const { sri } = config.security;
6946
- const enable = sri.enable === "auto" ? isProd4() : sri.enable;
6824
+ const enable = sri.enable === "auto" ? isProd5() : sri.enable;
6947
6825
  if (!enable) {
6948
6826
  return null;
6949
6827
  }
@@ -7135,13 +7013,193 @@ var init_nonce = __esm({
7135
7013
  }
7136
7014
  });
7137
7015
 
7016
+ // src/server/prodServer.ts
7017
+ var prodServer_exports = {};
7018
+ __export(prodServer_exports, {
7019
+ RsbuildProdServer: () => RsbuildProdServer,
7020
+ startProdServer: () => startProdServer
7021
+ });
7022
+ import { join as join11 } from "path";
7023
+ import {
7024
+ getNodeEnv as getNodeEnv8,
7025
+ isDebug as isDebug5,
7026
+ setNodeEnv as setNodeEnv4
7027
+ } from "@rsbuild/shared";
7028
+ async function startProdServer(context, config, { getPortSilently } = {}) {
7029
+ if (!getNodeEnv8()) {
7030
+ setNodeEnv4("production");
7031
+ }
7032
+ const { port, host, https } = await getServerConfig({
7033
+ config,
7034
+ getPortSilently
7035
+ });
7036
+ const { default: connect } = await import("../compiled/connect/index.js");
7037
+ const middlewares = connect();
7038
+ const serverConfig = config.server;
7039
+ const server = new RsbuildProdServer(
7040
+ {
7041
+ pwd: context.rootPath,
7042
+ output: {
7043
+ path: config.output.distPath.root || ROOT_DIST_DIR,
7044
+ assetPrefix: config.output.assetPrefix
7045
+ },
7046
+ serverConfig
7047
+ },
7048
+ middlewares
7049
+ );
7050
+ await context.hooks.onBeforeStartProdServer.call();
7051
+ const httpServer = await createHttpServer({
7052
+ serverConfig,
7053
+ middlewares: server.middlewares
7054
+ });
7055
+ await server.onInit(httpServer);
7056
+ return new Promise((resolve) => {
7057
+ httpServer.listen(
7058
+ {
7059
+ host,
7060
+ port
7061
+ },
7062
+ async () => {
7063
+ const routes = formatRoutes(
7064
+ context.entry,
7065
+ config.output.distPath.html,
7066
+ config.html.outputStructure
7067
+ );
7068
+ await context.hooks.onAfterStartProdServer.call({
7069
+ port,
7070
+ routes
7071
+ });
7072
+ const protocol = https ? "https" : "http";
7073
+ const urls = getAddressUrls({ protocol, port, host });
7074
+ printServerURLs({
7075
+ urls,
7076
+ port,
7077
+ routes,
7078
+ protocol,
7079
+ printUrls: serverConfig.printUrls
7080
+ });
7081
+ const onClose = () => {
7082
+ server.close();
7083
+ httpServer.close();
7084
+ };
7085
+ resolve({
7086
+ port,
7087
+ urls: urls.map((item) => item.url),
7088
+ server: {
7089
+ close: async () => {
7090
+ onClose();
7091
+ }
7092
+ }
7093
+ });
7094
+ }
7095
+ );
7096
+ });
7097
+ }
7098
+ var RsbuildProdServer;
7099
+ var init_prodServer = __esm({
7100
+ "src/server/prodServer.ts"() {
7101
+ "use strict";
7102
+ init_esm();
7103
+ init_constants();
7104
+ init_helper();
7105
+ init_httpServer();
7106
+ init_middlewares();
7107
+ RsbuildProdServer = class {
7108
+ constructor(options, middlewares) {
7109
+ __publicField(this, "app");
7110
+ __publicField(this, "options");
7111
+ __publicField(this, "middlewares");
7112
+ this.options = options;
7113
+ this.middlewares = middlewares;
7114
+ }
7115
+ // Complete the preparation of services
7116
+ async onInit(app) {
7117
+ this.app = app;
7118
+ await this.applyDefaultMiddlewares();
7119
+ }
7120
+ async applyDefaultMiddlewares() {
7121
+ const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
7122
+ if (isDebug5()) {
7123
+ this.middlewares.use(await getRequestLoggerMiddleware());
7124
+ }
7125
+ if (compress) {
7126
+ const { default: compression } = await import("../compiled/http-compression/index.js");
7127
+ this.middlewares.use((req, res, next) => {
7128
+ compression({
7129
+ gzip: true,
7130
+ brotli: false
7131
+ })(req, res, next);
7132
+ });
7133
+ }
7134
+ if (headers) {
7135
+ this.middlewares.use((_req, res, next) => {
7136
+ for (const [key, value] of Object.entries(headers)) {
7137
+ res.setHeader(key, value);
7138
+ }
7139
+ next();
7140
+ });
7141
+ }
7142
+ if (proxy) {
7143
+ const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
7144
+ const { middlewares, upgrade } = createProxyMiddleware2(proxy);
7145
+ for (const middleware of middlewares) {
7146
+ this.middlewares.use(middleware);
7147
+ }
7148
+ this.app.on("upgrade", upgrade);
7149
+ }
7150
+ this.applyStaticAssetMiddleware();
7151
+ if (historyApiFallback) {
7152
+ const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
7153
+ const historyApiFallbackMiddleware = connectHistoryApiFallback(
7154
+ historyApiFallback === true ? {} : historyApiFallback
7155
+ );
7156
+ this.middlewares.use(historyApiFallbackMiddleware);
7157
+ await this.applyStaticAssetMiddleware();
7158
+ }
7159
+ this.middlewares.use(faviconFallbackMiddleware);
7160
+ }
7161
+ async applyStaticAssetMiddleware() {
7162
+ const {
7163
+ output: { path: path14, assetPrefix },
7164
+ serverConfig: { htmlFallback },
7165
+ pwd
7166
+ } = this.options;
7167
+ const { default: sirv } = await import("../compiled/sirv/index.js");
7168
+ const assetMiddleware = sirv(join11(pwd, path14), {
7169
+ etag: true,
7170
+ dev: true,
7171
+ ignores: ["favicon.ico"],
7172
+ single: htmlFallback === "index"
7173
+ });
7174
+ this.middlewares.use((req, res, next) => {
7175
+ const url2 = req.url;
7176
+ if (assetPrefix && url2?.startsWith(assetPrefix)) {
7177
+ req.url = url2.slice(assetPrefix.length);
7178
+ assetMiddleware(req, res, (...args) => {
7179
+ req.url = url2;
7180
+ next(...args);
7181
+ });
7182
+ } else {
7183
+ assetMiddleware(req, res, next);
7184
+ }
7185
+ });
7186
+ }
7187
+ close() {
7188
+ }
7189
+ };
7190
+ }
7191
+ });
7192
+
7138
7193
  // src/createRsbuild.ts
7139
7194
  var createRsbuild_exports = {};
7140
7195
  __export(createRsbuild_exports, {
7141
7196
  createRsbuild: () => createRsbuild,
7142
7197
  pickRsbuildConfig: () => pickRsbuildConfig
7143
7198
  });
7144
- import { debug as debug8, pick as pick2 } from "@rsbuild/shared";
7199
+ import {
7200
+ debug as debug8,
7201
+ pick as pick2
7202
+ } from "@rsbuild/shared";
7145
7203
  async function applyDefaultPlugins(pluginManager, context) {
7146
7204
  const { pluginBasic: pluginBasic2 } = await Promise.resolve().then(() => (init_basic(), basic_exports));
7147
7205
  const { pluginEntry: pluginEntry2 } = await Promise.resolve().then(() => (init_entry(), entry_exports));
@@ -7241,6 +7299,11 @@ async function createRsbuild(options = {}) {
7241
7299
  rsbuildOptions,
7242
7300
  setCssExtractPlugin
7243
7301
  });
7302
+ const preview = async (options2) => {
7303
+ const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
7304
+ const config = await initRsbuildConfig({ context, pluginManager });
7305
+ return startProdServer2(context, config, options2);
7306
+ };
7244
7307
  const rsbuild = {
7245
7308
  ...pick2(pluginManager, [
7246
7309
  "addPlugins",
@@ -7266,13 +7329,13 @@ async function createRsbuild(options = {}) {
7266
7329
  ]),
7267
7330
  ...pick2(providerInstance, [
7268
7331
  "build",
7269
- "preview",
7270
7332
  "initConfigs",
7271
7333
  "inspectConfig",
7272
7334
  "createCompiler",
7273
7335
  "createDevServer",
7274
7336
  "startDevServer"
7275
7337
  ]),
7338
+ preview,
7276
7339
  context: pluginAPI.context
7277
7340
  };
7278
7341
  if (rsbuildConfig.plugins) {
@@ -7288,6 +7351,7 @@ var init_createRsbuild = __esm({
7288
7351
  init_esm();
7289
7352
  init_createContext();
7290
7353
  init_initPlugins();
7354
+ init_internal();
7291
7355
  init_pluginHelper();
7292
7356
  init_pluginManager();
7293
7357
  getRspackProvider = async () => {
@@ -7385,56 +7449,13 @@ var init_init = __esm({
7385
7449
  }
7386
7450
  });
7387
7451
 
7388
- // src/index.ts
7389
- init_esm();
7390
- import { rspack as rspack10 } from "@rspack/core";
7391
-
7392
- // src/internal.ts
7393
- var internal_exports = {};
7394
- __export(internal_exports, {
7395
- applySwcDecoratorConfig: () => applySwcDecoratorConfig,
7396
- createDevServer: () => createDevServer,
7397
- createPluginManager: () => createPluginManager,
7398
- formatStats: () => formatStats,
7399
- getChainUtils: () => getChainUtils,
7400
- getDevMiddleware: () => getDevMiddleware,
7401
- getHTMLPlugin: () => getHTMLPlugin,
7402
- getStatsOptions: () => getStatsOptions,
7403
- getSwcMinimizerOptions: () => getSwcMinimizerOptions,
7404
- initHooks: () => initHooks,
7405
- initPlugins: () => initPlugins,
7406
- initRsbuildConfig: () => initRsbuildConfig,
7407
- outputInspectConfigFiles: () => outputInspectConfigFiles,
7408
- prepareCli: () => prepareCli,
7409
- runCli: () => runCli,
7410
- setHTMLPlugin: () => setHTMLPlugin,
7411
- startProdServer: () => startProdServer,
7412
- stringifyConfig: () => stringifyConfig
7413
- });
7414
- init_esm();
7415
-
7416
7452
  // src/cli/commands.ts
7417
- init_esm();
7418
- init_helpers();
7419
- init_init();
7420
7453
  import { existsSync } from "fs";
7421
7454
  import { join as join12 } from "path";
7422
7455
  import { color as color13, logger as logger18 } from "@rsbuild/shared";
7423
7456
  import { program } from "../compiled/commander/index.js";
7424
- var applyCommonOptions = (command) => {
7425
- command.option(
7426
- "-c --config <config>",
7427
- "specify the configuration file, can be a relative or absolute path"
7428
- ).option(
7429
- "--env-mode <mode>",
7430
- "specify the env mode to load the `.env.[mode]` file"
7431
- );
7432
- };
7433
- var applyServerOptions = (command) => {
7434
- 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");
7435
- };
7436
7457
  function runCli() {
7437
- program.name("rsbuild").usage("<command> [options]").version("0.7.6");
7458
+ program.name("rsbuild").usage("<command> [options]").version("0.7.8");
7438
7459
  const devCommand = program.command("dev");
7439
7460
  const buildCommand = program.command("build");
7440
7461
  const previewCommand = program.command("preview");
@@ -7509,9 +7530,29 @@ function runCli() {
7509
7530
  });
7510
7531
  program.parse();
7511
7532
  }
7533
+ var applyCommonOptions, applyServerOptions;
7534
+ var init_commands = __esm({
7535
+ "src/cli/commands.ts"() {
7536
+ "use strict";
7537
+ init_esm();
7538
+ init_helpers();
7539
+ init_init();
7540
+ applyCommonOptions = (command) => {
7541
+ command.option(
7542
+ "-c --config <config>",
7543
+ "specify the configuration file, can be a relative or absolute path"
7544
+ ).option(
7545
+ "--env-mode <mode>",
7546
+ "specify the env mode to load the `.env.[mode]` file"
7547
+ );
7548
+ };
7549
+ applyServerOptions = (command) => {
7550
+ 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");
7551
+ };
7552
+ }
7553
+ });
7512
7554
 
7513
7555
  // src/cli/prepare.ts
7514
- init_esm();
7515
7556
  import { logger as logger19 } from "@rsbuild/shared";
7516
7557
  function initNodeEnv() {
7517
7558
  if (!process.env.NODE_ENV) {
@@ -7525,41 +7566,76 @@ function prepareCli() {
7525
7566
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7526
7567
  console.log();
7527
7568
  }
7528
- logger19.greet(` ${`Rsbuild v${"0.7.6"}`}
7569
+ logger19.greet(` ${`Rsbuild v${"0.7.8"}`}
7529
7570
  `);
7530
7571
  }
7572
+ var init_prepare = __esm({
7573
+ "src/cli/prepare.ts"() {
7574
+ "use strict";
7575
+ init_esm();
7576
+ }
7577
+ });
7531
7578
 
7532
7579
  // src/internal.ts
7533
- init_pluginManager();
7534
- init_initHooks();
7535
- init_initConfigs();
7536
- init_config();
7537
- init_pluginHelper();
7538
- init_helpers();
7539
- init_rspackConfig();
7540
- init_swc();
7541
- init_minimize();
7542
- init_devMiddleware();
7543
-
7544
- // src/server/index.ts
7545
- init_esm();
7546
- init_devServer();
7547
- init_prodServer();
7580
+ var internal_exports = {};
7581
+ __export(internal_exports, {
7582
+ applySwcDecoratorConfig: () => applySwcDecoratorConfig,
7583
+ createDevServer: () => createDevServer,
7584
+ createPluginManager: () => createPluginManager,
7585
+ formatStats: () => formatStats,
7586
+ getChainUtils: () => getChainUtils,
7587
+ getDevMiddleware: () => getDevMiddleware,
7588
+ getHTMLPlugin: () => getHTMLPlugin,
7589
+ getStatsOptions: () => getStatsOptions,
7590
+ getSwcMinimizerOptions: () => getSwcMinimizerOptions,
7591
+ initHooks: () => initHooks,
7592
+ initPlugins: () => initPlugins,
7593
+ initRsbuildConfig: () => initRsbuildConfig,
7594
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
7595
+ prepareCli: () => prepareCli,
7596
+ runCli: () => runCli,
7597
+ setHTMLPlugin: () => setHTMLPlugin,
7598
+ stringifyConfig: () => stringifyConfig
7599
+ });
7600
+ var init_internal = __esm({
7601
+ "src/internal.ts"() {
7602
+ "use strict";
7603
+ init_esm();
7604
+ init_commands();
7605
+ init_prepare();
7606
+ init_pluginManager();
7607
+ init_initHooks();
7608
+ init_initConfigs();
7609
+ init_config();
7610
+ init_pluginHelper();
7611
+ init_helpers();
7612
+ init_rspackConfig();
7613
+ init_swc();
7614
+ init_minimize();
7615
+ init_devMiddleware();
7616
+ init_devServer();
7617
+ }
7618
+ });
7548
7619
 
7549
7620
  // src/index.ts
7621
+ init_esm();
7622
+ init_internal();
7550
7623
  init_loadEnv();
7551
7624
  init_createRsbuild();
7552
7625
  init_config();
7553
7626
  init_mergeConfig();
7627
+ init_helpers();
7554
7628
  init_constants();
7629
+ import { rspack as rspack10 } from "@rspack/core";
7555
7630
  import { logger as logger20 } from "@rsbuild/shared";
7556
- var version = "0.7.6";
7631
+ var version = "0.7.8";
7557
7632
  export {
7558
7633
  PLUGIN_CSS_NAME,
7559
7634
  PLUGIN_SWC_NAME,
7560
7635
  internal_exports as __internalHelper,
7561
7636
  createRsbuild,
7562
7637
  defineConfig,
7638
+ ensureAssetPrefix,
7563
7639
  loadConfig,
7564
7640
  loadEnv,
7565
7641
  logger20 as logger,