@rsbuild/core 1.6.5 → 1.6.7

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.
@@ -1,4 +1,4 @@
1
- import { registerOverlay } from "./hmr";
1
+ import { registerOverlay } from "./hmr.js";
2
2
  function _define_property(obj, key, value) {
3
3
  if (key in obj) Object.defineProperty(obj, key, {
4
4
  value: value,
@@ -9,8 +9,8 @@ function _define_property(obj, key, value) {
9
9
  else obj[key] = value;
10
10
  return obj;
11
11
  }
12
- const { HTMLElement = class {
13
- }, customElements } = 'undefined' != typeof window ? window : globalThis;
12
+ const { HTMLElement: HTMLElement = class {
13
+ }, customElements: customElements } = 'undefined' != typeof window ? window : globalThis;
14
14
  class ErrorOverlay extends HTMLElement {
15
15
  constructor(html){
16
16
  var _root_querySelector, _root_querySelector1;
@@ -1,4 +1,3 @@
1
- let loader_ignoreCssLoader = function(source) {
1
+ export default function(source) {
2
2
  return (this?.cacheable(!0), source.includes('___CSS_LOADER_EXPORT___')) ? '' : source;
3
- };
4
- export { loader_ignoreCssLoader as default };
3
+ }
package/dist/index.cjs CHANGED
@@ -3039,7 +3039,7 @@ ${section.body}` : section.body).join("\n\n"));
3039
3039
  onAfterEnvironmentCompile: createEnvironmentAsyncHook()
3040
3040
  };
3041
3041
  }
3042
- let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isWatch })=>{
3042
+ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompile, isWatch })=>{
3043
3043
  let name = 'rsbuild:beforeCompile';
3044
3044
  if (compiler_isMultiCompiler(compiler)) {
3045
3045
  let waitBeforeCompileDone, { compilers } = compiler;
@@ -3049,11 +3049,11 @@ ${section.body}` : section.body).join("\n\n"));
3049
3049
  for(let index = 0; index < compilers.length; index++){
3050
3050
  let compiler = compilers[index];
3051
3051
  (isWatch ? compiler.hooks.watchRun : compiler.hooks.run).tapPromise(name, async ()=>{
3052
- waitBeforeCompileDone || (waitBeforeCompileDone = beforeCompile?.()), await waitBeforeCompileDone, await beforeEnvironmentCompiler(index);
3052
+ waitBeforeCompileDone || (waitBeforeCompileDone = beforeCompile()), await waitBeforeCompileDone, await beforeEnvironmentCompile(index);
3053
3053
  });
3054
3054
  }
3055
3055
  } else (isWatch ? compiler.hooks.watchRun : compiler.hooks.run).tapPromise(name, async ()=>{
3056
- await beforeCompile?.(), await beforeEnvironmentCompiler(0);
3056
+ await beforeCompile(), await beforeEnvironmentCompile(0);
3057
3057
  });
3058
3058
  }, onCompileDone = ({ compiler, onDone, onEnvironmentDone, MultiStatsCtor })=>{
3059
3059
  if (compiler_isMultiCompiler(compiler)) {
@@ -3073,13 +3073,13 @@ ${section.body}` : section.body).join("\n\n"));
3073
3073
  });
3074
3074
  }, registerBuildHook = ({ context, isWatch, compiler, bundlerConfigs, MultiStatsCtor })=>{
3075
3075
  let isFirstCompile = !0, { environmentList } = context, onDone = async (stats)=>{
3076
- let p = context.hooks.onAfterBuild.callBatch({
3076
+ let promise = context.hooks.onAfterBuild.callBatch({
3077
3077
  isFirstCompile,
3078
3078
  stats,
3079
3079
  environments: context.environments,
3080
3080
  isWatch
3081
3081
  });
3082
- isFirstCompile = !1, await p;
3082
+ isFirstCompile = !1, await promise;
3083
3083
  }, onEnvironmentDone = async (buildIndex, stats)=>{
3084
3084
  await context.hooks.onAfterEnvironmentCompile.callBatch({
3085
3085
  environment: environmentList[buildIndex].name,
@@ -3101,17 +3101,20 @@ ${section.body}` : section.body).join("\n\n"));
3101
3101
  isWatch,
3102
3102
  isFirstCompile
3103
3103
  }),
