@rsbuild/core 0.3.8 → 0.3.10

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.
@@ -112,7 +112,7 @@ const applyServerOptions = (command) => {
112
112
  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");
113
113
  };
114
114
  function runCli() {
115
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.8");
115
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.10");
116
116
  const devCommand = import_commander.program.command("dev");
117
117
  const buildCommand = import_commander.program.command("build");
118
118
  const previewCommand = import_commander.program.command("preview");
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.3.8"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.3.10"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_createRsbuild = require("./createRsbuild");
38
38
  var import_config = require("./cli/config");
39
39
  var import_shared = require("@rsbuild/shared");
40
40
  var import_constants = require("./constants");
41
- const version = "0.3.8";
41
+ const version = "0.3.10";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_BABEL_NAME,
@@ -21,19 +21,40 @@ __export(cleanOutput_exports, {
21
21
  pluginCleanOutput: () => pluginCleanOutput
22
22
  });
23
23
  module.exports = __toCommonJS(cleanOutput_exports);
24
+ var import_node_path = require("node:path");
24
25
  var import_shared = require("@rsbuild/shared");
25
26
  const emptyDir = async (dir) => {
26
27
  if (await import_shared.fse.pathExists(dir)) {
27
28
  await import_shared.fse.emptyDir(dir);
28
29
  }
29
30
  };
31
+ const addTrailingSep = (dir) => dir.endsWith(import_node_path.sep) ? dir : dir + import_node_path.sep;
32
+ const isStrictSubdir = (parent, child) => {
33
+ const parentDir = addTrailingSep(parent);
34
+ const childDir = addTrailingSep(child);
35
+ return parentDir !== childDir && childDir.startsWith(parentDir);
36
+ };
30
37
  const pluginCleanOutput = () => ({
31
38
  name: "rsbuild:clean-output",
32
39
  setup(api) {
33
40
  const clean = async () => {
41
+ const { distPath, rootPath } = api.context;
34
42
  const config = api.getNormalizedConfig();
35
- if (config.output.cleanDistPath) {
36
- const { distPath } = api.context;
43
+ let { cleanDistPath } = config.output;
44
+ if (cleanDistPath === void 0) {
45
+ cleanDistPath = isStrictSubdir(rootPath, distPath);
46
+ if (!cleanDistPath) {
47
+ import_shared.logger.warn(
48
+ "The dist path is not a subdir of root path, Rsbuild will not empty it."
49
+ );
50
+ import_shared.logger.warn(
51
+ `Please set ${import_shared.color.yellow("`output.cleanDistPath`")} config manually.`
52
+ );
53
+ import_shared.logger.warn(`Current root path: ${import_shared.color.dim(rootPath)}`);
54
+ import_shared.logger.warn(`Current dist path: ${import_shared.color.dim(distPath)}`);
55
+ }
56
+ }
57
+ if (cleanDistPath) {
37
58
  await emptyDir(distPath);
38
59
  }
39
60
  };
@@ -27,12 +27,10 @@ const pluginDefine = () => ({
27
27
  setup(api) {
28
28
  api.modifyBundlerChain((chain, { CHAIN_ID, bundler }) => {
29
29
  const config = api.getNormalizedConfig();
30
- const publicPath = chain.output.get("publicPath");
31
- const assetPrefix = publicPath && typeof publicPath === "string" ? publicPath : config.output.assetPrefix;
32
30
  const builtinVars = {
33
31
  "process.env.NODE_ENV": JSON.stringify((0, import_shared.getNodeEnv)()),
34
32
  "process.env.ASSET_PREFIX": JSON.stringify(
35
- (0, import_shared.removeTailSlash)(assetPrefix)
33
+ (0, import_shared.getPublicPathFromChain)(chain, false)
36
34
  )
37
35
  };
38
36
  chain.plugin(CHAIN_ID.PLUGIN.DEFINE).use(bundler.DefinePlugin, [
@@ -188,9 +188,7 @@ const pluginHtml = () => ({
188
188
  return;
189
189
  }
190
190
  const minify = await (0, import_shared.getMinify)(isProd, config);
191
- const assetPrefix = (0, import_shared.removeTailSlash)(
192
- chain.output.get("publicPath") || ""
193
- );
191
+ const assetPrefix = (0, import_shared.getPublicPathFromChain)(chain, false);
194
192
  const entries = chain.entryPoints.entries() || {};
195
193
  const entryNames = Object.keys(entries);
196
194
  const htmlPaths = api.getHTMLPaths();
@@ -43,6 +43,7 @@ const plugins = {
43
43
  splitChunks: () => Promise.resolve().then(() => __toESM(require("./splitChunks"))).then((m) => m.pluginSplitChunks()),
44
44
  inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.pluginInlineChunk()),
45
45
  bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.pluginBundleAnalyzer()),
46
+ rsdoctor: () => Promise.resolve().then(() => __toESM(require("./rsdoctor"))).then((m) => m.pluginRsdoctor()),
46
47
  asset: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset()),
47
48
  wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
48
49
  moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '../types';
2
+ export declare const pluginRsdoctor: () => RsbuildPlugin;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var rsdoctor_exports = {};
30
+ __export(rsdoctor_exports, {
31
+ pluginRsdoctor: () => pluginRsdoctor
32
+ });
33
+ module.exports = __toCommonJS(rsdoctor_exports);
34
+ var import_shared = require("@rsbuild/shared");
35
+ const pluginRsdoctor = () => ({
36
+ name: "rsbuild:rsdoctor",
37
+ setup(api) {
38
+ api.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
39
+ if (process.env.RSDOCTOR !== "true") {
40
+ return;
41
+ }
42
+ const isRspack = api.context.bundlerType === "rspack";
43
+ const packageName = isRspack ? "@rsdoctor/rspack-plugin" : "@rsdoctor/webpack-plugin";
44
+ let module2;
45
+ try {
46
+ const path = require.resolve(packageName, {
47
+ paths: [api.context.rootPath]
48
+ });
49
+ module2 = await Promise.resolve().then(() => __toESM(require(path)));
50
+ } catch (err) {
51
+ import_shared.logger.warn(
52
+ `\`process.env.RSDOCTOR\` enabled, please install ${import_shared.color.bold(import_shared.color.yellow(packageName))} package.`
53
+ );
54
+ return;
55
+ }
56
+ const pluginName = isRspack ? "RsdoctorRspackPlugin" : "RsdoctorWebpackPlugin";
57
+ if (!module2 || !module2[pluginName]) {
58
+ return;
59
+ }
60
+ let isAutoRegister = false;
61
+ bundlerConfigs.forEach((config) => {
62
+ const registered = config.plugins?.some(
63
+ (plugin) => plugin?.constructor?.name === pluginName
64
+ );
65
+ if (registered) {
66
+ return;
67
+ }
68
+ config.plugins || (config.plugins = []);
69
+ config.plugins.push(new module2[pluginName]());
70
+ isAutoRegister = true;
71
+ });
72
+ if (isAutoRegister) {
73
+ import_shared.logger.info(`${import_shared.color.bold(import_shared.color.yellow(packageName))} enabled.`);
74
+ }
75
+ });
76
+ }
77
+ });
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ pluginRsdoctor
81
+ });
@@ -1,4 +1,4 @@
1
1
  import type { RsbuildPlugin } from '../types';
2
2
  export declare const MODULE_PATH_REGEX: RegExp;
3
3
  export declare function getPackageNameFromModulePath(modulePath: string): string | undefined;
4
- export declare function pluginSplitChunks(): RsbuildPlugin;
4
+ export declare const pluginSplitChunks: () => RsbuildPlugin;
@@ -119,12 +119,12 @@ function splitByModule(ctx) {
119
119
  };
120
120
  }
121
121
  function splitBySize(ctx) {
122
- const { override, userDefinedCacheGroups, defaultConfig, rsbuildConfig } = ctx;
123
- (0, import_node_assert.default)(rsbuildConfig.strategy === "split-by-size");
122
+ const { override, userDefinedCacheGroups, defaultConfig, userConfig } = ctx;
123
+ (0, import_node_assert.default)(userConfig.strategy === "split-by-size");
124
124
  return {
125
125
  ...defaultConfig,
126
- minSize: rsbuildConfig.minSize ?? 0,
127
- maxSize: rsbuildConfig.maxSize ?? Infinity,
126
+ minSize: userConfig.minSize ?? 0,
127
+ maxSize: userConfig.maxSize ?? Infinity,
128
128
  ...override,
129
129
  cacheGroups: {
130
130
  ...defaultConfig.cacheGroups,
@@ -179,60 +179,58 @@ const SPLIT_STRATEGY_DISPATCHER = {
179
179
  "all-in-one": allInOne,
180
180
  "single-vendor": singleVendor
181
181
  };
182
- function pluginSplitChunks() {
183
- return {
184
- name: "rsbuild:split-chunks",
185
- setup(api) {
186
- api.modifyBundlerChain(
187
- async (chain, { isServer, isWebWorker, isServiceWorker }) => {
188
- if (isServer || isWebWorker || isServiceWorker) {
189
- chain.optimization.splitChunks(false);
190
- if (isWebWorker || isServiceWorker) {
191
- chain.module.parser.merge({
192
- javascript: {
193
- dynamicImportMode: "eager"
194
- }
195
- });
196
- }
197
- return;
198
- }
199
- const config = api.getNormalizedConfig();
200
- const defaultConfig = {
201
- // Optimize both `initial` and `async` chunks
202
- chunks: "all",
203
- // When chunk size >= 50000 bytes, split it into separate chunk
204
- // @ts-expect-error Rspack type missing
205
- enforceSizeThreshold: 5e4,
206
- cacheGroups: {}
207
- };
208
- const { chunkSplit } = config.performance;
209
- let userDefinedCacheGroups = {};
210
- if (chunkSplit.forceSplitting) {
211
- userDefinedCacheGroups = getUserDefinedCacheGroups(
212
- chunkSplit.forceSplitting
213
- );
182
+ const pluginSplitChunks = () => ({
183
+ name: "rsbuild:split-chunks",
184
+ setup(api) {
185
+ api.modifyBundlerChain(
186
+ async (chain, { isServer, isWebWorker, isServiceWorker }) => {
187
+ if (isServer || isWebWorker || isServiceWorker) {
188
+ chain.optimization.splitChunks(false);
189
+ if (isWebWorker || isServiceWorker) {
190
+ chain.module.parser.merge({
191
+ javascript: {
192
+ dynamicImportMode: "eager"
193
+ }
194
+ });
214
195
  }
215
- const override = chunkSplit.strategy === "custom" ? (
216
- // `chunkSplit.splitChunks` compat for Eden
217
- chunkSplit.splitChunks ?? chunkSplit.override
218
- ) : chunkSplit.override;
219
- const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
220
- defaultConfig,
221
- override: override || {},
222
- userDefinedCacheGroups,
223
- rsbuildConfig: chunkSplit,
224
- rootPath: api.context.rootPath,
225
- polyfill: config.output.polyfill
226
- });
227
- chain.optimization.splitChunks(
228
- // @ts-expect-error splitChunks type mismatch
229
- splitChunksOptions
196
+ return;
197
+ }
198
+ const config = api.getNormalizedConfig();
199
+ const defaultConfig = {
200
+ // Optimize both `initial` and `async` chunks
201
+ chunks: "all",
202
+ // When chunk size >= 50000 bytes, split it into separate chunk
203
+ // @ts-expect-error Rspack type missing
204
+ enforceSizeThreshold: 5e4,
205
+ cacheGroups: {}
206
+ };
207
+ const { chunkSplit } = config.performance;
208
+ let userDefinedCacheGroups = {};
209
+ if (chunkSplit.forceSplitting) {
210
+ userDefinedCacheGroups = getUserDefinedCacheGroups(
211
+ chunkSplit.forceSplitting
230
212
  );
231
213
  }
232
- );
233
- }
234
- };
235
- }
214
+ const override = chunkSplit.strategy === "custom" ? (
215
+ // `chunkSplit.splitChunks` compat for Eden
216
+ chunkSplit.splitChunks ?? chunkSplit.override
217
+ ) : chunkSplit.override;
218
+ const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy || "split-by-experience"]({
219
+ defaultConfig,
220
+ override: override || {},
221
+ userDefinedCacheGroups,
222
+ userConfig: chunkSplit,
223
+ rootPath: api.context.rootPath,
224
+ polyfill: config.output.polyfill
225
+ });
226
+ chain.optimization.splitChunks(
227
+ // @ts-expect-error splitChunks type mismatch
228
+ splitChunksOptions
229
+ );
230
+ }
231
+ );
232
+ }
233
+ });
236
234
  // Annotate the CommonJS export names for ESM import in node:
237
235
  0 && (module.exports = {
238
236
  MODULE_PATH_REGEX,
@@ -43,7 +43,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
43
43
  const context = {
44
44
  entry: config.source?.entry || {},
45
45
  targets: config.output?.targets || [],
46
- version: "0.3.8",
46
+ version: "0.3.10",
47
47
  rootPath,
48
48
  distPath,
49
49
  cachePath,
@@ -24,7 +24,9 @@ module.exports = __toCommonJS(transition_exports);
24
24
  const pluginTransition = () => ({
25
25
  name: "rsbuild:transition",
26
26
  setup() {
27
+ var _a;
27
28
  process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
29
+ (_a = process.env).WATCHPACK_WATCHER_LIMIT || (_a.WATCHPACK_WATCHER_LIMIT = "20");
28
30
  }
29
31
  });
30
32
  // Annotate the CommonJS export names for ESM import in node:
@@ -69,6 +69,7 @@ const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
69
69
  plugins.startUrl(),
70
70
  plugins.inlineChunk(),
71
71
  plugins.bundleAnalyzer(),
72
+ plugins.rsdoctor(),
72
73
  plugins.networkPerformance(),
73
74
  plugins.preloadOrPrefetch(),
74
75
  plugins.performance(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -52,12 +52,12 @@
52
52
  "types.d.ts"
53
53
  ],
54
54
  "dependencies": {
55
- "@rspack/core": "0.5.2",
55
+ "@rspack/core": "0.5.3",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.32.2",
58
58
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
59
59
  "postcss": "^8.4.33",
60
- "@rsbuild/shared": "0.3.8"
60
+ "@rsbuild/shared": "0.3.10"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",