@rsbuild/core 0.6.2 → 0.6.4

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.
@@ -39,7 +39,7 @@ const applyServerOptions = (command) => {
39
39
  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");
40
40
  };
41
41
  function runCli() {
42
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.6.2");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.6.4");
43
43
  const devCommand = import_commander.program.command("dev");
44
44
  const buildCommand = import_commander.program.command("build");
45
45
  const previewCommand = import_commander.program.command("preview");
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.6.2"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.6.4"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,7 +1,4 @@
1
- declare let createOverlay: undefined | ((err: string[]) => void);
2
- declare let clearOverlay: undefined | (() => void);
3
1
  export declare const registerOverlay: (options: {
4
2
  createOverlay: (err: string[]) => void;
5
3
  clearOverlay: () => void;
6
4
  }) => void;
7
- export {};
@@ -164,10 +164,10 @@ function linkedText(root, selector, text) {
164
164
  el.appendChild(document.createTextNode(frag));
165
165
  }
166
166
  var overlayTemplate = '\n<style>\n.root {\n position: fixed;\n z-index: 9999;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n margin: 0;\n background: rgba(0, 0, 0, 0.66);\n cursor: pointer;\n}\n.container {\n font-family: Menlo, Consolas, monospace;\n line-height: 1.6;\n width: 800px;\n max-width: 85%;\n color: #d8d8d8;\n margin: 32px auto;\n padding: 32px 40px;\n position: relative;\n background: #181818;\n border-radius: 24px;\n box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);\n overflow: hidden;\n direction: ltr;\n text-align: left;\n box-sizing: border-box;\n cursor: default;\n}\n.title {\n margin: 0 0 20px;\n padding-bottom: 12px;\n font-size: 17px;\n font-weight: 600;\n color: #fc5e5e;\n border-bottom: 2px solid rgba(252,94,94,.66);\n}\n.content {\n margin: 0;\n font-size: 14px;\n font-family: inherit;\n overflow-x: scroll;\n scrollbar-width: none;\n color: #b8b8b8;\n}\n.content::-webkit-scrollbar {\n display: none;\n}\n.file-link {\n cursor: pointer;\n color: #27caca;\n text-decoration: underline;\n &:hover {\n opacity: 0.8;\n }\n &:active {\n opacity: 0.6;\n }\n}\n.close {\n position: absolute;\n top: 27px;\n right: 32px;\n width: 32px;\n height: 32px;\n cursor: pointer;\n}\n.close:hover {\n opacity: 0.8;\n}\n.close:active {\n opacity: 0.6;\n}\n.close:before,\n.close:after {\n position: absolute;\n left: 16px;\n top: 8px;\n content: \' \';\n height: 18px;\n width: 2px;\n border-radius: 4px;\n background-color: #b8b8b8;\n}\n.close:before {\n transform: rotate(45deg);\n}\n.close:after {\n transform: rotate(-45deg);\n}\n.footer {\n font-size: 12px;\n color: #7e6a92;\n margin-top: 20px;\n padding-top: 12px;\n border-top: 2px solid rgba(126,106,146,.6);\n}\n.footer p {\n margin: 4px 0 0;\n}\n.footer span {\n color: #a88dc3;\n}\n</style>\n\n<div class="root">\n <div class="container">\n <div class="close"></div>\n <p class="title">Compilation failed</p>\n <pre class="content"></pre>\n <footer class="footer">\n <p><span>Fix error</span>, click outside, or press Esc to close the overlay.</p>\n <p>Disable overlay by setting Rsbuild\'s <span>dev.client.overlay</span> config to false.<p>\n </footer>\n </div>\n</div>\n';
167
- var _globalThis_HTMLElement = globalThis.HTMLElement, HTMLElement = _globalThis_HTMLElement === void 0 ? function HTMLElement() {
167
+ var _ref = typeof window !== "undefined" ? window : globalThis, _ref_HTMLElement = _ref.HTMLElement, HTMLElement = _ref_HTMLElement === void 0 ? function HTMLElement() {
168
168
  "use strict";
169
169
  _class_call_check(this, HTMLElement);
170
- } : _globalThis_HTMLElement, customElements = globalThis.customElements;
170
+ } : _ref_HTMLElement, customElements = _ref.customElements;
171
171
  var ErrorOverlay = /*#__PURE__*/ function(HTMLElement) {
172
172
  "use strict";
173
173
  _inherits(ErrorOverlay, HTMLElement);
package/dist/config.js CHANGED
@@ -140,7 +140,8 @@ const getDefaultOutputConfig = () => ({
140
140
  cssModules: {
141
141
  auto: true,
142
142
  exportLocalsConvention: "camelCase"
143
- }
143
+ },
144
+ emitAssets: () => true
144
145
  });