3104
- beforeEnvironmentCompiler: async (buildIndex)=>context.hooks.onBeforeEnvironmentCompile.callBatch({
3105
- environment: environmentList[buildIndex].name,
3104
+ beforeEnvironmentCompile: async (buildIndex)=>{
3105
+ let environment = environmentList[buildIndex];
3106
+ return context.hooks.onBeforeEnvironmentCompile.callBatch({
3107
+ environment: environment.name,
3106
3108
  args: [
3107
3109
  {
3108
- bundlerConfig: bundlerConfigs?.[buildIndex],
3109
- environment: environmentList[buildIndex],
3110
+ bundlerConfig: bundlerConfigs[buildIndex],
3111
+ environment,
3110
3112
  isWatch,
3111
3113
  isFirstCompile
3112
3114
  }
3113
3115
  ]
3114
- }),
3116
+ });
3117
+ },
3115
3118
  isWatch
3116
3119
  }), onCompileDone({
3117
3120
  compiler,
@@ -3121,12 +3124,12 @@ ${section.body}` : section.body).join("\n\n"));
3121
3124
  });
3122
3125
  }, registerDevHook = ({ context, compiler, bundlerConfigs, MultiStatsCtor })=>{
3123
3126
  let isFirstCompile = !0, { environmentList } = context, onDone = async (stats)=>{
3124
- let p = context.hooks.onAfterDevCompile.callBatch({
3127
+ let promise = context.hooks.onAfterDevCompile.callBatch({
3125
3128
  isFirstCompile,
3126
3129
  stats,
3127
3130
  environments: context.environments
3128
3131
  });
3129
- isFirstCompile = !1, await p;
3132
+ isFirstCompile = !1, await promise;
3130
3133
  }, onEnvironmentDone = async (buildIndex, stats)=>{
3131
3134
  await context.hooks.onAfterEnvironmentCompile.callBatch({
3132
3135
  environment: environmentList[buildIndex].name,
@@ -3142,17 +3145,20 @@ ${section.body}` : section.body).join("\n\n"));
3142
3145
  };
