@rsbuild/core 0.7.0-beta.4 → 0.7.0-beta.6

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.cjs CHANGED
@@ -35,6 +35,26 @@ var __publicField = (obj, key, value) => {
35
35
  return value;
36
36
  };
37
37
 
38
+ // src/constants.ts
39
+ var import_node_path, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, PLUGIN_LESS_NAME, PLUGIN_SASS_NAME, PLUGIN_STYLUS_NAME, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HTML_REGEX, CSS_REGEX;
40
+ var init_constants = __esm({
41
+ "src/constants.ts"() {
42
+ "use strict";
43
+ import_node_path = require("path");
44
+ PLUGIN_SWC_NAME = "rsbuild:swc";
45
+ PLUGIN_CSS_NAME = "rsbuild:css";
46
+ PLUGIN_LESS_NAME = "rsbuild:less";
47
+ PLUGIN_SASS_NAME = "rsbuild:sass";
48
+ PLUGIN_STYLUS_NAME = "rsbuild:stylus";
49
+ LOADER_PATH = (0, import_node_path.join)(__dirname);
50
+ STATIC_PATH = (0, import_node_path.join)(__dirname, "../static");
51
+ COMPILED_PATH = (0, import_node_path.join)(__dirname, "../compiled");
52
+ TS_CONFIG_FILE = "tsconfig.json";
53
+ HTML_REGEX = /\.html$/;
54
+ CSS_REGEX = /\.css$/;
55
+ }
56
+ });
57
+
38
58
  // src/client/format.ts
