@rsbuild/core 0.7.0 → 0.7.1

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
@@ -911,7 +911,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
911
911
  return {
912
912
  entry: getEntryObject(config, "web"),
913
913
  targets: config.output?.targets || [],
914
- version: "0.7.0",
914
+ version: "0.7.1",
915
915
  rootPath,
916
916
  distPath,
917
917
  cachePath,
@@ -6527,6 +6527,80 @@ var init_rspackProfile = __esm({
6527
6527
  }
6528
6528
  });
6529
6529
 
6530
+ // src/plugins/lazyCompilation.ts
6531
+ var lazyCompilation_exports = {};
6532
+ __export(lazyCompilation_exports, {
6533
+ pluginLazyCompilation: () => pluginLazyCompilation
6534
+ });
6535
+ var import_shared56, pluginLazyCompilation;
6536
+ var init_lazyCompilation = __esm({
6537
+ "src/plugins/lazyCompilation.ts"() {
6538
+ "use strict";
6539
+ import_shared56 = require("@rsbuild/shared");
6540
+ pluginLazyCompilation = () => ({
6541
+ name: "rsbuild:lazy-compilation",
6542
+ setup(api) {
6543
+ api.modifyBundlerChain((chain, { isProd: isProd4, target }) => {
6544
+ if (isProd4 || target !== "web") {
6545
+ return;
6546
+ }
6547
+ const config = api.getNormalizedConfig();
6548
+ const options = config.dev?.lazyCompilation;
6549
+ if (!options) {
6550
+ return;
6551
+ }
6552
+ const clientRegExp = /[\\/]core[\\/]dist[\\/]client[\\/]/;
6553
+ const cssRegExp = /\.(?:css|less|sass|scss|styl|stylus)$/;
6554
+ const isExcludedModule = (name) => {
6555
+ return (
6556
+ // alway include Rsbuild client code, such as HMR
6557
+ clientRegExp.test(name) || // exclude CSS files because Rspack does not support it yet
6558
+ // TODO: remove this after Rspack supporting it
6559
+ cssRegExp.test(name)
6560
+ );
6561
+ };
6562
+ const defaultTest = (module2) => {
6563
+ const name = module2.nameForCondition();
6564
+ if (!name) {
6565
+ return false;
6566
+ }
6567
+ return !isExcludedModule(name);
6568
+ };
6569
+ const mergeOptions = () => {
6570
+ if (options === true) {
6571
+ return { test: defaultTest };
6572
+ }
6573
+ const { test } = options;
6574
+ if (!test) {
6575
+ return {
6576
+ ...options,
6577
+ test: defaultTest
6578
+ };
6579
+ }
6580
+ return {
6581
+ ...options,
6582
+ test(module2) {
6583
+ const name = module2.nameForCondition();
6584
+ if (!name || isExcludedModule(name)) {
6585
+ return false;
6586
+ }
6587
+ if ((0, import_shared56.isRegExp)(test)) {
6588
+ return name ? test.test(name) : false;
6589
+ }
6590
+ return test(module2);
6591
+ }
6592
+ };
6593
+ };
6594
+ chain.experiments({
6595
+ ...chain.get("experiments"),
6596
+ lazyCompilation: mergeOptions()
6597
+ });
6598
+ });
6599
+ }
6600
+ });
6601
+ }
6602
+ });
6603
+
6530
6604
  // src/createRsbuild.ts
6531
6605
  var createRsbuild_exports = {};