3143
3146
  onBeforeCompile({
3144
3147
  compiler,
3145
- beforeEnvironmentCompiler: async (buildIndex)=>context.hooks.onBeforeEnvironmentCompile.callBatch({
3146
- environment: environmentList[buildIndex].name,
3148
+ beforeEnvironmentCompile: async (buildIndex)=>{
3149
+ let environment = environmentList[buildIndex];
3150
+ return context.hooks.onBeforeEnvironmentCompile.callBatch({
3151
+ environment: environment.name,
3147
3152
  args: [
3148
3153
  {
3149
- bundlerConfig: bundlerConfigs?.[buildIndex],
3150
- environment: environmentList[buildIndex],
3154
+ bundlerConfig: bundlerConfigs[buildIndex],
3155
+ environment,
3151
3156
  isWatch: !0,
3152
3157
  isFirstCompile
3153
3158
  }
3154
3159
  ]
3155
- }),
3160
+ });
3161
+ },
3156
3162
  beforeCompile: async ()=>context.hooks.onBeforeDevCompile.callBatch({
3157
3163
  bundlerConfigs,
3158
3164
  environments: context.environments,
@@ -3796,7 +3802,7 @@ ${section.body}` : section.body).join("\n\n"));
3796
3802
  exitHook_callbacks.delete(onExit);
3797
3803
  };
3798
3804
  }
3799
- let addTrailingSlash = (s)=>s.endsWith('/') ? s : `${s}/`, isURL = (str)=>str.startsWith('http') || str.startsWith('//:'), urlJoin = (base, path)=>{
3805
+ let addTrailingSlash = (s)=>s.endsWith('/') ? s : `${s}/`, isURL = (str)=>str.startsWith('http') || str.startsWith('//'), urlJoin = (base, path)=>{
3800
3806
  let [urlProtocol, baseUrl] = base.split('://');
3801
3807
  return `${urlProtocol}://${external_node_path_.posix.join(baseUrl, path)}`;
3802
3808
  }, canParse = (url)=>{
@@ -4221,7 +4227,7 @@ ${section.body}` : section.body).join("\n\n"));
4221
4227
  async function createContext(options, userConfig) {
4222
4228
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
4223
4229
  return {
4224
- version: "1.6.5",
4230
+ version: "1.6.7",
4225
4231
  rootPath,
4226
4232
  distPath: '',
4227
4233
  cachePath,
@@ -4813,7 +4819,7 @@ ${section.body}` : section.body).join("\n\n"));
4813
4819
  }
4814
4820
  let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
4815
4821
  let compiler, bundlerConfigs, { context } = initOptions;
4816
- if (customCompiler) compiler = customCompiler;
4822
+ if (customCompiler) compiler = customCompiler, bundlerConfigs = customCompiler.options;
4817
4823
  else {
4818
4824
  let result = await createCompiler_createCompiler(initOptions);
4819
4825
  compiler = result.compiler, bundlerConfigs = result.rspackConfigs;
@@ -4906,8 +4912,13 @@ ${section.body}` : section.body).join("\n\n"));
4906
4912
  }).set('generator', generatorOptions);
4907
4913
  };
4908
4914
  function getRegExpForExts(exts) {
4909
- let matcher = exts.map((ext)=>ext.trim()).map((ext)=>ext.startsWith('.') ? ext.slice(1) : ext).join('|');
4910
- return RegExp(1 === exts.length ? `\\.${matcher}$` : `\\.(?:${matcher})$`, 'i');
4915
+ let normalizedExts = [];
4916
+ for (let ext of exts){
4917
+ let trimmed = ext.trim();
4918
+ normalizedExts.push(trimmed.startsWith('.') ? trimmed.slice(1) : trimmed);
4919
+ }
4920
+ let matcher = normalizedExts.join('|');
4921
+ return RegExp(1 === normalizedExts.length ? `\\.${matcher}$` : `\\.(?:${matcher})$`, 'i');
4911
4922
  }
4912
4923
  let isUseAnalyzer = (config)=>process.env.BUNDLE_ANALYZE || config.performance?.bundleAnalyze;
4913
4924
  function pluginBundleAnalyzer() {
@@ -4961,7 +4972,7 @@ ${section.body}` : section.body).join("\n\n"));
4961
4972
  function getCacheDirectory({ cacheDirectory }, context) {
4962
4973
  return cacheDirectory ? (0, external_node_path_.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_.join)(context.rootPath, cacheDirectory) : (0, external_node_path_.join)(context.cachePath, context.bundlerType);
4963
4974
  }
4964
- async function getBuildDependencies(context, config, environmentContext, userBuildDependencies) {
4975
+ async function getBuildDependencies(context, config, environmentContext, additionalDependencies) {
4965
4976
  let rootPackageJson = (0, external_node_path_.join)(context.rootPath, 'package.json'), browserslistConfig = (0, external_node_path_.join)(context.rootPath, '.browserslistrc'), buildDependencies = {};
4966
4977
  await isFileExists(rootPackageJson) && (buildDependencies.packageJson = [
4967
4978
  rootPackageJson
@@ -4982,10 +4993,7 @@ ${section.body}` : section.body).join("\n\n"));
4982
4993
  ].map((ext)=>(0, external_node_path_.join)(context.rootPath, `tailwind.config.${ext}`)));
4983
4994
  return tailwindConfig && (buildDependencies.tailwindcss = [
4984
4995
  tailwindConfig
4985
- ]), {
4986
- ...buildDependencies,
4987
- ...userBuildDependencies
4988
- };
4996
+ ]), additionalDependencies && (buildDependencies.additional = additionalDependencies), buildDependencies;
4989
4997
  }
4990
4998
  let addTrailingSep = (dir)=>dir.endsWith(external_node_path_.sep) ? dir : dir + external_node_path_.sep, isStrictSubdir = (parent, child)=>{
4991
4999
  let parentDir = addTrailingSep(parent), childDir = addTrailingSep(child);
@@ -5789,37 +5797,6 @@ ${section.body}` : section.body).join("\n\n"));
5789
5797
  ...manifest
5790
5798
  };
5791
5799
  }
