@rsbuild/core 0.5.8 → 0.6.0

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.
Files changed (39) hide show
  1. package/dist/cli/commands.js +1 -1
  2. package/dist/cli/prepare.js +1 -1
  3. package/dist/client/hmr/createSocketUrl.d.ts +2 -2
  4. package/dist/client/hmr/index.d.ts +6 -0
  5. package/dist/client/hmr.mjs +11 -275
  6. package/dist/client/overlay.d.ts +1 -0
  7. package/dist/client/overlay.mjs +250 -0
  8. package/dist/config.d.ts +8 -1
  9. package/dist/config.js +154 -3
  10. package/dist/createRsbuild.js +1 -1
  11. package/dist/{provider/htmlPluginUtil.js → htmlUtils.js} +3 -3
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/internal.d.ts +20 -0
  15. package/dist/{provider/index.js → internal.js} +28 -18
  16. package/dist/plugins/fileSize.js +2 -0
  17. package/dist/provider/createCompiler.js +1 -1
  18. package/dist/provider/createContext.js +2 -2
  19. package/dist/provider/devMiddleware.js +19 -6
  20. package/dist/provider/initConfigs.js +1 -1
  21. package/dist/provider/plugins/css.js +11 -5
  22. package/dist/provider/rspackConfig.js +2 -2
  23. package/dist/provider/shared.d.ts +4 -3
  24. package/dist/provider/shared.js +27 -8
  25. package/dist/rspack/HtmlAppIconPlugin.js +2 -2
  26. package/dist/rspack/HtmlBasicPlugin.js +2 -2
  27. package/dist/rspack/HtmlCrossOriginPlugin.js +2 -2
  28. package/dist/rspack/HtmlNetworkPerformancePlugin.js +2 -2
  29. package/dist/rspack/HtmlNoncePlugin.js +2 -2
  30. package/dist/rspack/InlineChunkHtmlPlugin.js +2 -2
  31. package/dist/rspack/preload/HtmlPreloadOrPrefetchPlugin.js +3 -3
  32. package/dist/server/compilerDevMiddleware.d.ts +2 -2
  33. package/dist/server/compilerDevMiddleware.js +23 -15
  34. package/package.json +9 -13
  35. package/dist/client/hmr/overlay.d.ts +0 -2
  36. package/dist/provider/config.d.ts +0 -8
  37. package/dist/provider/config.js +0 -175
  38. package/dist/provider/index.d.ts +0 -14
  39. /package/dist/{provider/htmlPluginUtil.d.ts → htmlUtils.d.ts} +0 -0