6532
6606
  __export(createRsbuild_exports, {
@@ -6564,6 +6638,7 @@ async function applyDefaultPlugins(pluginManager, context) {
6564
6638
  const { pluginManifest: pluginManifest2 } = await Promise.resolve().then(() => (init_manifest(), manifest_exports));
6565
6639
  const { pluginModuleFederation: pluginModuleFederation2 } = await Promise.resolve().then(() => (init_moduleFederation(), moduleFederation_exports));
6566
6640
  const { pluginRspackProfile: pluginRspackProfile2 } = await Promise.resolve().then(() => (init_rspackProfile(), rspackProfile_exports));
6641
+ const { pluginLazyCompilation: pluginLazyCompilation2 } = await Promise.resolve().then(() => (init_lazyCompilation(), lazyCompilation_exports));
6567
6642
  pluginManager.addPlugins([
6568
6643
  pluginBasic2(),
6569
6644
  pluginEntry2(),
@@ -6598,7 +6673,8 @@ async function applyDefaultPlugins(pluginManager, context) {
6598
6673
  pluginServer2(),
6599
6674
  pluginManifest2(),
6600
6675
  pluginModuleFederation2(),
6601
- pluginRspackProfile2()
6676
+ pluginRspackProfile2(),
6677
+ pluginLazyCompilation2()
6602
6678
  ]);
6603
6679
  }
6604
6680
  async function createRsbuild(options = {}) {
@@ -6616,9 +6692,9 @@ async function createRsbuild(options = {}) {
6616
6692
  );
6617
6693
  const pluginAPI = getPluginAPI({ context, pluginManager });
6618
6694
  context.pluginAPI = pluginAPI;
6619
- (0, import_shared56.debug)("add default plugins");
6695
+ (0, import_shared57.debug)("add default plugins");
6620
6696
  await applyDefaultPlugins(pluginManager, context);
6621
- (0, import_shared56.debug)("add default plugins done");
6697
+ (0, import_shared57.debug)("add default plugins done");
6622
6698
  const provider = rsbuildConfig.provider || await getRspackProvider();
6623
6699
  const providerInstance = await provider({
6624
6700
  context,
@@ -6627,13 +6703,13 @@ async function createRsbuild(options = {}) {
6627
6703
  setCssExtractPlugin
6628
6704
  });
6629
6705
  const rsbuild = {
6630
- ...(0, import_shared56.pick)(pluginManager, [
6706
+ ...(0, import_shared57.pick)(pluginManager, [
6631
6707
  "addPlugins",
6632
6708
  "getPlugins",
6633
6709
  "removePlugins",
6634
6710
  "isPluginExists"
6635
6711
  ]),
6636
- ...(0, import_shared56.pick)(pluginAPI, [
6712
+ ...(0, import_shared57.pick)(pluginAPI, [
6637
6713
  "onBeforeBuild",
6638
6714
  "onBeforeCreateCompiler",
6639
6715
  "onBeforeStartDevServer",
@@ -6649,7 +6725,7 @@ async function createRsbuild(options = {}) {
6649
6725
  "getRsbuildConfig",
6650
6726
  "getNormalizedConfig"
6651
6727
  ]),
6652
- ...(0, import_shared56.pick)(providerInstance, [
6728
+ ...(0, import_shared57.pick)(providerInstance, [
6653
6729
  "build",
6654
6730
  "preview",
6655
6731
  "initConfigs",
@@ -6666,11 +6742,11 @@ async function createRsbuild(options = {}) {
6666
6742
  }
6667
6743
  return rsbuild;
6668
6744
  }
6669
- var import_shared56, getRspackProvider, pickRsbuildConfig;
6745
+ var import_shared57, getRspackProvider, pickRsbuildConfig;
6670
6746
  var init_createRsbuild = __esm({
6671
6747
  "src/createRsbuild.ts"() {
6672
6748
  "use strict";
6673
- import_shared56 = require("@rsbuild/shared");
6749
+ import_shared57 = require("@rsbuild/shared");
6674
6750
  init_createContext();
6675
6751
  init_initPlugins();
6676
6752
  init_pluginHelper();
@@ -6692,7 +6768,7 @@ var init_createRsbuild = __esm({
6692
6768
  "moduleFederation",
6693
6769
  "_privateMeta"
6694
6770
  ];
6695
- return (0, import_shared56.pick)(rsbuildConfig, keys);
6771
+ return (0, import_shared57.pick)(rsbuildConfig, keys);
6696
6772
  };
6697
6773
  }
6698
6774
  });
@@ -6711,7 +6787,7 @@ async function init({
6711
6787
  cwd: root,
6712
6788
  mode: cliOptions?.envMode
6713
6789
  });
6714
- if ((0, import_shared57.isDev)()) {
6790
+ if ((0, import_shared58.isDev)()) {
6715
6791
  onBeforeRestartServer(envs.cleanup);
6716
6792
  }
6717
6793
  const { content: config, filePath: configFilePath } = await loadConfig({
@@ -6751,17 +6827,17 @@ async function init({
6751
6827
  });
6752
6828
  } catch (err) {
6753
6829
  if (isRestart) {
6754
- import_shared57.logger.error(err);
6830
+ import_shared58.logger.error(err);
6755
6831
  } else {
6756
6832
  throw err;
6757
6833
  }
6758
6834
  }
6759
6835
  }
6760
- var import_shared57, commonOpts;
6836
+ var import_shared58, commonOpts;
6761
6837
  var init_init = __esm({
6762
6838
  "src/cli/init.ts"() {
6763
6839
  "use strict";
6764
- import_shared57 = require("@rsbuild/shared");
6840
+ import_shared58 = require("@rsbuild/shared");
6765
6841
  init_config();
6766
6842
  init_loadEnv();
6767
6843
  init_restart();
@@ -6779,7 +6855,7 @@ __export(src_exports, {
6779
6855
  defineConfig: () => defineConfig,
6780
6856
  loadConfig: () => loadConfig,
6781
6857
  loadEnv: () => loadEnv,
6782
- logger: () => import_shared60.logger,
6858
+ logger: () => import_shared61.logger,
6783
6859
  mergeRsbuildConfig: () => mergeRsbuildConfig,
6784
6860
  rspack: () => import_core10.rspack,
6785
6861
  version: () => version
@@ -6811,7 +6887,7 @@ __export(internal_exports, {
6811
6887
  // src/cli/commands.ts
6812
6888
  var import_node_fs5 = require("fs");
6813
6889
  var import_node_path28 = require("path");
6814
- var import_shared58 = require("@rsbuild/shared");
6890
+ var import_shared59 = require("@rsbuild/shared");
6815
6891
  var import_commander = require("../compiled/commander/index.js");
6816
6892
  init_init();
6817
6893
  var applyCommonOptions = (command) => {
@@ -6827,7 +6903,7 @@ var applyServerOptions = (command) => {
6827
6903
  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");
6828
6904
  };
6829
6905
  function runCli() {
6830
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.0");
6906
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.1");
6831
6907
  const devCommand = import_commander.program.command("dev");
6832
6908
  const buildCommand = import_commander.program.command("build");
6833
6909
  const previewCommand = import_commander.program.command("preview");
@@ -6841,8 +6917,8 @@ function runCli() {
6841
6917
  const rsbuild = await init({ cliOptions: options });
6842
6918
  await rsbuild?.startDevServer();
6843
6919
  } catch (err) {
6844
- import_shared58.logger.error("Failed to start dev server.");
6845
- import_shared58.logger.error(err);
6920
+ import_shared59.logger.error("Failed to start dev server.");
6921
+ import_shared59.logger.error(err);
6846
6922
  process.exit(1);
6847
6923
  }
6848
6924
  });
@@ -6853,8 +6929,8 @@ function runCli() {
6853
6929
  watch: options.watch
6854
6930
  });
6855
6931
  } catch (err) {
6856
- import_shared58.logger.error("Failed to build.");
6857
- import_shared58.logger.error(err);
6932
+ import_shared59.logger.error("Failed to build.");
6933
+ import_shared59.logger.error(err);
6858
6934
  process.exit(1);
6859
6935
  }
6860
6936
  });
@@ -6863,15 +6939,15 @@ function runCli() {
6863
6939
  const rsbuild = await init({ cliOptions: options });
6864
6940
  if (rsbuild && !(0, import_node_fs5.existsSync)(rsbuild.context.distPath)) {
6865
6941
  throw new Error(
6866
- `The output directory ${import_shared58.color.yellow(
6942
+ `The output directory ${import_shared59.color.yellow(
6867
6943
  rsbuild.context.distPath
6868
6944
  )} does not exist, please build the project before previewing.`
6869
6945
  );
6870
6946
  }
6871
6947
  await rsbuild?.preview();
6872
6948
  } catch (err) {
6873
- import_shared58.logger.error("Failed to start preview server.");
6874
- import_shared58.logger.error(err);
6949
+ import_shared59.logger.error("Failed to start preview server.");
6950
+ import_shared59.logger.error(err);
6875
6951
  process.exit(1);
6876
6952
  }
6877
6953
  });
@@ -6885,8 +6961,8 @@ function runCli() {
6885
6961
  writeToDisk: true
6886
6962
  });
6887
6963
  } catch (err) {
6888
- import_shared58.logger.error("Failed to inspect config.");
6889
- import_shared58.logger.error(err);
6964
+ import_shared59.logger.error("Failed to inspect config.");
6965
+ import_shared59.logger.error(err);
6890
6966
  process.exit(1);
6891
6967
  }
6892
6968
  });
@@ -6894,7 +6970,7 @@ function runCli() {
6894
6970
  }
6895
6971
 
6896
6972
  // src/cli/prepare.ts
6897
- var import_shared59 = require("@rsbuild/shared");
6973
+ var import_shared60 = require("@rsbuild/shared");
6898
6974
  function initNodeEnv() {
6899
6975
  if (!process.env.NODE_ENV) {
6900
6976
  const command = process.argv[2];
@@ -6907,7 +6983,7 @@ function prepareCli() {
6907
6983
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
6908
6984
  console.log();
6909
6985
  }
6910
- import_shared59.logger.greet(` ${`Rsbuild v${"0.7.0"}`}
6986
+ import_shared60.logger.greet(` ${`Rsbuild v${"0.7.1"}`}
6911
6987
  `);
6912
6988
  }
6913
6989
 
@@ -6930,10 +7006,10 @@ init_prodServer();
6930
7006
  init_loadEnv();
6931
7007
  init_createRsbuild();
6932
7008
  init_config();
6933
- var import_shared60 = require("@rsbuild/shared");
7009
+ var import_shared61 = require("@rsbuild/shared");
6934
7010
  init_mergeConfig();
6935
7011
  init_constants();
6936
- var version = "0.7.0";
7012
+ var version = "0.7.1";
6937
7013
  // Annotate the CommonJS export names for ESM import in node:
6938
7014
  0 && (module.exports = {
6939
7015
  PLUGIN_CSS_NAME,
package/dist/index.js CHANGED
@@ -962,7 +962,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
962
962
  return {
963
963
  entry: getEntryObject(config, "web"),
964
964
  targets: config.output?.targets || [],
965
- version: "0.7.0",
965
+ version: "0.7.1",
966
966
  rootPath,
967
967
  distPath,
968
968
  cachePath,
@@ -6767,6 +6767,81 @@ var init_rspackProfile = __esm({
6767
6767
  }
6768
6768
  });
6769
6769
 
6770
+ // src/plugins/lazyCompilation.ts
6771
+ var lazyCompilation_exports = {};
6772
+ __export(lazyCompilation_exports, {
6773
+ pluginLazyCompilation: () => pluginLazyCompilation
6774
+ });
6775
+ import { isRegExp } from "@rsbuild/shared";
6776
+ var pluginLazyCompilation;
6777
+ var init_lazyCompilation = __esm({
6778
+ "src/plugins/lazyCompilation.ts"() {
6779
+ "use strict";
6780
+ init_esm();
6781
+ pluginLazyCompilation = () => ({
6782
+ name: "rsbuild:lazy-compilation",
6783
+ setup(api) {
6784
+ api.modifyBundlerChain((chain, { isProd: isProd4, target }) => {
6785
+ if (isProd4 || target !== "web") {
6786
+ return;
6787
+ }
6788
+ const config = api.getNormalizedConfig();
6789
+ const options = config.dev?.lazyCompilation;
6790
+ if (!options) {
6791
+ return;
6792
+ }
6793
+ const clientRegExp = /[\\/]core[\\/]dist[\\/]client[\\/]/;
6794
+ const cssRegExp = /\.(?:css|less|sass|scss|styl|stylus)$/;
6795
+ const isExcludedModule = (name) => {
6796
+ return (
6797
+ // alway include Rsbuild client code, such as HMR
6798
+ clientRegExp.test(name) || // exclude CSS files because Rspack does not support it yet
6799
+ // TODO: remove this after Rspack supporting it
6800
+ cssRegExp.test(name)
6801
+ );
6802
+ };
6803
+ const defaultTest = (module) => {
6804
+ const name = module.nameForCondition();
6805
+ if (!name) {
6806
+ return false;
6807
+ }
6808
+ return !isExcludedModule(name);
6809
+ };
6810
+ const mergeOptions = () => {
6811
+ if (options === true) {
6812
+ return { test: defaultTest };
6813
+ }
6814
+ const { test } = options;
6815
+ if (!test) {
6816
+ return {
6817
+ ...options,
6818
+ test: defaultTest
6819
+ };
6820
+ }
6821
+ return {
6822
+ ...options,
6823
+ test(module) {
6824
+ const name = module.nameForCondition();
6825
+ if (!name || isExcludedModule(name)) {
6826
+ return false;
6827
+ }
6828
+ if (isRegExp(test)) {
6829
+ return name ? test.test(name) : false;
6830
+ }
6831
+ return test(module);
6832
+ }
6833
+ };
6834
+ };
6835
+ chain.experiments({
6836
+ ...chain.get("experiments"),
6837
+ lazyCompilation: mergeOptions()
6838
+ });
6839
+ });
6840
+ }
6841
+ });
6842
+ }
6843
+ });
6844
+
6770
6845
  // src/createRsbuild.ts
6771
6846
  var createRsbuild_exports = {};
6772
6847
  __export(createRsbuild_exports, {
@@ -6805,6 +6880,7 @@ async function applyDefaultPlugins(pluginManager, context) {
6805
6880
  const { pluginManifest: pluginManifest2 } = await Promise.resolve().then(() => (init_manifest(), manifest_exports));
6806
6881
  const { pluginModuleFederation: pluginModuleFederation2 } = await Promise.resolve().then(() => (init_moduleFederation(), moduleFederation_exports));
6807
6882
  const { pluginRspackProfile: pluginRspackProfile2 } = await Promise.resolve().then(() => (init_rspackProfile(), rspackProfile_exports));
6883
+ const { pluginLazyCompilation: pluginLazyCompilation2 } = await Promise.resolve().then(() => (init_lazyCompilation(), lazyCompilation_exports));
6808
6884
  pluginManager.addPlugins([
6809
6885
  pluginBasic2(),
6810
6886
  pluginEntry2(),
@@ -6839,7 +6915,8 @@ async function applyDefaultPlugins(pluginManager, context) {
6839
6915
  pluginServer2(),
6840
6916
  pluginManifest2(),
6841
6917
  pluginModuleFederation2(),
6842
- pluginRspackProfile2()
6918
+ pluginRspackProfile2(),
6919
+ pluginLazyCompilation2()
6843
6920
  ]);
6844
6921
  }
6845
6922
  async function createRsbuild(options = {}) {
@@ -7057,7 +7134,7 @@ var applyServerOptions = (command) => {
7057
7134
  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");
7058
7135
  };
7059
7136
  function runCli() {
7060
- program.name("rsbuild").usage("<command> [options]").version("0.7.0");
7137
+ program.name("rsbuild").usage("<command> [options]").version("0.7.1");
7061
7138
  const devCommand = program.command("dev");
7062
7139
  const buildCommand = program.command("build");
7063
7140
  const previewCommand = program.command("preview");
@@ -7138,7 +7215,7 @@ function prepareCli() {
7138
7215
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7139
7216
  console.log();
7140
7217
  }
7141
- logger18.greet(` ${`Rsbuild v${"0.7.0"}`}
7218
+ logger18.greet(` ${`Rsbuild v${"0.7.1"}`}
7142
7219
  `);
7143
7220
  }
7144
7221
 
@@ -7165,7 +7242,7 @@ init_config();
7165
7242
  init_mergeConfig();
7166
7243
  init_constants();
7167
7244
  import { logger as logger19 } from "@rsbuild/shared";
7168
- var version = "0.7.0";
7245
+ var version = "0.7.1";
7169
7246
  export {
7170
7247
  PLUGIN_CSS_NAME,
7171
7248
  PLUGIN_SWC_NAME,
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export declare const pluginLazyCompilation: () => RsbuildPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -51,7 +51,7 @@
51
51
  "core-js": "~3.36.0",
52
52
  "html-webpack-plugin": "npm:html-rspack-plugin@5.7.2",
53
53
  "postcss": "^8.4.38",
54
- "@rsbuild/shared": "0.7.0"
54
+ "@rsbuild/shared": "0.7.1"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/connect": "3.4.38",