5792
- class PatchSplitChunksPlugin {
5793
- name;
5794
- constructor(name){
5795
- this.name = name;
5796
- }
5797
- apply(compiler) {
5798
- let { splitChunks } = compiler.options.optimization;
5799
- if (!splitChunks) return;
5800
- let applyPatch = (config)=>{
5801
- if ('object' != typeof config || (0, types_namespaceObject.isRegExp)(config)) return;
5802
- let { chunks } = config;
5803
- if (chunks && 'async' !== chunks) {
5804
- if ('function' == typeof chunks) {
5805
- config.chunks = (chunk)=>(!chunk.name || chunk.name !== this.name) && chunks(chunk);
5806
- return;
5807
- }
5808
- if ('all' === chunks) {
5809
- config.chunks = (chunk)=>!chunk.name || chunk.name !== this.name;
5810
- return;
5811
- }
5812
- if ('initial' === chunks) {
5813
- config.chunks = (chunk)=>(!chunk.name || chunk.name !== this.name) && chunk.isOnlyInitial();
5814
- return;
5815
- }
5816
- }
5817
- };
5818
- applyPatch(splitChunks);
5819
- let { cacheGroups } = splitChunks;
5820
- if (cacheGroups) for (let cacheGroupKey of Object.keys(cacheGroups))cacheGroups[cacheGroupKey] && applyPatch(cacheGroups[cacheGroupKey]);
5821
- }
5822
- }
5823
5800
  function pluginModuleFederation() {
5824
5801
  return {
5825
5802
  name: 'rsbuild:module-federation',
@@ -5844,9 +5821,7 @@ ${section.body}` : section.body).join("\n\n"));
5844
5821
  let { options } = config.moduleFederation;
5845
5822
  chain.plugin(CHAIN_ID.PLUGIN.MODULE_FEDERATION).use(rspack_rspack.container.ModuleFederationPlugin, [
5846
5823
  options
5847
- ]), options.name && (options.exposes && chain.plugin('mf-patch-split-chunks').use(PatchSplitChunksPlugin, [
5848
- options.name
5849
- ]), chain.output.get('uniqueName') || chain.output.set('uniqueName', options.name));
5824
+ ]), options.name && !chain.output.get('uniqueName') && chain.output.set('uniqueName', options.name);
5850
5825
  }));
5851
5826
  }
5852
5827
  };
@@ -8332,8 +8307,16 @@ ${section.body}` : section.body).join("\n\n"));
8332
8307
  };
8333
8308
  preEntry.forEach(addEntry), injectCoreJsEntry && addEntry(createVirtualModule('import "core-js";')), helpers_castArray(entry[entryName]).forEach(addEntry);
8334
8309
  }
