@rsbuild/core 0.0.10 → 0.0.12

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,5 +1,6 @@
1
1
  import { type RsbuildInstance, type RsbuildProvider, type CreateRsbuildOptions } from '@rsbuild/shared';
2
2
  import type { RsbuildConfig } from './rspack-provider';
3
+ export declare const getCreateRsbuildDefaultOptions: () => Required<CreateRsbuildOptions>;
3
4
  export declare function createRsbuild<P extends ({
4
5
  rsbuildConfig
5
6
  }: {
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var createRsbuild_exports = {};
30
30
  __export(createRsbuild_exports, {
31
- createRsbuild: () => createRsbuild
31
+ createRsbuild: () => createRsbuild,
32
+ getCreateRsbuildDefaultOptions: () => getCreateRsbuildDefaultOptions
32
33
  });
33
34
  module.exports = __toCommonJS(createRsbuild_exports);
34
35
  var import_shared = require("@rsbuild/shared");
@@ -39,10 +40,19 @@ const getRspackProvider = async (rsbuildConfig) => {
39
40
  rsbuildConfig
40
41
  });
41
42
  };
43
+ const getCreateRsbuildDefaultOptions = () => ({
44
+ cwd: process.cwd(),
45
+ entry: {},
46
+ target: ["web"],
47
+ configPath: null
48
+ });
42
49
  async function createRsbuild(options) {
43
50
  const { rsbuildConfig } = options;
44
51
  const provider = options.provider ? options.provider({ rsbuildConfig }) : await getRspackProvider(rsbuildConfig);
45
- const rsbuildOptions = (0, import_shared.applyDefaultRsbuildOptions)(options);
52
+ const rsbuildOptions = {
53
+ ...getCreateRsbuildDefaultOptions(),
54
+ ...options
55
+ };
46
56
  const pluginStore = (0, import_shared.createPluginStore)();
47
57
  const {
48
58
  build,
@@ -88,5 +98,6 @@ async function createRsbuild(options) {
88
98
  }
89
99
  // Annotate the CommonJS export names for ESM import in node:
90
100
  0 && (module.exports = {
91
- createRsbuild
101
+ createRsbuild,
102
+ getCreateRsbuildDefaultOptions
92
103
  });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { createRsbuild } from './createRsbuild';
1
+ export { createRsbuild, getCreateRsbuildDefaultOptions } from './createRsbuild';
2
2
  export { mergeRsbuildConfig } from '@rsbuild/shared';
3
3
  export { defineConfig } from './cli';
4
4
  export type { RsbuildPluginAPI, RsbuildConfig } from './rspack-provider';
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var src_exports = {};
20
20
  __export(src_exports, {
21
21
  createRsbuild: () => import_createRsbuild.createRsbuild,
22
22
  defineConfig: () => import_cli.defineConfig,
23
+ getCreateRsbuildDefaultOptions: () => import_createRsbuild.getCreateRsbuildDefaultOptions,
23
24
  mergeRsbuildConfig: () => import_shared.mergeRsbuildConfig
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
@@ -30,5 +31,6 @@ var import_cli = require("./cli");
30
31
  0 && (module.exports = {
31
32
  createRsbuild,
32
33
  defineConfig,
34
+ getCreateRsbuildDefaultOptions,
33
35
  mergeRsbuildConfig
34
36
  });
@@ -1,2 +0,0 @@
1
- import { DefaultRsbuildPlugin } from '@rsbuild/shared';
2
- export declare function pluginCheckSyntax(): DefaultRsbuildPlugin;
@@ -1,78 +1 @@
1
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 checkSyntax_exports = {};
30
- __export(checkSyntax_exports, {
31
- pluginCheckSyntax: () => pluginCheckSyntax
32
- });
33
- module.exports = __toCommonJS(checkSyntax_exports);
34
- var import_shared = require("@rsbuild/shared");
35
- function pluginCheckSyntax() {
36
- return {
37
- name: "plugin-check-syntax",
38
- setup(api) {
39
- api.modifyBundlerChain(async (chain, { isProd, target }) => {
40
- const config = api.getNormalizedConfig();
41
- const { checkSyntax } = config.security;
42
- if (!isProd || ["node", "web-worker"].includes(target) || !checkSyntax) {
43
- return;
44
- }
45
- const targets = await getCheckTargets(
46
- api.context,
47
- config,
48
- target,
49
- checkSyntax
50
- );
51
- const { CheckSyntaxPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
52
- chain.plugin(CheckSyntaxPlugin.name).use(CheckSyntaxPlugin, [
53
- {
54
- targets,
55
- rootPath: api.context.rootPath,
56
- ...typeof checkSyntax === "object" ? checkSyntax : {}
57
- }
58
- ]);
59
- });
60
- }
61
- };
62
- }
63
- async function getCheckTargets(rsbuildContext, rsbuildConfig, rsbuildTarget, checkSyntax) {
64
- var _a, _b;
65
- const browserslist = (_a = await (0, import_shared.getBrowserslistWithDefault)(
66
- rsbuildContext.rootPath,
67
- rsbuildConfig,
68
- rsbuildTarget
69
- )) != null ? _a : import_shared.DEFAULT_BROWSERSLIST[rsbuildTarget];
70
- if (checkSyntax === true) {
71
- return browserslist;
72
- }
73
- return (_b = checkSyntax.targets) != null ? _b : browserslist;
74
- }
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- pluginCheckSyntax
78
- });
@@ -38,7 +38,6 @@ var import_fs_extra = require("@rsbuild/shared/fs-extra");
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  var import_filesize = __toESM(require("filesize"));
40
40
  var import_gzip_size = __toESM(require("gzip-size"));
41
- var import_strip_ansi = __toESM(require("strip-ansi"));
42
41
  const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
43
42
  const getAssetColor = (size) => {
44
43
  if (size > 300 * 1e3) {
@@ -98,11 +97,9 @@ async function printFileSizes(stats, distPath) {
98
97
  return;
99
98
  }
100
99
  assets.sort((a, b) => b.size - a.size);
101
- const longestLabelLength = Math.max(
102
- ...assets.map((a) => (0, import_strip_ansi.default)(a.sizeLabel).length)
103
- );
100
+ const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
104
101
  const longestFileLength = Math.max(
105
- ...assets.map((a) => (0, import_strip_ansi.default)(a.folder + import_path.default.sep + a.name).length)
102
+ ...assets.map((a) => (a.folder + import_path.default.sep + a.name).length)
106
103
  );
107
104
  import_shared.logger.info(`Production file sizes:
108
105
  `);
@@ -112,8 +109,8 @@ async function printFileSizes(stats, distPath) {
112
109
  assets.forEach((asset) => {
113
110
  let { sizeLabel } = asset;
114
111
  const { name, folder, gzipSizeLabel } = asset;
115
- const fileNameLength = (0, import_strip_ansi.default)(folder + import_path.default.sep + name).length;
116
- const sizeLength = (0, import_strip_ansi.default)(sizeLabel).length;
112
+ const fileNameLength = (folder + import_path.default.sep + name).length;
113
+ const sizeLength = sizeLabel.length;
117
114
  totalSize += asset.size;
118
115
  totalGzipSize += asset.gzippedSize;
119
116
  if (sizeLength < longestLabelLength) {
@@ -51,7 +51,6 @@ const plugins = {
51
51
  image: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("image", import_shared.IMAGE_EXTENSIONS)),
52
52
  media: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("media", import_shared.MEDIA_EXTENSIONS)),
53
53
  assetsRetry: () => Promise.resolve().then(() => __toESM(require("./assetsRetry"))).then((m) => m.pluginAssetsRetry()),
54
- checkSyntax: () => Promise.resolve().then(() => __toESM(require("./checkSyntax"))).then((m) => m.pluginCheckSyntax()),
55
54
  rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.pluginRem()),
56
55
  wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
57
56
  moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
@@ -23,14 +23,10 @@ __export(tools_exports, {
23
23
  module.exports = __toCommonJS(tools_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const toolsConfigSchema = import_shared.sharedToolsConfigSchema.extend({
26
- sass: import_shared.z.chained(import_shared.z.any(), import_shared.z.object({ addExcludes: import_shared.FileFilterUtilSchema })),
27
- less: import_shared.z.chained(import_shared.z.any(), import_shared.z.object({ addExcludes: import_shared.FileFilterUtilSchema })),
28
26
  htmlPlugin: import_shared.z.chained(
29
27
  import_shared.z.any(),
30
28
  import_shared.z.object({ entryName: import_shared.z.string(), entryValue: import_shared.z.any() })
31
29
  ),
32
- postcss: import_shared.z.chained(import_shared.z.any(), import_shared.z.object({ addPlugins: import_shared.z.function() })),
33
- autoprefixer: import_shared.z.chained(import_shared.z.any()),
34
30
  rspack: import_shared.z.chained(import_shared.z.any(), import_shared.z.any())
35
31
  });
36
32
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,6 +1,5 @@
1
1
  import type { ModernDevServerOptions } from '@modern-js/server';
2
2
  import type { Compiler, MultiCompiler } from '@rspack/core';
3
3
  type DevMiddlewareOptions = ModernDevServerOptions['devMiddleware'];
4
- export declare function getHotRuntimeEntries(compiler: Compiler): string[];
5
- export declare const getDevMiddleware: (compiler: Compiler | MultiCompiler) => NonNullable<DevMiddlewareOptions>;
4
+ export declare const getDevMiddleware: (multiCompiler: Compiler | MultiCompiler) => NonNullable<DevMiddlewareOptions>;
6
5
  export {};
@@ -28,50 +28,38 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var devMiddleware_exports = {};
30
30
  __export(devMiddleware_exports, {
31
- getDevMiddleware: () => getDevMiddleware,
32
- getHotRuntimeEntries: () => getHotRuntimeEntries
31
+ getDevMiddleware: () => getDevMiddleware
33
32
  });
34
33
  module.exports = __toCommonJS(devMiddleware_exports);
35
34
  var import_webpack_dev_middleware = __toESM(require("@rsbuild/shared/webpack-dev-middleware"));
36
35
  var import_shared = require("@rsbuild/shared");
37
- function getHotRuntimeEntries(compiler) {
38
- var _a, _b, _c, _d, _e;
39
- const hot = (_b = (_a = compiler.options.devServer) == null ? void 0 : _a.hot) != null ? _b : true;
40
- const refresh = (_e = (_d = (_c = compiler.options.builtins) == null ? void 0 : _c.react) == null ? void 0 : _d.refresh) != null ? _e : true;
41
- if (hot && refresh) {
42
- const reactRefreshEntryPath = require.resolve("@rspack/dev-client/react-refresh-entry");
43
- return [reactRefreshEntryPath];
44
- }
45
- return [];
46
- }
47
36
  function applyHMREntry(compiler, clientPath) {
48
37
  if (!(0, import_shared.isClientCompiler)(compiler)) {
49
38
  return;
50
39
  }
51
- const hotRuntimeEntires = getHotRuntimeEntries(compiler);
52
- const entires = [...hotRuntimeEntires, clientPath];
53
40
  for (const key in compiler.options.entry) {
54
41
  compiler.options.entry[key].import = [
55
- ...entires,
42
+ clientPath,
56
43
  ...compiler.options.entry[key].import || []
57
44
  ];
58
45
  }
59
46
  }
60
- const getDevMiddleware = (compiler) => (options) => {
47
+ const getDevMiddleware = (multiCompiler) => (options) => {
61
48
  const { hmrClientPath, callbacks, ...restOptions } = options;
62
- if (compiler.compilers) {
63
- compiler.compilers.forEach((compiler2) => {
64
- hmrClientPath && applyHMREntry(compiler2, hmrClientPath);
65
- (0, import_shared.setupServerHooks)(compiler2, callbacks);
66
- });
67
- } else {
68
- hmrClientPath && applyHMREntry(compiler, hmrClientPath);
49
+ const setupCompiler = (compiler) => {
50
+ if (hmrClientPath) {
51
+ applyHMREntry(compiler, hmrClientPath);
52
+ }
69
53
  (0, import_shared.setupServerHooks)(compiler, callbacks);
54
+ };
55
+ if (multiCompiler.compilers) {
56
+ multiCompiler.compilers.forEach(setupCompiler);
57
+ } else {
58
+ setupCompiler(multiCompiler);
70
59
  }
71
- return (0, import_webpack_dev_middleware.default)(compiler, restOptions);
60
+ return (0, import_webpack_dev_middleware.default)(multiCompiler, restOptions);
72
61
  };
73
62
  // Annotate the CommonJS export names for ESM import in node:
74
63
  0 && (module.exports = {
75
- getDevMiddleware,
76
- getHotRuntimeEntries
64
+ getDevMiddleware
77
65
  });
@@ -94,7 +94,7 @@ const pluginSwc = () => ({
94
94
  swcConfig.env.mode = void 0;
95
95
  } else {
96
96
  swcConfig.env.mode = polyfillMode;
97
- await applyCoreJs(swcConfig, chain, rule);
97
+ await applyCoreJs(swcConfig, chain, rule, polyfillMode);
98
98
  }
99
99
  }
100
100
  rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(swcConfig);
@@ -114,11 +114,14 @@ const pluginSwc = () => ({
114
114
  });
115
115
  }
116
116
  });
117
- async function applyCoreJs(swcConfig, chain, rule) {
117
+ async function applyCoreJs(swcConfig, chain, rule, polyfillMode) {
118
118
  const coreJsPath = require.resolve("core-js/package.json");
119
119
  const version = (0, import_shared.getCoreJsVersion)(coreJsPath);
120
120
  const coreJsDir = path.dirname(coreJsPath);
121
121
  swcConfig.env.coreJs = version;
122
+ if (polyfillMode === "usage") {
123
+ swcConfig.env.shippedProposals = true;
124
+ }
122
125
  chain.resolve.alias.merge({
123
126
  "core-js": coreJsDir
124
127
  });
@@ -72,7 +72,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
72
72
  plugins.inlineChunk(),
73
73
  plugins.bundleAnalyzer(),
74
74
  plugins.assetsRetry(),
75
- plugins.checkSyntax(),
76
75
  plugins.networkPerformance(),
77
76
  plugins.preloadOrPrefetch(),
78
77
  plugins.performance(),
@@ -48,6 +48,7 @@ export type BuiltinSwcLoaderOptions = {
48
48
  include?: string[];
49
49
  exclude?: string[];
50
50
  coreJs?: string;
51
+ shippedProposals?: boolean;
51
52
  targets?: any;
52
53
  };
53
54
  isModule?: boolean | 'unknown';
package/package.json CHANGED
@@ -1,25 +1,17 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
+ "version": "0.0.12",
3
4
  "description": "Unleash the power of Rspack with the out-of-the-box build tool.",
4
5
  "homepage": "https://rsbuild.dev",
6
+ "bugs": {
7
+ "url": "https://github.com/web-infra-dev/rsbuild/issues"
8
+ },
5
9
  "repository": {
6
10
  "type": "git",
7
11
  "url": "https://github.com/web-infra-dev/rsbuild",
8
12
  "directory": "packages/core"
9
13
  },
10
- "bugs": {
11
- "url": "https://github.com/web-infra-dev/rsbuild/issues"
12
- },
13
- "bin": {
14
- "rsbuild": "./bin/rsbuild.js"
15
- },
16
- "engines": {
17
- "node": ">=14.0.0"
18
- },
19
14
  "license": "MIT",
20
- "version": "0.0.10",
21
- "types": "./dist/index.d.ts",
22
- "main": "./dist/index.js",
23
15
  "exports": {
24
16
  ".": {
25
17
  "types": "./dist/index.d.ts",
@@ -42,6 +34,8 @@
42
34
  "default": "./dist/rspack-provider/index.js"
43
35
  }
44
36
  },
37
+ "main": "./dist/index.js",
38
+ "types": "./dist/index.d.ts",
45
39
  "typesVersions": {
46
40
  "*": {
47
41
  "cli": [
@@ -58,19 +52,16 @@
58
52
  ]
59
53
  }
60
54
  },
55
+ "bin": {
56
+ "rsbuild": "./bin/rsbuild.js"
57
+ },
61
58
  "files": [
62
59
  "bin",
63
60
  "dist"
64
61
  ],
65
- "publishConfig": {
66
- "registry": "https://registry.npmjs.org/",
67
- "access": "public",
68
- "provenance": true
69
- },
70
62
  "dependencies": {
71
63
  "@modern-js/server": "^2.39.0",
72
64
  "@rspack/core": "0.3.8",
73
- "@rspack/dev-client": "0.3.8",
74
65
  "@rspack/plugin-html": "0.3.8",
75
66
  "commander": "^10.0.1",
76
67
  "filesize": "^8.0.7",
@@ -82,18 +73,25 @@
82
73
  "postcss": "8.4.31",
83
74
  "rspack-manifest-plugin": "5.0.0-alpha0",
84
75
  "semver": "^7.5.4",
85
- "strip-ansi": "^6.0.1",
86
- "webpack": "^5.88.1",
87
- "@rsbuild/shared": "0.0.10"
76
+ "webpack": "^5.89.0",
77
+ "@rsbuild/shared": "0.0.12"
88
78
  },
89
79
  "devDependencies": {
90
80
  "@types/lodash": "^4.14.200",
91
81
  "@types/node": "^16",
92
82
  "@types/semver": "^7.5.4",
93
- "typescript": "^5"
83
+ "typescript": "^5.2.2"
84
+ },
85
+ "engines": {
86
+ "node": ">=14.0.0"
87
+ },
88
+ "publishConfig": {
89
+ "access": "public",
90
+ "provenance": true,
91
+ "registry": "https://registry.npmjs.org/"
94
92
  },
95
93
  "scripts": {
96
- "dev": "modern build --watch",
97
- "build": "modern build"
94
+ "build": "modern build",
95
+ "dev": "modern build --watch"
98
96
  }
99
97
  }