145
146
  const createDefaultConfig = () => ({
146
147
  dev: getDefaultDevConfig(),
@@ -160,8 +161,8 @@ function getDefaultEntry(root) {
160
161
  "js",
161
162
  "tsx",
162
163
  "jsx",
163
- ".mjs",
164
- ".cjs"
164
+ "mjs",
165
+ "cjs"
165
166
  ].map((ext) => (0, import_node_path.join)(root, `src/index.${ext}`));
166
167
  const entryFile = (0, import_shared.findExists)(files);
167
168
  if (entryFile) {
@@ -1,5 +1,5 @@
1
1
  import { type BundlerType, type RsbuildConfig, type RsbuildContext, type NormalizedConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
2
- import type { InternalContext } from '../types';
2
+ import type { InternalContext } from './types';
3
3
  export declare function updateContextByNormalizedConfig(context: RsbuildContext, config: NormalizedConfig): void;
4
4
  export declare function createPublicContext(context: RsbuildContext): Readonly<RsbuildContext>;
5
5
  /**
@@ -25,9 +25,9 @@ __export(createContext_exports, {
25
25
  module.exports = __toCommonJS(createContext_exports);
26
26
  var import_node_path = require("node:path");
27
27
  var import_shared = require("@rsbuild/shared");
28
- var import_initHooks = require("../initHooks");
29
- var import_config = require("../config");
30
- var import_entry = require("../plugins/entry");
28
+ var import_initHooks = require("./initHooks");
29
+ var import_config = require("./config");
30
+ var import_entry = require("./plugins/entry");
31
31
  function getAbsolutePath(root, filepath) {
32
32
  return (0, import_node_path.isAbsolute)(filepath) ? filepath : (0, import_node_path.join)(root, filepath);
33
33
  }
@@ -44,7 +44,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
44
44
  const context = {
45
45
  entry: (0, import_entry.getEntryObject)(config, "web"),
46
46
  targets: config.output?.targets || [],
47
- version: "0.6.2",
47
+ version: "0.6.4",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_config = require("./config");
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  var import_mergeConfig = require("./mergeConfig");
40
40
  var import_constants = require("./constants");
41
- const version = "0.6.2";
41
+ const version = "0.6.4";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_CSS_NAME,
@@ -1,5 +1,5 @@
1
1
  import { type PluginManager, type RsbuildPluginAPI } from '@rsbuild/shared';
2
- import type { InternalContext, NormalizedConfig } from '../types';
2
+ import type { InternalContext, NormalizedConfig } from './types';
3
3
  export declare function getHTMLPathByEntry(entryName: string, config: NormalizedConfig): string;
4
4
  export declare function getPluginAPI({ context, pluginManager, }: {
5
5
  context: InternalContext;
@@ -104,11 +104,11 @@ function getPluginAPI({
104
104
  if (descriptor.resourceQuery) {
105
105
  rule.resourceQuery(descriptor.resourceQuery);
106
106
  }
107
- rule.use(id).loader((0, import_node_path.join)(__dirname, "../rspack/transformLoader")).options({ id });
107
+ rule.use(id).loader((0, import_node_path.join)(__dirname, "./rspack/transformLoader")).options({ id });
108
108
  applyTransformPlugin(chain, transformer);
109
109
  });
110
110
  };
111
- (0, import_shared.onExitProcess)(() => {
111
+ process.on("exit", () => {
112
112
  hooks.onExit.call();
113
113
  });
114
114
  return {
@@ -4,17 +4,17 @@
4
4
  * Please do not use them in your Rsbuild project or plugins.
5
5
  */
6
6
  export { rspackProvider } from './provider/provider';
7
- export { createContext, createPublicContext } from './provider/createContext';
7
+ export { createContext, createPublicContext } from './createContext';
8
8
  export { initPlugins, createPluginManager } from './pluginManager';
9
9
  export { initHooks, type Hooks } from './initHooks';
10
10
  export { initRsbuildConfig } from './provider/initConfigs';
11
- export { getPluginAPI } from './provider/initPlugins';
11
+ export { getPluginAPI } from './initPlugins';
12
12
  export { applyBaseCSSRule, applyCSSModuleRule } from './provider/plugins/css';
13
13
  export type { InternalContext } from './types';
14
14
  export { setHTMLPlugin, getHTMLPlugin } from './htmlUtils';
15
15
  export { formatStats, getStatsOptions } from './provider/shared';
16
16
  export { getChainUtils } from './provider/rspackConfig';
17
17
  export { applySwcDecoratorConfig } from './provider/plugins/swc';
18
- export { getDevMiddleware } from './provider/devMiddleware';
18
+ export { getDevMiddleware } from './server/devMiddleware';
19
19
  export { createDevServer, startProdServer } from './server';
20
20
  export { plugins } from './plugins';
package/dist/internal.js CHANGED
@@ -41,17 +41,17 @@ __export(internal_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(internal_exports);
43
43
  var import_provider = require("./provider/provider");
44
- var import_createContext = require("./provider/createContext");
44
+ var import_createContext = require("./createContext");
45
45
  var import_pluginManager = require("./pluginManager");
46
46
  var import_initHooks = require("./initHooks");
47
47
  var import_initConfigs = require("./provider/initConfigs");
48
- var import_initPlugins = require("./provider/initPlugins");
48
+ var import_initPlugins = require("./initPlugins");
49
49
  var import_css = require("./provider/plugins/css");
50
50
  var import_htmlUtils = require("./htmlUtils");
51
51
  var import_shared = require("./provider/shared");
52
52
  var import_rspackConfig = require("./provider/rspackConfig");
53
53
  var import_swc = require("./provider/plugins/swc");
54
- var import_devMiddleware = require("./provider/devMiddleware");
54
+ var import_devMiddleware = require("./server/devMiddleware");
55
55
  var import_server = require("./server");
56
56
  var import_plugins = require("./plugins");
57
57
  // Annotate the CommonJS export names for ESM import in node:
@@ -28,6 +28,7 @@ const OVERRIDE_PATH = [
28
28
  "output.inlineStyles",
29
29
  "output.cssModules.auto",
30
30
  "output.targets",
31
+ "output.emitAssets",
31
32
  "server.printUrls",
32
33
  "dev.startUrl",
33
34
  "provider"
@@ -35,22 +35,25 @@ module.exports = __toCommonJS(asset_exports);
35
35
  var import_node_path = __toESM(require("node:path"));
36
36
  var import_shared = require("@rsbuild/shared");
37
37
  const chainStaticAssetRule = ({
38
+ emit,
38
39
  rule,
39
40
  maxSize,
40
41
  filename,
41
42
  assetType
42
43
  }) => {
43
- rule.oneOf(`${assetType}-asset-url`).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", {
44
+ const generatorOptions = {
44
45
  filename
45
- });
46
+ };
47
+ if (emit === false) {
48
+ generatorOptions.emit = false;
49
+ }
50
+ rule.oneOf(`${assetType}-asset-url`).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", generatorOptions);
46
51
  rule.oneOf(`${assetType}-asset-inline`).type("asset/inline").resourceQuery(/inline/);
47
52
  rule.oneOf(`${assetType}-asset`).type("asset").parser({
48
53
  dataUrlCondition: {
49
54
  maxSize
50
55
  }
51
- }).set("generator", {
52
- filename
53
- });
56
+ }).set("generator", generatorOptions);
54
57
  };
55
58
  function getRegExpForExts(exts) {
56
59
  const matcher = exts.map((ext) => ext.trim()).map((ext) => ext.startsWith(".") ? ext.slice(1) : ext).join("|");
@@ -62,9 +65,9 @@ function getRegExpForExts(exts) {
62
65
  const pluginAsset = () => ({
63
66
  name: "rsbuild:asset",
64
67
  setup(api) {
65
- api.modifyBundlerChain((chain, { isProd }) => {
68
+ api.modifyBundlerChain((chain, { isProd, target }) => {
66
69
  const config = api.getNormalizedConfig();
67
- const createAssetRule = (assetType, exts) => {
70
+ const createAssetRule = (assetType, exts, emit2) => {
68
71
  const regExp = getRegExpForExts(exts);
69
72
  const distDir = (0, import_shared.getDistPath)(config, assetType);
70
73
  const filename = (0, import_shared.getFilename)(config, assetType, isProd);
@@ -72,16 +75,22 @@ const pluginAsset = () => ({
72
75
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
73
76
  const rule = chain.module.rule(assetType).test(regExp);
74
77
  chainStaticAssetRule({
78
+ emit: emit2,
75
79
  rule,
76
80
  maxSize,
77
81
  filename: import_node_path.default.posix.join(distDir, filename),
78
82
  assetType
79
83
  });
80
84
  };
81
- createAssetRule("image", import_shared.IMAGE_EXTENSIONS);
82
- createAssetRule("svg", ["svg"]);
83
- createAssetRule("media", [...import_shared.VIDEO_EXTENSIONS, ...import_shared.AUDIO_EXTENSIONS]);
84
- createAssetRule("font", import_shared.FONT_EXTENSIONS);
85
+ const emit = config.output.emitAssets({ target });
86
+ createAssetRule("image", import_shared.IMAGE_EXTENSIONS, emit);
87
+ createAssetRule("svg", ["svg"], emit);
88
+ createAssetRule(
89
+ "media",
90
+ [...import_shared.VIDEO_EXTENSIONS, ...import_shared.AUDIO_EXTENSIONS],
91
+ emit
92
+ );
93
+ createAssetRule("font", import_shared.FONT_EXTENSIONS, emit);
85
94
  });
86
95
  }
87
96
  });
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
6
  var __export = (target, all) => {
8
7
  for (var name in all)
9
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,48 +16,18 @@ var __copyProps = (to, from, except, desc) => {
17
16
  return to;
18
17
  };
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
19
  var moment_exports = {};
25
20
  __export(moment_exports, {
26
21
  pluginMoment: () => pluginMoment
27
22
  });
28
23
  module.exports = __toCommonJS(moment_exports);
29
- class IgnorePlugin {
30
- constructor(options) {
31
- __publicField(this, "options");
32
- this.options = options;
33
- this.checkIgnore = this.checkIgnore.bind(this);
34
- }
35
- checkIgnore(resolveData) {
36
- if ("resourceRegExp" in this.options && this.options.resourceRegExp && this.options.resourceRegExp.test(resolveData.request)) {
37
- if ("contextRegExp" in this.options && this.options.contextRegExp) {
38
- if (this.options.contextRegExp.test(resolveData.context)) {
39
- return false;
40
- }
41
- } else {
42
- return false;
43
- }
44
- }
45
- }
46
- apply(compiler) {
47
- compiler.hooks.normalModuleFactory.tap("IgnorePlugin", (nmf) => {
48
- nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
49
- });
50
- compiler.hooks.contextModuleFactory.tap("IgnorePlugin", (cmf) => {
51
- cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
52
- });
53
- }
54
- }
55
24
  const pluginMoment = () => ({
56
25
  name: "rsbuild:moment",
57
26
  setup(api) {
58
- api.modifyBundlerChain(async (chain) => {
27
+ api.modifyBundlerChain(async (chain, { bundler }) => {
59
28
  const config = api.getNormalizedConfig();
60
29
  if (config.performance.removeMomentLocale) {
61
- chain.plugin("remove-moment-locale").use(IgnorePlugin, [
30
+ chain.plugin("remove-moment-locale").use(bundler.IgnorePlugin, [
62
31
  {
63
32
  resourceRegExp: /^\.\/locale$/,
64
33
  contextRegExp: /moment$/
@@ -131,7 +131,7 @@ async function createDevMiddleware(options, customCompiler) {
131
131
  rspackConfigs
132
132
  });
133
133
  }
134
- const { getDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./devMiddleware")));
134
+ const { getDevMiddleware } = await Promise.resolve().then(() => __toESM(require("../server/devMiddleware")));
135
135
  return {
136
136
  devMiddleware: getDevMiddleware(compiler),
137
137
  compiler
@@ -24,7 +24,7 @@ __export(initConfigs_exports, {
24
24
  module.exports = __toCommonJS(initConfigs_exports);
25
25
  var import_shared = require("@rsbuild/shared");
26
26
  var import_mergeConfig = require("../mergeConfig");
27
- var import_createContext = require("./createContext");
27
+ var import_createContext = require("../createContext");
28
28
  var import_inspectConfig = require("./inspectConfig");
29
29
  var import_rspackConfig = require("./rspackConfig");
30
30
  var import_config = require("../config");
@@ -32,9 +32,9 @@ __export(provider_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(provider_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
- var import_createContext = require("./createContext");
35
+ var import_createContext = require("../createContext");
36
36
  var import_initConfigs = require("./initConfigs");
37
- var import_initPlugins = require("./initPlugins");
37
+ var import_initPlugins = require("../initPlugins");
38
38
  var import_plugins = require("../plugins");
39
39
  const rspackProvider = async ({
40
40
  pluginManager,
@@ -115,6 +115,7 @@ async function generateRspackConfig({
115
115
  const {
116
116
  BannerPlugin,
117
117
  DefinePlugin,
118
+ IgnorePlugin,
118
119
  ProvidePlugin,
119
120
  HotModuleReplacementPlugin
120
121
  } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
@@ -123,6 +124,7 @@ async function generateRspackConfig({
123
124
  bundler: {
124
125
  BannerPlugin,
125
126
  DefinePlugin,
127
+ IgnorePlugin,
126
128
  ProvidePlugin,
127
129
  HotModuleReplacementPlugin
128
130
  }
@@ -1,6 +1,6 @@
1
1
  import { isMultiCompiler, type Stats, type MultiStats, type StatsError } from '@rsbuild/shared';
2
2
  import type { StatsCompilation, StatsValue } from '@rspack/core';
3
- export declare const rspackMinVersion = "0.6.0";
3
+ export declare const rspackMinVersion = "0.6.2";
4
4
  export declare const isSatisfyRspackVersion: (originalVersion: string) => Promise<boolean>;
5
5
  export declare const getCompiledPath: (packageName: string) => string;
6
6
  export declare const BUILTIN_LOADER = "builtin:";
@@ -32,7 +32,7 @@ var import_node_path = require("node:path");
32
32
  var import_shared = require("@rsbuild/shared");
33
33
  var import_shared2 = require("@rsbuild/shared");
34
34
  var import_formatStats = require("../client/formatStats");
35
- const rspackMinVersion = "0.6.0";
35
+ const rspackMinVersion = "0.6.2";
36
36
  const compareSemver = (version1, version2) => {
37
37
  const parts1 = version1.split(".").map(Number);
38
38
  const parts2 = version2.split(".").map(Number);
@@ -29,12 +29,12 @@ export declare const getPort: ({ host, port, strictPort, tryLimits, silent, }: {
29
29
  host: string;
30
30
  port: string | number;
31
31
  strictPort: boolean;
32
- tryLimits?: number | undefined;
33
- silent?: boolean | undefined;
32
+ tryLimits?: number;
33
+ silent?: boolean;
34
34
  }) => Promise<number>;
35
35
  export declare const getServerOptions: ({ rsbuildConfig, getPortSilently, }: {
36
36
  rsbuildConfig: RsbuildConfig;
37
- getPortSilently?: boolean | undefined;
37
+ getPortSilently?: boolean;
38
38
  }) => Promise<{
39
39
  port: number;
40
40
  host: string;
@@ -43,7 +43,7 @@ export declare const getServerOptions: ({ rsbuildConfig, getPortSilently, }: {
43
43
  }>;
44
44
  export declare const getDevOptions: ({ rsbuildConfig, getPortSilently, }: {
45
45
  rsbuildConfig: RsbuildConfig;
46
- getPortSilently?: boolean | undefined;
46
+ getPortSilently?: boolean;
47
47
  }) => Promise<{
48
48
  devConfig: DevConfig;
49
49
  serverConfig: import("@rsbuild/shared").ServerConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -48,12 +48,12 @@
48
48
  "types.d.ts"
49
49
  ],
50
50
  "dependencies": {
51
- "@rspack/core": "0.6.1",
51
+ "@rspack/core": "0.6.2",
52
52
  "@swc/helpers": "0.5.3",
53
53
  "core-js": "~3.36.0",
54
54
  "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
55
55
  "postcss": "^8.4.38",
56
- "@rsbuild/shared": "0.6.2"
56
+ "@rsbuild/shared": "0.6.4"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "16.x",
File without changes
File without changes