8335
- }), api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
8336
- if (bundlerConfigs.every((config)=>!config.entry)) throw Error(`${color.dim('[rsbuild:config]')} Could not find any entry module, please make sure that ${color.yellow('src/index.(ts|js|tsx|jsx|mts|cts|mjs|cjs)')} exists, or customize entry through the ${color.yellow('source.entry')} configuration.`);
8310
+ }), api.onBeforeCreateCompiler({
8311
+ order: 'post',
8312
+ handler: ({ bundlerConfigs })=>{
8313
+ if (bundlerConfigs.some((config)=>config.entry)) return;
8314
+ let isModuleFederationPlugin = (plugin)=>isObject(plugin) && 'ModuleFederationPlugin' === plugin.constructor.name;
8315
+ if (bundlerConfigs.some(({ plugins })=>plugins?.some(isModuleFederationPlugin))) return void bundlerConfigs.forEach((config)=>{
8316
+ config.entry = {};
8317
+ });
8318
+ throw Error(`${color.dim('[rsbuild:config]')} Could not find any entry module, please make sure that ${color.yellow('src/index.(ts|js|tsx|jsx|mts|cts|mjs|cjs)')} exists, or customize entry through the ${color.yellow('source.entry')} configuration.`);
8319
+ }
8337
8320
  });
8338
8321
  }
8339
8322
  },
@@ -8384,9 +8367,7 @@ ${section.body}` : section.body).join("\n\n"));
8384
8367
  let { config } = environment, { bundlerType } = api.context, buildCache = config.performance.buildCache ?? 'webpack' === bundlerType;
8385
8368
  if (!1 === buildCache) return;
8386
8369
  cacheEnabled = !0;
8387
- let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment, cacheConfig.buildDependencies ? {
8388
- userBuildDependencies: cacheConfig.buildDependencies
8389
- } : {});
8370
+ let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment, cacheConfig.buildDependencies);
8390
8371
  'webpack' === bundlerType && await validateWebpackCache(cacheDirectory, buildDependencies);
8391
8372
  let cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${await helpers_hash(JSON.stringify(cacheConfig.cacheDigest))}` : `${environment.name}-${env}`;
8392
8373
  'rspack' === bundlerType ? (chain.cache(!0), chain.experiments({
@@ -9135,7 +9116,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9135
9116
  api.modifyBundlerChain((chain, { environment, target })=>{
9136
9117
  let { config } = environment;
9137
9118
  if (config.output.module) {
9138
- if ('web' === target && chain.optimization.runtimeChunk(!0), 'node' === target && chain.output.library({
9119
+ if ('node' === target && chain.output.library({
9139
9120
  ...chain.output.get('library'),
9140
9121
  type: 'module'
9141
9122
  }), 'web-worker' === target) throw Error('[rsbuild:config] `output.module` is not supported for web-worker target.');
@@ -9868,7 +9849,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9868
9849
  };
9869
9850
  function setupCommands() {
9870
9851
  let cli = ((name = "")=>new CAC(name))('rsbuild');
9871
- cli.version("1.6.5"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
9852
+ cli.version("1.6.7"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
9872
9853
  default: 'auto'
9873
9854
  }).option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
9874
9855
  type: [
@@ -9937,7 +9918,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9937
9918
  }
9938
9919
  function showGreeting() {
9939
9920
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
9940
- logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.6.5\n`);
9921
+ logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.6.7\n`);
9941
9922
  }
9942
9923
  function setupLogLevel() {
9943
9924
  let logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
@@ -9958,7 +9939,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9958
9939
  logger.error('Failed to start Rsbuild CLI.'), logger.error(err);
9959
9940
  }
9960
9941
  }
9961
- let src_version = "1.6.5";
9942
+ let src_version = "1.6.7";
9962
9943
  })(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, exports.defaultAllowedOrigins = __webpack_exports__.defaultAllowedOrigins, exports.defineConfig = __webpack_exports__.defineConfig, exports.ensureAssetPrefix = __webpack_exports__.ensureAssetPrefix, exports.loadConfig = __webpack_exports__.loadConfig, exports.loadEnv = __webpack_exports__.loadEnv, exports.logger = __webpack_exports__.logger, exports.mergeRsbuildConfig = __webpack_exports__.mergeRsbuildConfig, exports.rspack = __webpack_exports__.rspack, exports.runCLI = __webpack_exports__.runCLI, exports.version = __webpack_exports__.version, __webpack_exports__)-1 === [
9963
9944
  "PLUGIN_CSS_NAME",
9964
9945
  "PLUGIN_SWC_NAME",