@rsbuild/core 1.1.3 → 1.1.5

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
@@ -1,6 +1,4 @@
1
1
  let pluginHelper_htmlPlugin, cssExtractPlugin, swcHelpersPath;
2
- import { fileURLToPath as __webpack_fileURLToPath__ } from "url";
3
- import { dirname as __webpack_dirname__ } from "path";
4
2
  import * as __WEBPACK_EXTERNAL_MODULE_crypto__ from "crypto";
5
3
  import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
6
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_child_process__ from "node:child_process";
@@ -13,6 +11,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
13
11
  import * as __WEBPACK_EXTERNAL_MODULE__rspack_core__ from "@rspack/core";
14
12
  import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
15
13
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__ from "../compiled/picocolors/index.js";
14
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
16
15
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__ from "../compiled/rslog/index.js";
17
16
  import * as __WEBPACK_EXTERNAL_MODULE_node_util_types__ from "node:util/types";
18
17
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_rspack_chain_index_js__ from "../compiled/rspack-chain/index.js";
@@ -20,7 +19,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_util__ from "node:util";
20
19
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_mrmime_index_js__ from "../compiled/mrmime/index.js";
21
20
  import * as __WEBPACK_EXTERNAL_MODULE_node_crypto__ from "node:crypto";
22
21
  import * as __WEBPACK_EXTERNAL_MODULE_node_zlib__ from "node:zlib";
23
- import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
24
22
  import * as __WEBPACK_EXTERNAL_MODULE_node_net__ from "node:net";
25
23
  import * as __WEBPACK_EXTERNAL_MODULE_node_os__ from "node:os";
26
24
  import * as __WEBPACK_EXTERNAL_MODULE_node_inspector__ from "node:inspector";
@@ -1398,8 +1396,8 @@ let pluginHelper_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createReq
1398
1396
  }, getHTMLPlugin = ()=>(!pluginHelper_htmlPlugin && (pluginHelper_htmlPlugin = pluginHelper_require('../compiled/html-rspack-plugin/index.js')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
1399
1397
  cssExtractPlugin = plugin;
1400
1398
  }, getCssExtractPlugin = ()=>cssExtractPlugin ? cssExtractPlugin : __WEBPACK_EXTERNAL_MODULE__rspack_core__.default.CssExtractRspackPlugin;
1401
- var external_node_fs_ = __webpack_require__("node:fs"), external_node_path_ = __webpack_require__("node:path"), main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js"), lib_main = __webpack_require__("../../node_modules/.pnpm/dotenv-expand@11.0.7/node_modules/dotenv-expand/lib/main.js"), cjs = __webpack_require__("../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"), cjs_default = __webpack_require__.n(cjs), constants_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
1402
- let ROOT_DIST_DIR = 'dist', LOADER_PATH = (0, external_node_path_.join)(constants_dirname), STATIC_PATH = (0, external_node_path_.join)(constants_dirname, '../static'), COMPILED_PATH = (0, external_node_path_.join)(constants_dirname, '../compiled'), RSBUILD_OUTPUTS_PATH = '.rsbuild', DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_ASSET_PREFIX = '/', DEFAULT_WEB_BROWSERSLIST = [
1399
+ var external_node_fs_ = __webpack_require__("node:fs"), external_node_path_ = __webpack_require__("node:path"), main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js"), lib_main = __webpack_require__("../../node_modules/.pnpm/dotenv-expand@11.0.7/node_modules/dotenv-expand/lib/main.js"), cjs = __webpack_require__("../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"), cjs_default = __webpack_require__.n(cjs);
1400
+ let constants_filename = (0, __WEBPACK_EXTERNAL_MODULE_node_url__.fileURLToPath)(import.meta.url), constants_dirname = (0, external_node_path_.dirname)(constants_filename), ROOT_DIST_DIR = 'dist', LOADER_PATH = (0, external_node_path_.join)(constants_dirname), STATIC_PATH = (0, external_node_path_.join)(constants_dirname, '../static'), COMPILED_PATH = (0, external_node_path_.join)(constants_dirname, '../compiled'), RSBUILD_OUTPUTS_PATH = '.rsbuild', DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_ASSET_PREFIX = '/', DEFAULT_WEB_BROWSERSLIST = [
1403
1401
  'chrome >= 87',
1404
1402
  'edge >= 88',
1405
1403
  'firefox >= 78',
@@ -1988,7 +1986,6 @@ async function startWatchFiles({ paths, options, type = 'reload-page' }, compile
1988
1986
  compileMiddlewareAPI.sockWrite('static-changed');
1989
1987
  }), watcher;
1990
1988
  }
1991
- var config_filename = __webpack_fileURLToPath__(import.meta.url);
1992
1989
  let config_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url), getDefaultDevConfig = ()=>({
1993
1990
  hmr: !0,
1994
1991
  liveReload: !0,
@@ -2168,7 +2165,7 @@ async function watchFilesForRestart(files, root, isBuildWatch, watchOptions) {
2168
2165
  });
2169
2166
  watcher.on('add', callback), watcher.on('change', callback), watcher.on('unlink', callback);
2170
2167
  }