@@ -28,7 +28,7 @@ __export(InlineChunkHtmlPlugin_exports, {
28
28
  module.exports = __toCommonJS(InlineChunkHtmlPlugin_exports);
29
29
  var import_node_path = require("node:path");
30
30
  var import_shared = require("@rsbuild/shared");
31
- var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
31
+ var import_htmlUtils = require("../htmlUtils");
32
32
  class InlineChunkHtmlPlugin {
33
33
  constructor({
34
34
  styleTests,
@@ -160,7 +160,7 @@ class InlineChunkHtmlPlugin {
160
160
  compiler.hooks.compilation.tap(this.name, (compilation) => {
161
161
  const publicPath = (0, import_shared.getPublicPathFromCompiler)(compiler);
162
162
  const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
163
- const hooks = (0, import_htmlPluginUtil.getHTMLPlugin)().getHooks(compilation);
163
+ const hooks = (0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation);
164
164
  hooks.alterAssetTagGroups.tap(this.name, (assets) => {
165
165
  assets.headTags = assets.headTags.map(tagFunction);
166
166
  assets.bodyTags = assets.bodyTags.map(tagFunction);
@@ -28,7 +28,7 @@ __export(HtmlPreloadOrPrefetchPlugin_exports, {
28
28
  module.exports = __toCommonJS(HtmlPreloadOrPrefetchPlugin_exports);
29
29
  var import_shared = require("@rsbuild/shared");
30
30
  var import_helpers = require("./helpers");
31
- var import_htmlPluginUtil = require("../../provider/htmlPluginUtil");
31
+ var import_htmlUtils = require("../../htmlUtils");
32
32
  /**
33
33
  * @license
34
34
  * Copyright 2018 Google Inc.
@@ -137,7 +137,7 @@ class HtmlPreloadOrPrefetchPlugin {
137
137
  }
138
138
  apply(compiler) {
139
139
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
140
- (0, import_htmlPluginUtil.getHTMLPlugin)().getHooks(compilation).beforeAssetTagGeneration.tap(
140
+ (0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).beforeAssetTagGeneration.tap(
141
141
  `HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
142
142
  (htmlPluginData) => {
143
143
  this.resourceHints = generateLinks(
@@ -150,7 +150,7 @@ class HtmlPreloadOrPrefetchPlugin {
150
150
  return htmlPluginData;
151
151
  }
152
152
  );
153
- (0, import_htmlPluginUtil.getHTMLPlugin)().getHooks(compilation).alterAssetTags.tap(
153
+ (0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).alterAssetTags.tap(
154
154
  `HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
155
155
  (htmlPluginData) => {
156
156
  if (this.resourceHints) {
@@ -16,8 +16,8 @@ type Options = {
16
16
  */
17
17
  export declare class CompilerDevMiddleware {
18
18
  middleware: DevMiddlewareAPI;
19
- private devOptions;
20
- private serverOptions;
19
+ private devConfig;
20
+ private serverConfig;
21
21
  private devMiddleware;
22
22
  private publicPaths;
23
23
  private socketServer;
@@ -39,23 +39,27 @@ module.exports = __toCommonJS(compilerDevMiddleware_exports);
39
39
  var import_socketServer = require("./socketServer");
40
40
  const noop = () => {
41
41
  };
42
- function getHMRClientPath(client = {}) {
43
- const params = Object.entries(client).reduce((query, [key, value]) => {
44
- return value ? `${query}&${key}=${value}` : `${query}`;
45
- }, "");
46
- const clientEntry = `${require.resolve("@rsbuild/core/client/hmr")}?${params}`;
47
- return clientEntry;
42
+ function getClientPaths(devConfig) {
43
+ const clientPaths = [];
44
+ if (!devConfig.hmr && !devConfig.liveReload) {
45
+ return clientPaths;
46
+ }
47
+ clientPaths.push(require.resolve("@rsbuild/core/client/hmr"));
48
+ if (devConfig.client?.overlay) {
49
+ clientPaths.push(`${require.resolve("@rsbuild/core/client/overlay")}`);
50
+ }
51
+ return clientPaths;
48
52
  }
49
53
  class CompilerDevMiddleware {
50
54
  constructor({ dev, server, devMiddleware, publicPaths }) {
51
55
  __publicField(this, "middleware");
52
- __publicField(this, "devOptions");
53
- __publicField(this, "serverOptions");
56
+ __publicField(this, "devConfig");
57
+ __publicField(this, "serverConfig");
54
58
  __publicField(this, "devMiddleware");
55
59
  __publicField(this, "publicPaths");
56
60
  __publicField(this, "socketServer");
57
- this.devOptions = dev;
58
- this.serverOptions = server;
61
+ this.devConfig = dev;
62
+ this.serverConfig = server;
59
63
  this.publicPaths = publicPaths;
60
64
  this.socketServer = new import_socketServer.SocketServer(dev);
61
65
  this.devMiddleware = devMiddleware;
@@ -78,7 +82,7 @@ class CompilerDevMiddleware {
78
82
  this.socketServer.sockWrite(type, data);
79
83
  }
80
84
  setupDevMiddleware(devMiddleware, publicPaths) {
81
- const { devOptions, serverOptions } = this;
85
+ const { devConfig, serverConfig } = this;
82
86
  const callbacks = {
83
87
  onInvalid: () => {
84
88
  this.socketServer.sockWrite("invalid");
@@ -87,15 +91,19 @@ class CompilerDevMiddleware {
87
91
  this.socketServer.updateStats(stats);
88
92
  }
89
93
  };
90
- const injectClient = this.devOptions.hmr || this.devOptions.liveReload;
94
+ const clientPaths = getClientPaths(devConfig);
91
95
  const middleware = devMiddleware({
92
- headers: serverOptions.headers,
96
+ headers: serverConfig.headers,
93
97
  publicPath: "/",
94
98
  stats: false,
95
99
  callbacks,
96
- hmrClientPath: injectClient ? getHMRClientPath(devOptions.client) : void 0,
100
+ clientPaths,
101
+ clientConfig: devConfig.client,
102
+ writeToDisk: devConfig.writeToDisk,
97
103
  serverSideRender: true,
98
- writeToDisk: devOptions.writeToDisk
104
+ // weak is enough in dev
105
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests#weak_validation
106
+ etag: "weak"
99
107
  });
100
108
  const warp = async (req, res, next) => {
101
109
  const { url } = req;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -18,21 +18,17 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "default": "./dist/index.js"
20
20
  },
21
- "./server": {
22
- "types": "./dist/server/index.d.ts",
23
- "default": "./dist/server/index.js"
24
- },
25
21
  "./client/hmr": {
26
22
  "types": "./dist/client/hmr/index.d.ts",
27
23
  "default": "./dist/client/hmr.mjs"
28
24
  },
29
- "./plugins/*": {
30
- "types": "./dist/plugins/*.d.ts",
31
- "default": "./dist/plugins/*.js"
25
+ "./client/overlay": {
26
+ "types": "./dist/client/overlay.d.ts",
27
+ "default": "./dist/client/overlay.mjs"
32
28
  },
33
- "./provider": {
34
- "types": "./dist/provider/index.d.ts",
35
- "default": "./dist/provider/index.js"
29
+ "./internal": {
30
+ "types": "./dist/internal.d.ts",
31
+ "default": "./dist/internal.js"
36
32
  },
37
33
  "./types": {
38
34
  "types": "./types.d.ts"
@@ -52,12 +48,12 @@
52
48
  "types.d.ts"
53
49
  ],
54
50
  "dependencies": {
55
- "@rspack/core": "0.5.9-canary-8778e17-20240403045016",
51
+ "@rspack/core": "0.6.0",
56
52
  "@swc/helpers": "0.5.3",
57
53
  "core-js": "~3.36.0",
58
54
  "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
59
55
  "postcss": "^8.4.38",
60
- "@rsbuild/shared": "0.5.8"
56
+ "@rsbuild/shared": "0.6.0"
61
57
  },
62
58
  "devDependencies": {
63
59
  "@types/node": "16.x",
@@ -1,2 +0,0 @@
1
- export declare function createOverlay(err: string[]): void;
2
- export declare function clearOverlay(): void;
@@ -1,8 +0,0 @@
1
- import type { RsbuildConfig, NormalizedConfig } from '@rsbuild/shared';
2
- export declare const withDefaultConfig: (rootPath: string, config: RsbuildConfig) => Promise<RsbuildConfig>;
3
- /** #__PURE__
4
- * 1. May used by multiple plugins.
5
- * 2. Object value that should not be empty.
6
- * 3. Meaningful and can be filled by constant value.
7
- */
8
- export declare const normalizeConfig: (config: RsbuildConfig) => NormalizedConfig;
@@ -1,175 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var config_exports = {};
20
- __export(config_exports, {
21
- normalizeConfig: () => normalizeConfig,
22
- withDefaultConfig: () => withDefaultConfig
23
- });
24
- module.exports = __toCommonJS(config_exports);
25
- var import_node_path = require("node:path");
26
- var import_shared = require("@rsbuild/shared");
27
- var import_mergeConfig = require("../mergeConfig");
28
- const getDefaultDevConfig = () => ({
29
- hmr: true,
30
- liveReload: true,
31
- assetPrefix: import_shared.DEFAULT_ASSET_PREFIX,
32
- startUrl: false
33
- });
34
- const getDefaultServerConfig = () => ({
35
- port: import_shared.DEFAULT_PORT,
36
- host: import_shared.DEFAULT_DEV_HOST,
37
- htmlFallback: "index",
38
- compress: true,
39
- printUrls: true,
40
- strictPort: false,
41
- publicDir: {
42
- name: "public",
43
- copyOnBuild: true
44
- }
45
- });
46
- const getDefaultSourceConfig = () => ({
47
- alias: {},
48
- define: {},
49
- aliasStrategy: "prefer-tsconfig",
50
- preEntry: [],
51
- decorators: {
52
- version: "legacy"
53
- }
54
- });
55
- const getDefaultHtmlConfig = () => ({
56
- meta: {
57
- charset: { charset: "UTF-8" },
58
- viewport: "width=device-width, initial-scale=1.0"
59
- },
60
- title: "Rsbuild App",
61
- inject: "head",
62
- mountId: import_shared.DEFAULT_MOUNT_ID,
63
- crossorigin: false,
64
- outputStructure: "flat",
65
- scriptLoading: "defer"
66
- });
67
- const getDefaultSecurityConfig = () => ({
68
- nonce: ""
69
- });
70
- const getDefaultToolsConfig = () => ({
71
- cssExtract: {
72
- loaderOptions: {},
73
- pluginOptions: {}
74
- }
75
- });
76
- const getDefaultPerformanceConfig = () => ({
77
- profile: false,
78
- buildCache: true,
79
- printFileSize: true,
80
- removeConsole: false,
81
- removeMomentLocale: false,
82
- chunkSplit: {
83
- strategy: "split-by-experience"
84
- }
85
- });
86
- const getDefaultOutputConfig = () => ({
87
- targets: ["web"],
88
- distPath: {
89
- root: import_shared.ROOT_DIST_DIR,
90
- js: import_shared.JS_DIST_DIR,
91
- css: import_shared.CSS_DIST_DIR,
92
- svg: import_shared.SVG_DIST_DIR,
93
- font: import_shared.FONT_DIST_DIR,
94
- html: import_shared.HTML_DIST_DIR,
95
- wasm: import_shared.WASM_DIST_DIR,
96
- image: import_shared.IMAGE_DIST_DIR,
97
- media: import_shared.MEDIA_DIST_DIR,
98
- server: import_shared.SERVER_DIST_DIR,
99
- worker: import_shared.SERVICE_WORKER_DIST_DIR
100
- },
101
- assetPrefix: import_shared.DEFAULT_ASSET_PREFIX,
102
- filename: {},
103
- charset: "ascii",
104
- polyfill: "usage",
105
- dataUriLimit: {
106
- svg: import_shared.DEFAULT_DATA_URL_SIZE,
107
- font: import_shared.DEFAULT_DATA_URL_SIZE,
108
- image: import_shared.DEFAULT_DATA_URL_SIZE,
109
- media: import_shared.DEFAULT_DATA_URL_SIZE
110
- },
111
- legalComments: "linked",
112
- injectStyles: false,
113
- minify: true,
114
- sourceMap: {
115
- js: void 0,
116
- css: false
117
- },
118
- filenameHash: true,
119
- enableCssModuleTSDeclaration: false,
120
- inlineScripts: false,
121
- inlineStyles: false,
122
- cssModules: {
123
- auto: true,
124
- exportLocalsConvention: "camelCase"
125
- }
126
- });
127
- const createDefaultConfig = () => ({
128
- dev: getDefaultDevConfig(),
129
- server: getDefaultServerConfig(),
130
- html: getDefaultHtmlConfig(),
131
- source: getDefaultSourceConfig(),
132
- output: getDefaultOutputConfig(),
133
- tools: getDefaultToolsConfig(),
134
- security: getDefaultSecurityConfig(),
135
- performance: getDefaultPerformanceConfig()
136
- });
137
- function getDefaultEntry(root) {
138
- const files = [
139
- // Most projects are using typescript now.
140
- // So we put `.ts` as the first one to improve performance.
141
- "ts",
142
- "js",
143
- "tsx",
144
- "jsx",
145
- ".mjs",
146
- ".cjs"
147
- ].map((ext) => (0, import_node_path.join)(root, `src/index.${ext}`));
148
- const entryFile = (0, import_shared.findExists)(files);
149
- if (entryFile) {
150
- return {
151
- index: entryFile
152
- };
153
- }
154
- return {};
155
- }
156
- const withDefaultConfig = async (rootPath, config) => {
157
- const merged = (0, import_mergeConfig.mergeRsbuildConfig)(createDefaultConfig(), config);
158
- merged.source || (merged.source = {});
159
- if (!merged.source.entry) {
160
- merged.source.entry = getDefaultEntry(rootPath);
161
- }
162
- if (!merged.source.tsconfigPath) {
163
- const tsconfigPath = (0, import_node_path.join)(rootPath, import_shared.TS_CONFIG_FILE);
164
- if (await (0, import_shared.isFileExists)(tsconfigPath)) {
165
- merged.source.tsconfigPath = tsconfigPath;
166
- }
167
- }
168
- return merged;
169
- };
170
- const normalizeConfig = (config) => (0, import_mergeConfig.mergeRsbuildConfig)(createDefaultConfig(), config);
171
- // Annotate the CommonJS export names for ESM import in node:
172
- 0 && (module.exports = {
173
- normalizeConfig,
174
- withDefaultConfig
175
- });
@@ -1,14 +0,0 @@
1
- export { rspackProvider } from './provider';
2
- export type { Rspack, RspackConfig } from '@rsbuild/shared';
3
- export { createContext, createPublicContext } from './createContext';
4
- export { initPlugins, createPluginManager } from '../pluginManager';
5
- export { initHooks, type Hooks } from '../initHooks';
6
- export { initRsbuildConfig } from './initConfigs';
7
- export { getPluginAPI } from './initPlugins';
8
- export { applyBaseCSSRule, applyCSSModuleRule } from './plugins/css';
9
- export type { InternalContext } from '../types';
10
- export { setHTMLPlugin, getHTMLPlugin } from './htmlPluginUtil';
11
- export { formatStats } from './shared';
12
- export { getChainUtils } from './rspackConfig';
13
- export { applySwcDecoratorConfig } from './plugins/swc';
14
- export { getDevMiddleware } from './devMiddleware';