39
59
  function resolveFileName(stats) {
40
60
  if (stats.moduleIdentifier) {
@@ -87,23 +107,6 @@ var init_format = __esm({
87
107
  }
88
108
  });
89
109
 
90
- // src/constants.ts
91
- var import_node_path, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, PLUGIN_LESS_NAME, PLUGIN_SASS_NAME, PLUGIN_STYLUS_NAME, LOADER_PATH, STATIC_PATH, COMPILED_PATH;
92
- var init_constants = __esm({
93
- "src/constants.ts"() {
94
- "use strict";
95
- import_node_path = require("path");
96
- PLUGIN_SWC_NAME = "rsbuild:swc";
97
- PLUGIN_CSS_NAME = "rsbuild:css";
98
- PLUGIN_LESS_NAME = "rsbuild:less";
99
- PLUGIN_SASS_NAME = "rsbuild:sass";
100
- PLUGIN_STYLUS_NAME = "rsbuild:stylus";
101
- LOADER_PATH = (0, import_node_path.join)(__dirname);
102
- STATIC_PATH = (0, import_node_path.join)(__dirname, "../static");
103
- COMPILED_PATH = (0, import_node_path.join)(__dirname, "../compiled");
104
- }
105
- });
106
-
107
110
  // src/helpers.ts
108
111
  function formatErrorMessage(errors) {
109
112
  const messages = errors.map((error) => addNodePolyfillTip(error));
@@ -201,13 +204,7 @@ var init_helpers = __esm({
201
204
  }
202
205
  return true;
203
206
  };
204
- getCompiledPath = (packageName) => {
205
- const providerCompilerPath = import_node_path2.default.join(COMPILED_PATH, packageName);
206
- if (import_shared2.fse.existsSync(providerCompilerPath)) {
207
- return providerCompilerPath;
208
- }
209
- return (0, import_shared.getSharedPkgCompiledPath)(packageName);
210
- };
207
+ getCompiledPath = (packageName) => import_node_path2.default.join(COMPILED_PATH, packageName);
211
208
  addNodePolyfillTip = (message) => {
212
209
  if (!message.includes(`Can't resolve`)) {
213
210
  return message;
@@ -524,6 +521,7 @@ var init_config = __esm({
524
521
  import_node_fs = __toESM(require("fs"));
525
522
  import_node_path4 = require("path");
526
523
  import_shared5 = require("@rsbuild/shared");
524
+ init_constants();
527
525
  init_helpers();
528
526
  init_mergeConfig();
529
527
  init_restart();
@@ -576,7 +574,9 @@ var init_config = __esm({
576
574
  getDefaultToolsConfig = () => ({
577
575
  cssExtract: {
578
576
  loaderOptions: {},
579
- pluginOptions: {}
577
+ pluginOptions: {
578
+ ignoreOrder: true
579
+ }
580
580
  }
581
581
  });
582
582
  getDefaultPerformanceConfig = () => ({
@@ -627,6 +627,7 @@ var init_config = __esm({
627
627
  inlineStyles: false,
628
628
  cssModules: {
629
629
  auto: true,
630
+ exportGlobals: false,
630
631
  exportLocalsConvention: "camelCase"
631
632
  },
632
633
  emitAssets: () => true
@@ -648,7 +649,7 @@ var init_config = __esm({
648
649
  merged.source.entry = getDefaultEntry(rootPath);
649
650
  }
650
651
  if (!merged.source.tsconfigPath) {
651
- const tsconfigPath = (0, import_node_path4.join)(rootPath, import_shared5.TS_CONFIG_FILE);
652
+ const tsconfigPath = (0, import_node_path4.join)(rootPath, TS_CONFIG_FILE);
652
653
  if (await isFileExists(tsconfigPath)) {
653
654
  merged.source.tsconfigPath = tsconfigPath;
654
655
  }
@@ -816,9 +817,7 @@ function createPluginManager() {
816
817
  };
817
818
  const isPluginExists = (pluginName) => Boolean(plugins2.find((plugin) => plugin.name === pluginName));
818
819
  return {
819
- get plugins() {
820
- return plugins2;
821
- },
820
+ getPlugins: () => plugins2,
822
821
  addPlugins,
823
822
  removePlugins,
824
823
  isPluginExists
@@ -829,7 +828,7 @@ async function initPlugins({
829
828
  pluginManager
830
829
  }) {
831
830
  (0, import_shared7.debug)("init plugins");
832
- const plugins2 = pluginDagSort(pluginManager.plugins);
831
+ const plugins2 = pluginDagSort(pluginManager.getPlugins());
833
832
  const removedPlugins = plugins2.reduce((ret, plugin) => {
834
833
  if (plugin.remove) {
835
834
  return ret.concat(plugin.remove);
@@ -1044,7 +1043,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
1044
1043
  const context = {
1045
1044
  entry: getEntryObject(config, "web"),
1046
1045
  targets: config.output?.targets || [],
1047
- version: "0.7.0-beta.4",
1046
+ version: "0.7.0-beta.6",
1048
1047
  rootPath,
1049
1048
  distPath,
1050
1049
  cachePath,
@@ -1280,7 +1279,6 @@ var init_basic = __esm({
1280
1279
  level: "error"
1281
1280
  }
1282
1281
  });
1283
- chain.ignoreWarnings([/Conflicting order/]);
1284
1282
  chain.performance.hints(false);
1285
1283
  chain.module.parser.merge({
1286
1284
  javascript: {
@@ -2103,8 +2101,8 @@ async function applyCSSRule({
2103
2101
  target
2104
2102
  );
2105
2103
  const enableExtractCSS = isUseCssExtract(config, target);
2106
- const localIdentName = getCssModuleLocalIdentName(config, isProd4);
2107
- const cssLoaderOptions = getCssLoaderOptions({
2104
+ const localIdentName = getCSSModulesLocalIdentName(config, isProd4);
2105
+ const cssLoaderOptions = getCSSLoaderOptions({
2108
2106
  config,
2109
2107
  importLoaders,
2110
2108
  target,
@@ -2112,11 +2110,7 @@ async function applyCSSRule({
2112
2110
  });
2113
2111
  if (target === "web") {
2114
2112
  if (enableExtractCSS) {
2115
- const extraCSSOptions = typeof config.tools.cssExtract === "object" ? config.tools.cssExtract : {
2116
- loaderOptions: {},
2117
- pluginOptions: {}
2118
- };
2119
- rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(extraCSSOptions.loaderOptions).end();
2113
+ rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions).end();
2120
2114
  } else {
2121
2115
  const styleLoaderOptions = (0, import_shared17.mergeChainedOptions)({
2122
2116
  defaults: {},
@@ -2139,7 +2133,7 @@ async function applyCSSRule({
2139
2133
  rule.merge({ sideEffects: true });
2140
2134
  rule.resolve.preferRelative(true);
2141
2135
  }
2142
- var import_node_path11, import_shared17, enableNativeCss, isUseCssExtract, getCssModuleLocalIdentName, normalizeCssLoaderOptions, userPostcssrcCache, applyAutoprefixer, getPostcssLoaderOptions, getCssLoaderOptions, pluginCss;
2136
+ var import_node_path11, import_shared17, enableNativeCss, isUseCssExtract, getCSSModulesLocalIdentName, normalizeCssLoaderOptions, userPostcssrcCache, applyAutoprefixer, getPostcssLoaderOptions, getCSSLoaderOptions, pluginCss;
2143
2137
  var init_css = __esm({
2144
2138
  "src/plugins/css.ts"() {
2145
2139
  "use strict";
@@ -2150,7 +2144,7 @@ var init_css = __esm({
2150
2144
  init_pluginHelper();
2151
2145
  enableNativeCss = (config) => !config.output.injectStyles;
2152
2146
  isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
2153
- getCssModuleLocalIdentName = (config, isProd4) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
2147
+ getCSSModulesLocalIdentName = (config, isProd4) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
2154
2148
  (isProd4 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
2155
2149
  normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
2156
2150
  if (options.modules && exportOnlyLocals) {
@@ -2237,7 +2231,7 @@ var init_css = __esm({
2237
2231
  mergedConfig.postcssOptions.config = false;
2238
2232
  return mergedConfig;
2239
2233
  };
2240
- getCssLoaderOptions = ({
2234
+ getCSSLoaderOptions = ({
2241
2235
  config,
2242
2236
  importLoaders,
2243
2237
  target,
@@ -2249,6 +2243,7 @@ var init_css = __esm({
2249
2243
  modules: {
2250
2244
  auto: cssModules.auto,
2251
2245
  namedExport: false,
2246
+ exportGlobals: cssModules.exportGlobals,
2252
2247
  exportLocalsConvention: cssModules.exportLocalsConvention,
2253
2248
  localIdentName
2254
2249
  },
@@ -2272,7 +2267,7 @@ var init_css = __esm({
2272
2267
  api.modifyBundlerChain(async (chain, utils) => {
2273
2268
  const rule = chain.module.rule(utils.CHAIN_ID.RULE.CSS);
2274
2269
  const config = api.getNormalizedConfig();
2275
- rule.test(import_shared17.CSS_REGEX);
2270
+ rule.test(CSS_REGEX);
2276
2271
  await applyCSSRule({
2277
2272
  rule,
2278
2273
  utils,
@@ -2361,10 +2356,7 @@ var init_output = __esm({
2361
2356
  chain.plugin(CHAIN_ID3.PLUGIN.COPY).use(import_core3.rspack.CopyRspackPlugin, [options]);
2362
2357
  }
2363
2358
  if (isUseCssExtract(config, target)) {
2364
- const extractPluginOptions = (0, import_shared18.mergeChainedOptions)({
2365
- defaults: {},
2366
- options: config.tools.cssExtract?.pluginOptions
2367
- });
2359
+ const extractPluginOptions = config.tools.cssExtract.pluginOptions;
2368
2360
  const cssPath = (0, import_shared18.getDistPath)(config, "css");
2369
2361
  const cssFilename = (0, import_shared18.getFilename)(config, "css", isProd4);
2370
2362
  const cssAsyncPath = (0, import_shared18.getDistPath)(config, "cssAsync");
@@ -2372,7 +2364,6 @@ var init_output = __esm({
2372
2364
  {
2373
2365
  filename: import_node_path12.posix.join(cssPath, cssFilename),
2374
2366
  chunkFilename: import_node_path12.posix.join(cssAsyncPath, cssFilename),
2375
- ignoreOrder: true,
2376
2367
  ...extractPluginOptions
2377
2368
  }
2378
2369
  ]);
@@ -2761,6 +2752,7 @@ var init_fileSize = __esm({
2761
2752
  import_node_path14 = __toESM(require("path"));
2762
2753
  import_shared22 = require("@rsbuild/shared");
2763
2754
  import_shared23 = require("@rsbuild/shared");
2755
+ init_constants();
2764
2756
  filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
2765
2757
  getAssetColor = (size) => {
2766
2758
  if (size > 300 * 1e3) {
@@ -2779,10 +2771,10 @@ var init_fileSize = __esm({
2779
2771
  if (import_shared22.JS_REGEX.test(assetName)) {
2780
2772
  return import_shared23.color.cyan(assetName);
2781
2773
  }
2782
- if (import_shared22.CSS_REGEX.test(assetName)) {
2774
+ if (CSS_REGEX.test(assetName)) {
2783
2775
  return import_shared23.color.yellow(assetName);
2784
2776
  }
2785
- if (import_shared22.HTML_REGEX.test(assetName)) {
2777
+ if (HTML_REGEX.test(assetName)) {
2786
2778
  return import_shared23.color.green(assetName);
2787
2779
  }
2788
2780
  return import_shared23.color.magenta(assetName);
@@ -3342,6 +3334,7 @@ var init_inlineChunk = __esm({
3342
3334
  "src/plugins/inlineChunk.ts"() {
3343
3335
  "use strict";
3344
3336
  import_shared28 = require("@rsbuild/shared");
3337
+ init_constants();
3345
3338
  pluginInlineChunk = () => ({
3346
3339
  name: "rsbuild:inline-chunk",
3347
3340
  setup(api) {
@@ -3358,7 +3351,7 @@ var init_inlineChunk = __esm({
3358
3351
  scriptTests.push(inlineScripts === true ? import_shared28.JS_REGEX : inlineScripts);
3359
3352
  }
3360
3353
  if (inlineStyles) {
3361
- styleTests.push(inlineStyles === true ? import_shared28.CSS_REGEX : inlineStyles);
3354
+ styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
3362
3355
  }
3363
3356
  if (!scriptTests.length && !styleTests.length) {
3364
3357
  return;
@@ -4119,7 +4112,7 @@ function pluginLess() {
4119
4112
  api.modifyBundlerChain(async (chain, utils) => {
4120
4113
  const config = api.getNormalizedConfig();
4121
4114
  const { applyCSSRule: applyCSSRule2 } = await Promise.resolve().then(() => (init_css(), css_exports));
4122
- const rule = chain.module.rule(utils.CHAIN_ID.RULE.LESS).test(import_shared37.LESS_REGEX);
4115
+ const rule = chain.module.rule(utils.CHAIN_ID.RULE.LESS).test(/\.less$/);
4123
4116
  const { excludes, options } = getLessLoaderOptions(
4124
4117
  config.tools.less,
4125
4118
  config.output.sourceMap.css,
@@ -4229,7 +4222,7 @@ function pluginSass() {
4229
4222
  // otherwise the resolve-url-loader will throw an error
4230
4223
  true
4231
4224
  );
4232
- const rule = chain.module.rule(utils.CHAIN_ID.RULE.SASS).test(import_shared38.SASS_REGEX);
4225
+ const rule = chain.module.rule(utils.CHAIN_ID.RULE.SASS).test(/\.s(?:a|c)ss$/);
4233
4226
  for (const item of excludes) {
4234
4227
  rule.exclude.add(item);
4235
4228
  }
@@ -4645,7 +4638,7 @@ async function inspectConfig({
4645
4638
  })).rspackConfigs;
4646
4639
  const rsbuildDebugConfig = {
4647
4640
  ...context.normalizedConfig,
4648
- pluginNames: pluginManager.plugins.map((p) => p.name)
4641
+ pluginNames: pluginManager.getPlugins().map((p) => p.name)
4649
4642
  };
4650
4643
  const rawRsbuildConfig = await (0, import_shared41.stringifyConfig)(
4651
4644
  rsbuildDebugConfig,
@@ -4758,7 +4751,6 @@ function getChainUtils(target) {
4758
4751
  isServer: target === "node",
4759
4752
  isWebWorker: target === "web-worker",
4760
4753
  isServiceWorker: target === "service-worker",
4761
- getCompiledPath,
4762
4754
  CHAIN_ID: import_shared42.CHAIN_ID,
4763
4755
  HtmlPlugin: getHTMLPlugin()
4764
4756
  };
@@ -4799,7 +4791,6 @@ var init_rspackConfig = __esm({
4799
4791
  "use strict";
4800
4792
  import_shared42 = require("@rsbuild/shared");
4801
4793
  import_core5 = require("@rspack/core");
4802
- init_helpers();
4803
4794
  init_pluginHelper();
4804
4795
  }
4805
4796
  });
@@ -4900,12 +4891,11 @@ function applyHMREntry({
4900
4891
  }).apply(compiler);
4901
4892
  }
4902
4893
  }
4903
- var import_shared44, import_webpack_dev_middleware, setupServerHooks, getDevMiddleware;
4894
+ var import_shared44, setupServerHooks, getDevMiddleware;
4904
4895
  var init_devMiddleware = __esm({
4905
4896
  "src/server/devMiddleware.ts"() {
4906
4897
  "use strict";
4907
4898
  import_shared44 = require("@rsbuild/shared");
4908
- import_webpack_dev_middleware = __toESM(require("../compiled/webpack-dev-middleware/index.js"));
4909
4899
  setupServerHooks = (compiler, hookCallbacks) => {
4910
4900
  if ((0, import_shared44.isNodeCompiler)(compiler)) {
4911
4901
  return;
@@ -4915,21 +4905,24 @@ var init_devMiddleware = __esm({
4915
4905
  invalid.tap("rsbuild-dev-server", hookCallbacks.onInvalid);
4916
4906
  done.tap("rsbuild-dev-server", hookCallbacks.onDone);
4917
4907
  };
4918
- getDevMiddleware = (multiCompiler) => (options) => {
4919
- const { clientPaths, clientConfig, callbacks, liveReload, ...restOptions } = options;
4920
- const setupCompiler = (compiler) => {
4921
- if (clientPaths) {
4922
- applyHMREntry({
4923
- compiler,
4924
- clientPaths,
4925
- clientConfig,
4926
- liveReload
4927
- });
4928
- }
4929
- setupServerHooks(compiler, callbacks);
4908
+ getDevMiddleware = async (multiCompiler) => {
4909
+ const { default: webpackDevMiddleware } = await import("../compiled/webpack-dev-middleware/index.js");
4910
+ return (options) => {
4911
+ const { clientPaths, clientConfig, callbacks, liveReload, ...restOptions } = options;
4912
+ const setupCompiler = (compiler) => {
4913
+ if (clientPaths) {
4914
+ applyHMREntry({
4915
+ compiler,
4916
+ clientPaths,
4917
+ clientConfig,
4918
+ liveReload
4919
+ });
4920
+ }
4921
+ setupServerHooks(compiler, callbacks);
4922
+ };
4923
+ (0, import_shared44.applyToCompiler)(multiCompiler, setupCompiler);
4924
+ return webpackDevMiddleware(multiCompiler, restOptions);
4930
4925
  };
4931
- (0, import_shared44.applyToCompiler)(multiCompiler, setupCompiler);
4932
- return (0, import_webpack_dev_middleware.default)(multiCompiler, restOptions);
4933
4926
  };
4934
4927
  }
4935
4928
  });
@@ -5036,7 +5029,7 @@ async function createDevMiddleware(options, customCompiler) {
5036
5029
  }
5037
5030
  const { getDevMiddleware: getDevMiddleware2 } = await Promise.resolve().then(() => (init_devMiddleware(), devMiddleware_exports));
5038
5031
  return {
5039
- devMiddleware: getDevMiddleware2(compiler),
5032
+ devMiddleware: await getDevMiddleware2(compiler),
5040
5033
  compiler
5041
5034
  };
5042
5035
  }
@@ -6817,7 +6810,12 @@ async function createRsbuild(options = {}) {
6817
6810
  await applyDefaultPlugins(pluginManager);
6818
6811
  (0, import_shared59.debug)("add default plugins done");
6819
6812
  const rsbuild = {
6820
- ...(0, import_shared59.pick)(pluginManager, ["addPlugins", "removePlugins", "isPluginExists"]),
6813
+ ...(0, import_shared59.pick)(pluginManager, [
6814
+ "addPlugins",
6815
+ "getPlugins",
6816
+ "removePlugins",
6817
+ "isPluginExists"
6818
+ ]),
6821
6819
  ...(0, import_shared59.pick)(pluginAPI, [
6822
6820
  "onBeforeBuild",
6823
6821
  "onBeforeCreateCompiler",
@@ -6974,10 +6972,8 @@ __export(internal_exports, {
6974
6972
  initHooks: () => initHooks,
6975
6973
  initPlugins: () => initPlugins,
6976
6974
  initRsbuildConfig: () => initRsbuildConfig,
6977
- parseMinifyOptions: () => parseMinifyOptions,
6978
6975
  plugins: () => plugins,
6979
6976
  prepareCli: () => prepareCli,
6980
- rspackProvider: () => rspackProvider,
6981
6977
  runCli: () => runCli,
6982
6978
  setCssExtractPlugin: () => setCssExtractPlugin,
6983
6979
  setHTMLPlugin: () => setHTMLPlugin,
@@ -7003,7 +6999,7 @@ var applyServerOptions = (command) => {
7003
6999
  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");
7004
7000
  };
7005
7001
  function runCli() {
7006
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.0-beta.4");
7002
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.0-beta.6");
7007
7003
  const devCommand = import_commander.program.command("dev");
7008
7004
  const buildCommand = import_commander.program.command("build");
7009
7005
  const previewCommand = import_commander.program.command("preview");
@@ -7083,12 +7079,11 @@ function prepareCli() {
7083
7079
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7084
7080
  console.log();
7085
7081
  }
7086
- import_shared62.logger.greet(` ${`Rsbuild v${"0.7.0-beta.4"}`}
7082
+ import_shared62.logger.greet(` ${`Rsbuild v${"0.7.0-beta.6"}`}
7087
7083
  `);
7088
7084
  }
7089
7085
 
7090
7086
  // src/internal.ts
7091
- init_provider();
7092
7087
  init_createContext();
7093
7088
  init_pluginManager();
7094
7089
  init_initHooks();
@@ -7116,7 +7111,7 @@ init_config();
7116
7111
  var import_shared63 = require("@rsbuild/shared");
7117
7112
  init_mergeConfig();
7118
7113
  init_constants();
7119
- var version = "0.7.0-beta.4";
7114
+ var version = "0.7.0-beta.6";
7120
7115
  // Annotate the CommonJS export names for ESM import in node:
7121
7116
  0 && (module.exports = {
7122
7117
  PLUGIN_CSS_NAME,