2171
- async function config_loadConfig({ cwd = process.cwd(), path, envMode } = {}) {
2168
+ async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta } = {}) {
2172
2169
  let configExport;
2173
2170
  let configFilePath = resolveConfigPath(cwd, path);
2174
2171
  if (!configFilePath) return {
@@ -2187,7 +2184,7 @@ async function config_loadConfig({ cwd = process.cwd(), path, envMode } = {}) {
2187
2184
  try {
2188
2185
  if (void 0 === configExport) {
2189
2186
  let { default: jiti } = await import("../compiled/jiti/index.js");
2190
- configExport = jiti(config_filename, {
2187
+ configExport = jiti(constants_filename, {
2191
2188
  esmResolve: !0,
2192
2189
  requireCache: !1,
2193
2190
  interopDefault: !0
@@ -2200,7 +2197,8 @@ async function config_loadConfig({ cwd = process.cwd(), path, envMode } = {}) {
2200
2197
  let command = process.argv[2], nodeEnv = getNodeEnv(), result = await configExport({
2201
2198
  env: nodeEnv,
2202
2199
  command,
2203
- envMode: envMode || nodeEnv
2200
+ envMode: envMode || nodeEnv,
2201
+ meta
2204
2202
  });
2205
2203
  if (void 0 === result) throw Error('The config function must return a config object.');
2206
2204
  return {
@@ -2633,7 +2631,7 @@ async function updateEnvironmentContext(context, configs) {
2633
2631
  async function createContext(options, userConfig, bundlerType) {
2634
2632
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache');
2635
2633
  return {
2636
- version: "1.1.3",
2634
+ version: "1.1.5",
2637
2635
  rootPath,
2638
2636
  distPath: '',
2639
2637
  cachePath,
@@ -2816,8 +2814,8 @@ let pluginAppIcon = ()=>({
2816
2814
  });
2817
2815
  }
2818
2816
  }), getJsSourceMap = (config)=>{
2819
- let { sourceMap } = config.output;
2820
- return void 0 === sourceMap.js ? 'production' !== config.mode && 'cheap-module-source-map' : sourceMap.js;
2817
+ let { sourceMap } = config.output, isProd = 'production' === config.mode;
2818
+ return !1 !== sourceMap && (!0 === sourceMap ? isProd ? 'source-map' : 'cheap-module-source-map' : void 0 === sourceMap.js ? !isProd && 'cheap-module-source-map' : sourceMap.js);
2821
2819
  }, pluginBasic = ()=>({
2822
2820
  name: 'rsbuild:basic',
2823
2821
  setup (api) {
@@ -2920,27 +2918,26 @@ let pluginCache = ()=>({
2920
2918
  });
2921
2919
  }), api.onBeforeStartDevServer(cleanAll);
2922
2920
  }
2923
- });
2924
- var dist_isNil = (o)=>null == o, dist_isFunction = (func)=>"function" == typeof func, dist_isObject = (obj)=>null !== obj && "object" == typeof obj, dist_isPlainObject = (obj)=>dist_isObject(obj) && "[object Object]" === Object.prototype.toString.call(obj);
2921
+ }), dist_isNil = (o)=>null == o, dist_isFunction = (func)=>'function' == typeof func, dist_isObject = (obj)=>null !== obj && 'object' == typeof obj, dist_isPlainObject = (obj)=>dist_isObject(obj) && '[object Object]' === Object.prototype.toString.call(obj);
2925
2922
  function reduceConfigs({ initial, config, mergeFn = Object.assign }) {
2926
- return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? config(initial) ?? initial : Array.isArray(config) ? config.reduce((initial2, config2)=>reduceConfigs({
2927
- initial: initial2,
2928
- config: config2,
2923
+ return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? config(initial) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigs({
2924
+ initial,
2925
+ config,
2929
2926
  mergeFn
2930
2927
  }), initial) : config ?? initial;
2931
2928
  }
2932
2929
  function reduceConfigsWithContext({ initial, config, ctx, mergeFn = Object.assign }) {
2933
- return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? config(initial, ctx) ?? initial : Array.isArray(config) ? config.reduce((initial2, config2)=>reduceConfigsWithContext({
2934
- initial: initial2,
2935
- config: config2,
2930
+ return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? config(initial, ctx) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigsWithContext({
2931
+ initial,
2932
+ config,
2936
2933
  ctx,
2937
2934
  mergeFn
2938
2935
  }), initial) : config ?? initial;
2939
2936
  }
2940
2937
  async function reduceConfigsAsyncWithContext({ initial, config, ctx, mergeFn = Object.assign }) {
2941
- return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? await config(initial, ctx) ?? initial : Array.isArray(config) ? config.reduce((initial2, config2)=>reduceConfigsWithContext({
2942
- initial: initial2,
2943
- config: config2,
2938
+ return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? await config(initial, ctx) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigsWithContext({
2939
+ initial,
2940
+ config,
2944
2941
  ctx,
2945
2942
  mergeFn
2946
2943
  }), initial) : config ?? initial;
@@ -2949,9 +2946,9 @@ function reduceConfigsMergeContext({ initial, config, ctx, mergeFn = Object.assi
2949
2946
  return dist_isNil(config) ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : dist_isFunction(config) ? config({
2950
2947
  value: initial,
2951
2948
  ...ctx
2952
- }) ?? initial : Array.isArray(config) ? config.reduce((initial2, config2)=>reduceConfigsMergeContext({
2953
- initial: initial2,
2954
- config: config2,
2949
+ }) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigsMergeContext({
2950
+ initial,
2951
+ config,
2955
2952
  ctx,
2956
2953
  mergeFn
2957
2954
  }), initial) : config ?? initial;
@@ -2978,7 +2975,10 @@ let getCSSModulesLocalIdentName = (config, isProd)=>config.output.cssModules.loc
2978
2975
  plugins: config.plugins ? [
2979
2976
  ...config.plugins
2980
2977
  ] : void 0
2981
- });
2978
+ }), getCSSSourceMap = (config)=>{
2979
+ let { sourceMap } = config.output;
2980
+ return 'boolean' == typeof sourceMap ? sourceMap : sourceMap.css;
2981
+ };
2982
2982
  async function loadUserPostcssrc(root) {
2983
2983
  let cached = userPostcssrcCache.get(root);
2984
2984
  if (cached) return clonePostCSSConfig(await cached);
@@ -2996,7 +2996,7 @@ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plu
2996
2996
  initial: {
2997
2997
  implementation: getCompiledPath('postcss'),
2998
2998
  postcssOptions: userOptions,
2999
- sourceMap: config.output.sourceMap.css
2999
+ sourceMap: getCSSSourceMap(config)
3000
3000
  },
3001
3001
  config: config.tools.postcss,
3002
3002
  ctx: {
@@ -3035,67 +3035,61 @@ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plu
3035
3035
  ...cssModules,
3036
3036
  localIdentName
3037
3037
  },
3038
- sourceMap: config.output.sourceMap.css
3038
+ sourceMap: getCSSSourceMap(config)
3039
3039
  },
3040
3040
  config: config.tools.cssLoader,
3041
3041
  mergeFn: cjs_default()
3042
3042
  }), !emitCss);
3043
- };
3044
- async function applyCSSRule({ rule, config, context, utils: { target, isProd, CHAIN_ID, environment } }) {
3045
- let emitCss = config.output.emitCss ?? 'web' === target;
3046
- if (emitCss) {
3047
- if (config.output.injectStyles) {
3048
- let styleLoaderOptions = reduceConfigs({
3049
- initial: {},
3050
- config: config.tools.styleLoader
3051
- });
3052
- rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
3053
- } else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions);
3054
- } else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_.default.join(LOADER_PATH, 'ignoreCssLoader.cjs'));
3055
- let importLoaders = 0;
3056
- if (rule.use(CHAIN_ID.USE.CSS).loader(getCompiledPath('css-loader')), emitCss) {
3057
- var _postcssLoaderOptions_postcssOptions_plugins, _postcssLoaderOptions_postcssOptions;
3058
- if ('rspack' === context.bundlerType && !1 !== config.tools.lightningcssLoader) {
3059
- importLoaders++;
3060
- let userOptions = !0 === config.tools.lightningcssLoader ? {} : config.tools.lightningcssLoader, initialOptions = {
3061
- targets: environment.browserslist
3062
- };
3063
- 'production' === config.mode && config.output.injectStyles && (initialOptions.minify = !0);
3064
- let loaderOptions = reduceConfigs({
3065
- initial: initialOptions,
3066
- config: userOptions
3067
- });
3068
- rule.use(CHAIN_ID.USE.LIGHTNINGCSS).loader('builtin:lightningcss-loader').options(loaderOptions);
3069
- }
3070
- let postcssLoaderOptions = await getPostcssLoaderOptions({
3071
- config,
3072
- root: context.rootPath
3073
- });
3074
- ('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) && (importLoaders++, rule.use(CHAIN_ID.USE.POSTCSS).loader(getCompiledPath('postcss-loader')).options(postcssLoaderOptions));
3075
- }
3076
- let localIdentName = getCSSModulesLocalIdentName(config, isProd), cssLoaderOptions = getCSSLoaderOptions({
3077
- config,
3078
- importLoaders,
3079
- localIdentName,
3080
- emitCss
3081
- });
3082
- rule.use(CHAIN_ID.USE.CSS).options(cssLoaderOptions), rule.merge({
3083
- sideEffects: !0
3084
- }), rule.resolve.preferRelative(!0);
3085
- }
3086
- let pluginCss = ()=>({
3043
+ }, pluginCss = ()=>({
3087
3044
  name: 'rsbuild:css',
3088
3045
  setup (api) {
3089
3046
  api.modifyBundlerChain({
3090
3047
  order: 'pre',
3091
- handler: async (chain, utils)=>{
3092
- let rule = chain.module.rule(utils.CHAIN_ID.RULE.CSS), { config } = utils.environment;
3093
- rule.test(CSS_REGEX).type('javascript/auto'), await applyCSSRule({
3094
- rule,
3095
- utils,
3048
+ handler: async (chain, { target, isProd, CHAIN_ID, environment })=>{
3049
+ let rule = chain.module.rule(CHAIN_ID.RULE.CSS), { config } = environment;
3050
+ rule.test(CSS_REGEX).type('javascript/auto').dependency({
3051
+ not: 'url'
3052
+ });
3053
+ let emitCss = config.output.emitCss ?? 'web' === target;
3054
+ if (emitCss) {
3055
+ if (config.output.injectStyles) {
3056
+ let styleLoaderOptions = reduceConfigs({
3057
+ initial: {},
3058
+ config: config.tools.styleLoader
3059
+ });
3060
+ rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
3061
+ } else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions);
3062
+ } else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_.default.join(LOADER_PATH, 'ignoreCssLoader.mjs'));
3063
+ let importLoaders = 0;
3064
+ if (rule.use(CHAIN_ID.USE.CSS).loader(getCompiledPath('css-loader')), emitCss) {
3065
+ var _postcssLoaderOptions_postcssOptions_plugins, _postcssLoaderOptions_postcssOptions;
3066
+ if ('rspack' === api.context.bundlerType && !1 !== config.tools.lightningcssLoader) {
3067
+ importLoaders++;
3068
+ let userOptions = !0 === config.tools.lightningcssLoader ? {} : config.tools.lightningcssLoader, initialOptions = {
3069
+ targets: environment.browserslist
3070
+ };
3071
+ 'production' === config.mode && config.output.injectStyles && (initialOptions.minify = !0);
3072
+ let loaderOptions = reduceConfigs({
3073
+ initial: initialOptions,
3074
+ config: userOptions
3075
+ });
3076
+ rule.use(CHAIN_ID.USE.LIGHTNINGCSS).loader('builtin:lightningcss-loader').options(loaderOptions);
3077
+ }
3078
+ let postcssLoaderOptions = await getPostcssLoaderOptions({
3079
+ config,
3080
+ root: api.context.rootPath
3081
+ });
3082
+ ('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) && (importLoaders++, rule.use(CHAIN_ID.USE.POSTCSS).loader(getCompiledPath('postcss-loader')).options(postcssLoaderOptions));
3083
+ }
3084
+ let localIdentName = getCSSModulesLocalIdentName(config, isProd), cssLoaderOptions = getCSSLoaderOptions({
3096
3085
  config,
3097
- context: api.context
3086
+ importLoaders,
3087
+ localIdentName,
3088
+ emitCss
3098
3089
  });
3090
+ rule.use(CHAIN_ID.USE.CSS).options(cssLoaderOptions), rule.merge({
3091
+ sideEffects: !0
3092
+ }), rule.resolve.preferRelative(!0);
3099
3093
  }
3100
3094
  });
3101
3095
  }
@@ -3142,7 +3136,7 @@ let pluginCss = ()=>({
3142
3136
  async function gzipSize(input) {
3143
3137
  return (await fileSize_gzip(input)).length;
3144
3138
  }
3145
- let filterAsset = (asset)=>!/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset), getAssetColor = (size)=>size > 300000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.red : size > 100000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.yellow : __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.green, calcFileSize = (len)=>{
3139
+ let excludeAsset = (asset)=>/\.(?:map|LICENSE\.txt)$/.test(asset.name), getAssetColor = (size)=>size > 300000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.red : size > 100000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.yellow : __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.green, calcFileSize = (len)=>{
3146
3140
  let val = len / 1000;
3147
3141
  return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
3148
3142
  }, coloringAssetName = (assetName)=>JS_REGEX.test(assetName) ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.cyan(assetName) : CSS_REGEX.test(assetName) ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.yellow(assetName) : HTML_REGEX.test(assetName) ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.green(assetName) : __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__.default.magenta(assetName);
@@ -3162,7 +3156,7 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
3162
3156
  }, getAssets = async ()=>{
3163
3157
  let distPath = stats.compilation.outputOptions.path;
3164
3158
  if (!distPath) return [];
3165
- let filteredAssets = stats.toJson({
3159
+ let origin = stats.toJson({
3166
3160
  all: !1,
3167
3161
  assets: !0,
3168
3162
  cachedAssets: !0,
@@ -3171,7 +3165,13 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
3171
3165
  groupAssetsByChunk: !1,
3172
3166
  groupAssetsByExtension: !1,
3173
3167
  groupAssetsByEmitStatus: !1
3174
- }).assets.filter((asset)=>filterAsset(asset.name)), distFolder = external_node_path_.default.relative(rootPath, distPath);
3168
+ }), exclude = options.exclude ?? excludeAsset, filteredAssets = origin.assets.filter((asset)=>{
3169
+ let assetInfo = {
3170
+ name: asset.name,
3171
+ size: asset.size
3172
+ };
3173
+ return !exclude(assetInfo) && (!options.include || options.include(assetInfo));
3174
+ }), distFolder = external_node_path_.default.relative(rootPath, distPath);
3175
3175
  return Promise.all(filteredAssets.map((asset)=>formatAsset(asset, distPath, distFolder)));
3176
3176
  }, assets = await getAssets();
3177
3177
  if (0 === assets.length) return logs;
@@ -3901,7 +3901,7 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (inp
3901
3901
  let trailingSlashBase = addTrailingSlash(base);
3902
3902
  return path.startsWith(trailingSlashBase) ? path.slice(trailingSlashBase.length - 1) : path;
3903
3903
  }, getRoutes = (context)=>Object.values(context.environments).reduce((prev, environmentContext)=>{
3904
- let { distPath, config } = environmentContext, distPrefix = external_node_path_.posix.relative(context.distPath, distPath), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, external_node_path_.posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
3904
+ let { distPath, config } = environmentContext, distPrefix = (0, external_node_path_.relative)(context.distPath, distPath).split(external_node_path_.sep).join('/'), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, external_node_path_.posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
3905
3905
  return prev.concat(...routes);
3906
3906
  }, []), formatRoutes = (entry, base, distPathPrefix, outputStructure)=>{
3907
3907
  let prefix = joinUrlSegments(base, formatPrefix(distPathPrefix));
@@ -4721,7 +4721,9 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
4721
4721
  order: 'pre',
4722
4722
  handler: async (chain, { CHAIN_ID, isDev, target, environment })=>{
4723
4723
  var browserslist, target1;
4724
- let { config, browserslist: browserslist1 } = environment, cacheRoot = external_node_path_.default.join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).type('javascript/auto'), dataUriRule = chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
4724
+ let { config, browserslist: browserslist1 } = environment, cacheRoot = external_node_path_.default.join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).type('javascript/auto').dependency({
4725
+ not: 'url'
4726
+ }), dataUriRule = chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
4725
4727
  or: [
4726
4728
  'text/javascript',
4727
4729
  'application/javascript'
@@ -5395,6 +5397,7 @@ class SocketServer {
5395
5397
  errorDetails: !1,
5396
5398
  entrypoints: !0,
5397
5399
  children: !0,
5400
+ moduleTrace: !0,
5398
5401
  ...statsOptions
5399
5402
  });
5400
5403
  }
@@ -5457,7 +5460,7 @@ let compilerDevMiddleware_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.
5457
5460
  let { writeToDisk } = config;
5458
5461
  return compilationName && environments[compilationName] && (writeToDisk = environments[compilationName].config.dev.writeToDisk ?? writeToDisk), 'function' == typeof writeToDisk ? writeToDisk(filePath) : writeToDisk;
5459
5462
  }
5460
- }, noop = ()=>{};
5463
+ };
5461
5464
  class CompilerDevMiddleware {
5462
5465
  async init() {
5463
5466
  let devMiddleware = await getDevMiddleware(this.compiler);
@@ -5466,9 +5469,16 @@ class CompilerDevMiddleware {
5466
5469
  upgrade(req, sock, head) {
5467
5470
  this.socketServer.upgrade(req, sock, head);
5468
5471
  }
5469
- close() {
5470
- var _this_middleware;
5471
- this.socketServer.close(), null === (_this_middleware = this.middleware) || void 0 === _this_middleware || _this_middleware.close(noop);
5472
+ async close() {
5473
+ this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
5474
+ this.middleware.close(()=>{
5475
+ resolve();
5476
+ });
5477
+ }), await new Promise((resolve)=>{
5478
+ this.compiler.close(()=>{
5479
+ resolve();
5480
+ });
5481
+ });
5472
5482
  }
5473
5483
  sockWrite(type, data) {
5474
5484
  this.socketServer.sockWrite({
@@ -6006,7 +6016,7 @@ let run = async (bundlePath, outputPath, compilerOptions, readFileSync)=>new Bas
6006
6016
  });
6007
6017
  return middlewares.push(...after), {
6008
6018
  close: async ()=>{
6009
- null == compileMiddlewareAPI || compileMiddlewareAPI.close();
6019
+ await (null == compileMiddlewareAPI ? void 0 : compileMiddlewareAPI.close());
6010
6020
  },
6011
6021
  onUpgrade,
6012
6022
  middlewares
@@ -6196,6 +6206,7 @@ async function createCompiler_createCompiler(options) {
6196
6206
  let done = (stats)=>{
6197
6207
  let statsOptions = getStatsOptions(compiler), statsJson = stats.toJson({
6198
6208
  children: !0,
6209
+ moduleTrace: !0,
6199
6210
  timings: !0,
6200
6211
  preset: 'errors-warnings',
6201
6212
  ...statsOptions
@@ -6698,7 +6709,7 @@ async function createRsbuild(options = {}) {
6698
6709
  if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environment.name)) return;
6699
6710
  let rule = chain.module.rule(id);
6700
6711
  descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer);
6701
- let loaderName = descriptor.raw ? 'transformRawLoader.cjs' : 'transformLoader.cjs', loaderPath = (0, external_node_path_.join)(LOADER_PATH, loaderName);
6712
+ let loaderName = descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs', loaderPath = (0, external_node_path_.join)(LOADER_PATH, loaderName);
6702
6713
  rule.use(id).loader(loaderPath).options({
6703
6714
  id,
6704
6715
  getEnvironment: ()=>environment
@@ -6871,11 +6882,11 @@ async function runCLI() {
6871
6882
  }
6872
6883
  }();
6873
6884
  let { npm_execpath } = process.env;
6874
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rsbuild v1.1.3\n`);
6885
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rsbuild v1.1.5\n`);
6875
6886
  }();
6876
6887
  try {
6877
6888
  !function() {
6878
- program.name('rsbuild').usage('<command> [options]').version("1.1.3");
6889
+ program.name('rsbuild').usage('<command> [options]').version("1.1.5");
6879
6890
  let devCommand = program.command('dev'), buildCommand = program.command('build'), previewCommand = program.command('preview'), inspectCommand = program.command('inspect');
6880
6891
  [
6881
6892
  devCommand,
@@ -6934,6 +6945,6 @@ async function runCLI() {
6934
6945
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to start Rsbuild CLI.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
6935
6946
  }
6936
6947
  }
6937
- let src_version = "1.1.3";
6948
+ let src_version = "1.1.5";
6938
6949
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core__.rspack;
6939
6950
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, internal_namespaceObject as __internalHelper, createRsbuild, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
@@ -0,0 +1,21 @@
1
+ async function transformLoader_rslib_entry_transform(source, map) {
2
+ var _this__compiler___rsbuildTransformer, _this__compiler;
3
+ let callback = this.async(), bypass = ()=>callback(null, source, map), { id: transformId, getEnvironment } = this.getOptions();
4
+ if (!transformId) return bypass();
5
+ let transform = null === (_this__compiler = this._compiler) || void 0 === _this__compiler ? void 0 : null === (_this__compiler___rsbuildTransformer = _this__compiler.__rsbuildTransformer) || void 0 === _this__compiler___rsbuildTransformer ? void 0 : _this__compiler___rsbuildTransformer[transformId];
6
+ if (!transform) return bypass();
7
+ let result = await transform({
8
+ code: source,
9
+ resource: this.resource,
10
+ resourcePath: this.resourcePath,
11
+ resourceQuery: this.resourceQuery,
12
+ environment: getEnvironment(),
13
+ addDependency: this.addDependency,
14
+ emitFile: this.emitFile
15
+ });
16
+ if (null == result) return bypass();
17
+ if ('string' == typeof result) return callback(null, result, map);
18
+ let useMap = null != map, finalMap = result.map ?? map;
19
+ callback(null, result.code, useMap ? finalMap : void 0);
20
+ }
21
+ export { transformLoader_rslib_entry_transform as default };
@@ -0,0 +1,21 @@
1
+ let transformRawLoader_rslib_entry_ = async function transformLoader_transform(source, map) {
2
+ var _this__compiler___rsbuildTransformer, _this__compiler;
3
+ let callback = this.async(), bypass = ()=>callback(null, source, map), { id: transformId, getEnvironment } = this.getOptions();
4
+ if (!transformId) return bypass();
5
+ let transform = null === (_this__compiler = this._compiler) || void 0 === _this__compiler ? void 0 : null === (_this__compiler___rsbuildTransformer = _this__compiler.__rsbuildTransformer) || void 0 === _this__compiler___rsbuildTransformer ? void 0 : _this__compiler___rsbuildTransformer[transformId];
6
+ if (!transform) return bypass();
7
+ let result = await transform({
8
+ code: source,
9
+ resource: this.resource,
10
+ resourcePath: this.resourcePath,
11
+ resourceQuery: this.resourceQuery,
12
+ environment: getEnvironment(),
13
+ addDependency: this.addDependency,
14
+ emitFile: this.emitFile
15
+ });
16
+ if (null == result) return bypass();
17
+ if ('string' == typeof result) return callback(null, result, map);
18
+ let useMap = null != map, finalMap = result.map ?? map;
19
+ callback(null, result.code, useMap ? finalMap : void 0);
20
+ }, raw = !0;
21
+ export { transformRawLoader_rslib_entry_ as default, raw };
@@ -12,6 +12,7 @@ export type ConfigParams = {
12
12
  env: string;
13
13
  command: string;
14
14
  envMode?: string;
15
+ meta?: Record<string, unknown>;
15
16
  };
16
17
  export type RsbuildConfigAsyncFn = (env: ConfigParams) => Promise<RsbuildConfig>;
17
18
  export type RsbuildConfigSyncFn = (env: ConfigParams) => RsbuildConfig;
@@ -25,14 +26,39 @@ export declare function defineConfig(config: RsbuildConfigSyncFn): RsbuildConfig
25
26
  export declare function defineConfig(config: RsbuildConfigAsyncFn): RsbuildConfigAsyncFn;
26
27
  export declare function defineConfig(config: RsbuildConfigExport): RsbuildConfigExport;
27
28
  export declare function watchFilesForRestart(files: string[], root: string, isBuildWatch: boolean, watchOptions?: ChokidarOptions): Promise<void>;
28
- export declare function loadConfig({ cwd, path, envMode, }?: {
29
+ export type LoadConfigOptions = {
30
+ /**
31
+ * The root path to resolve the config file.
32
+ * @default process.cwd()
33
+ */
29
34
  cwd?: string;
35
+ /**
36
+ * The path to the config file, can be a relative or absolute path.
37
+ * If `path` is not provided, the function will search for the config file in the `cwd`.
38
+ */
30
39
  path?: string;
40
+ /**
41
+ * A custom meta object to be passed into the config function of `defineConfig`.
42
+ */
43
+ meta?: Record<string, unknown>;
44
+ /**
45
+ * The `envMode` passed into the config function of `defineConfig`.
46
+ * @default process.env.NODE_ENV
47
+ */
31
48
  envMode?: string;
32
- }): Promise<{
49
+ };
50
+ export type LoadConfigResult = {
51
+ /**
52
+ * The loaded configuration object.
53
+ */
33
54
  content: RsbuildConfig;
55
+ /**
56
+ * The path to the loaded configuration file.
57
+ * Return `null` if the configuration file is not found.
58
+ */
34
59
  filePath: string | null;
35
- }>;
60
+ };
61
+ export declare function loadConfig({ cwd, path, envMode, meta, }?: LoadConfigOptions): Promise<LoadConfigResult>;
36
62
  export declare const getRsbuildInspectConfig: ({ normalizedConfig, inspectOptions, pluginManager, }: {
37
63
  normalizedConfig: NormalizedConfig;
38
64
  inspectOptions: InspectConfigOptions;
@@ -1,3 +1,5 @@
1
+ export declare const __filename: string;
2
+ export declare const __dirname: string;
1
3
  export declare const ROOT_DIST_DIR = "dist";
2
4
  export declare const HTML_DIST_DIR = "./";
3
5
  export declare const JS_DIST_DIR = "static/js";
@@ -7,7 +7,7 @@ import type * as Rspack from '@rspack/core';
7
7
  import * as __internalHelper from './internal';
8
8
  export { loadEnv } from './loadEnv';
9
9
  export { createRsbuild } from './createRsbuild';
10
- export { loadConfig, defineConfig } from './config';
10
+ export { loadConfig, defineConfig, type LoadConfigOptions, type LoadConfigResult, } from './config';
11
11
  export { runCLI } from './cli';
12
12
  export declare const version: string;
13
13
  export { rspack };
@@ -1,4 +1,4 @@
1
- import type { RsbuildPlugin } from '../types';
2
- /** Filter source map and license files */
3
- export declare const filterAsset: (asset: string) => boolean;
1
+ import type { PrintFileSizeAsset, RsbuildPlugin } from '../types';
2
+ /** Exclude source map and license files by default */
3
+ export declare const excludeAsset: (asset: PrintFileSizeAsset) => boolean;
4
4
  export declare const pluginFileSize: () => RsbuildPlugin;
@@ -24,7 +24,7 @@ export declare class CompilerDevMiddleware {
24
24
  constructor({ dev, server, compiler, publicPaths, environments }: Options);
25
25
  init(): Promise<void>;
26
26
  upgrade(req: IncomingMessage, sock: Socket, head: any): void;
27
- close(): void;
27
+ close(): Promise<void>;
28
28
  sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
29
29
  private setupDevMiddleware;
30
30
  }
@@ -4,7 +4,7 @@ export type CompileMiddlewareAPI = {
4
4
  middleware: RequestHandler;
5
5
  sockWrite: SetupMiddlewaresServer['sockWrite'];
6
6
  onUpgrade: UpgradeEvent;
7
- close: () => void;
7
+ close: () => Promise<void>;
8
8
  };
9
9
  export type RsbuildDevMiddlewareOptions = {
10
10
  pwd: string;
@@ -310,10 +310,47 @@ export type BuildCacheOptions = {
310
310
  cacheDirectory?: string;
311
311
  cacheDigest?: Array<string | undefined>;
312
312
  };
313
+ export type PrintFileSizeAsset = {
314
+ /**
315
+ * The name of the asset.
316
+ * @example 'index.html', 'static/js/index.[hash].js'
317
+ */
318
+ name: string;
319
+ /**
320
+ * The size of the asset in bytes.
321
+ */
322
+ size: number;
323
+ };
313
324
  export type PrintFileSizeOptions = {
325
+ /**
326
+ * Whether to print the total size of all static assets.
327
+ * @default true
328
+ */
314
329
  total?: boolean;
330
+ /**
331
+ * Whether to print the size of each static asset.
332
+ * @default true
333
+ */
315
334
  detail?: boolean;
335
+ /**
336
+ * Whether to print the gzip-compressed size of each static asset.
337
+ * Disable this option can save some gzip computation time for large projects.
338
+ * @default true
339
+ */
316
340
  compressed?: boolean;
341
+ /**
342
+ * A filter function to determine which static assets to print.
343
+ * If returned `false`, the static asset will be excluded and not included in the
344
+ * total size or detailed size.
345
+ * @default undefined
346
+ */
347
+ include?: (asset: PrintFileSizeAsset) => boolean;
348
+ /**
349
+ * A filter function to exclude static assets from the total size or detailed size.
350
+ * If both `include` and `exclude` are set, `exclude` will take precedence.
351
+ * @default (asset) => /\.(?:map|LICENSE\.txt)$/.test(asset.name)
352
+ */
353
+ exclude?: (asset: PrintFileSizeAsset) => boolean;
317
354
  };
318
355
  export interface PreconnectOption {
319
356
  href: string;
@@ -721,7 +758,7 @@ export interface OutputConfig {
721
758
  * };
722
759
  * ```
723
760
  */
724
- sourceMap?: SourceMap;
761
+ sourceMap?: boolean | SourceMap;
725
762
  /**
726
763
  * Whether to add filename hash after production build.
727
764
  * @default true
@@ -774,7 +811,7 @@ export interface NormalizedOutputConfig extends OutputConfig {
774
811
  filename: FilenameConfig;
775
812
  distPath: Omit<Required<DistPathConfig>, 'jsAsync' | 'cssAsync' | 'js'> & Pick<DistPathConfig, 'jsAsync' | 'cssAsync' | 'js'>;
776
813
  polyfill: Polyfill;
777
- sourceMap: {
814
+ sourceMap: boolean | {
778
815
  js?: Rspack.Configuration['devtool'];
779
816
  css: boolean;
780
817
  };