@rsbuild/core 0.1.1 → 0.1.3

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 (54) hide show
  1. package/compiled/ws/index.d.ts +410 -0
  2. package/compiled/ws/index.js +1 -0
  3. package/compiled/ws/license +20 -0
  4. package/compiled/ws/package.json +1 -0
  5. package/dist/cli/commands.d.ts +6 -3
  6. package/dist/cli/commands.js +15 -11
  7. package/dist/cli/config.d.ts +13 -2
  8. package/dist/cli/config.js +29 -19
  9. package/dist/cli/prepare.js +1 -1
  10. package/dist/client/hmr.js +4 -4
  11. package/dist/createRsbuild.js +2 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/plugins/fileSize.js +43 -23
  14. package/dist/plugins/html.d.ts +1 -1
  15. package/dist/plugins/html.js +10 -3
  16. package/dist/plugins/nodeAddons.js +1 -1
  17. package/dist/plugins/performance.js +3 -4
  18. package/dist/plugins/splitChunks.js +3 -5
  19. package/dist/plugins/startUrl.js +6 -4
  20. package/dist/rspack-provider/core/build.js +3 -3
  21. package/dist/rspack-provider/core/createCompiler.d.ts +1 -1
  22. package/dist/rspack-provider/core/createCompiler.js +16 -0
  23. package/dist/rspack-provider/core/createContext.js +1 -1
  24. package/dist/rspack-provider/core/initConfigs.d.ts +4 -0
  25. package/dist/rspack-provider/core/initConfigs.js +16 -5
  26. package/dist/rspack-provider/core/initHooks.d.ts +4 -3
  27. package/dist/rspack-provider/core/initHooks.js +2 -0
  28. package/dist/rspack-provider/core/initPlugins.js +2 -0
  29. package/dist/rspack-provider/core/inspectConfig.d.ts +12 -1
  30. package/dist/rspack-provider/core/inspectConfig.js +6 -2
  31. package/dist/rspack-provider/core/rspackConfig.js +9 -4
  32. package/dist/rspack-provider/index.d.ts +2 -1
  33. package/dist/rspack-provider/index.js +5 -4
  34. package/dist/rspack-provider/plugins/css.js +1 -2
  35. package/dist/rspack-provider/plugins/less.js +1 -2
  36. package/dist/rspack-provider/plugins/progress.js +2 -5
  37. package/dist/rspack-provider/plugins/rspackProfile.js +1 -2
  38. package/dist/rspack-provider/plugins/sass.js +1 -2
  39. package/dist/rspack-provider/plugins/swc.js +5 -5
  40. package/dist/rspack-provider/provider.d.ts +2 -2
  41. package/dist/rspack-provider/provider.js +2 -7
  42. package/dist/rspack-provider/shared.d.ts +2 -2
  43. package/dist/rspack-provider/shared.js +8 -9
  44. package/dist/server/dev-middleware/index.js +5 -6
  45. package/dist/server/dev-middleware/socketServer.d.ts +3 -3
  46. package/dist/server/dev-middleware/socketServer.js +2 -3
  47. package/dist/server/devServer.d.ts +3 -3
  48. package/dist/server/devServer.js +6 -9
  49. package/dist/server/middlewares.js +1 -2
  50. package/dist/server/prodServer.d.ts +3 -2
  51. package/dist/server/prodServer.js +14 -11
  52. package/dist/server/proxy.js +1 -2
  53. package/dist/types.d.ts +2 -2
  54. package/package.json +2 -4
@@ -21,18 +21,19 @@ __export(rspack_provider_exports, {
21
21
  createContextByConfig: () => import_createContext.createContextByConfig,
22
22
  createPublicContext: () => import_createContext.createPublicContext,
23
23
  getRspackVersion: () => import_shared.getRspackVersion,
24
- rspackProvider: () => import_provider.rspackProvider,
25
- updateContextByNormalizedConfig: () => import_createContext.updateContextByNormalizedConfig
24
+ initRsbuildConfig: () => import_initConfigs.initRsbuildConfig,
25
+ rspackProvider: () => import_provider.rspackProvider
26
26
  });
27
27
  module.exports = __toCommonJS(rspack_provider_exports);
28
28
  var import_shared = require("./shared");
29
29
  var import_provider = require("./provider");
30
30
  var import_createContext = require("./core/createContext");
31
+ var import_initConfigs = require("./core/initConfigs");
31
32
  // Annotate the CommonJS export names for ESM import in node:
32
33
  0 && (module.exports = {
33
34
  createContextByConfig,
34
35
  createPublicContext,
35
36
  getRspackVersion,
36
- rspackProvider,
37
- updateContextByNormalizedConfig
37
+ initRsbuildConfig,
38
+ rspackProvider
38
39
  });
@@ -164,7 +164,6 @@ const pluginCss = () => {
164
164
  });
165
165
  api.modifyRspackConfig(
166
166
  async (rspackConfig, { isProd, isServer, isWebWorker }) => {
167
- var _a;
168
167
  const config = api.getNormalizedConfig();
169
168
  if (!enableNativeCss(config)) {
170
169
  (0, import_shared.setConfig)(rspackConfig, "experiments.css", false);
@@ -183,7 +182,7 @@ const pluginCss = () => {
183
182
  localIdentName,
184
183
  exportsOnly: isServer || isWebWorker
185
184
  });
186
- const rules = (_a = rspackConfig.module) == null ? void 0 : _a.rules;
185
+ const rules = rspackConfig.module?.rules;
187
186
  applyCSSModuleRule(rules, import_shared.CSS_REGEX, config);
188
187
  }
189
188
  );
@@ -63,10 +63,9 @@ function pluginLess() {
63
63
  rule.use(utils.CHAIN_ID.USE.LESS).loader(utils.getCompiledPath("less-loader")).options(options);
64
64
  });
65
65
  api.modifyRspackConfig(async (rspackConfig) => {
66
- var _a;
67
66
  const { applyCSSModuleRule } = await Promise.resolve().then(() => __toESM(require("./css")));
68
67
  const config = api.getNormalizedConfig();
69
- const rules = (_a = rspackConfig.module) == null ? void 0 : _a.rules;
68
+ const rules = rspackConfig.module?.rules;
70
69
  applyCSSModuleRule(rules, import_shared.LESS_REGEX, config);
71
70
  });
72
71
  }
@@ -36,12 +36,9 @@ const pluginProgress = () => ({
36
36
  name: "rsbuild:progress",
37
37
  setup(api) {
38
38
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
39
- var _a;
40
39
  const config = api.getNormalizedConfig();
41
- const options = (_a = config.dev.progressBar) != null ? _a : (
42
- // enable progress bar in production by default
43
- (0, import_shared.isProd)()
44
- );
40
+ const options = config.dev.progressBar ?? // enable progress bar in production by default
41
+ (0, import_shared.isProd)();
45
42
  if (!options) {
46
43
  return;
47
44
  }
@@ -52,8 +52,7 @@ const stopProfiler = (output, profileSession) => {
52
52
  const pluginRspackProfile = () => ({
53
53
  name: "rsbuild:rspack-profile",
54
54
  setup(api) {
55
- var _a;
56
- const RSPACK_PROFILE = (_a = process.env.RSPACK_PROFILE) == null ? void 0 : _a.toUpperCase();
55
+ const RSPACK_PROFILE = process.env.RSPACK_PROFILE?.toUpperCase();
57
56
  if (!RSPACK_PROFILE) {
58
57
  return;
59
58
  }
@@ -68,10 +68,9 @@ function pluginSass() {
68
68
  }).end().use(utils.CHAIN_ID.USE.SASS).loader(utils.getCompiledPath("sass-loader")).options(options);
69
69
  });
70
70
  api.modifyRspackConfig(async (rspackConfig) => {
71
- var _a;
72
71
  const { applyCSSModuleRule } = await Promise.resolve().then(() => __toESM(require("./css")));
73
72
  const config = api.getNormalizedConfig();
74
- const rules = (_a = rspackConfig.module) == null ? void 0 : _a.rules;
73
+ const rules = rspackConfig.module?.rules;
75
74
  applyCSSModuleRule(rules, import_shared.SASS_REGEX, config);
76
75
  });
77
76
  }
@@ -123,19 +123,19 @@ async function applyCoreJs(swcConfig, chain, polyfillMode) {
123
123
  });
124
124
  }
125
125
  function applyTransformImport(swcConfig, pluginImport) {
126
- var _a, _b, _c;
126
+ var _a;
127
127
  if (pluginImport !== false && pluginImport) {
128
- (_a = swcConfig.rspackExperiments) != null ? _a : swcConfig.rspackExperiments = {};
129
- (_c = (_b = swcConfig.rspackExperiments).import) != null ? _c : _b.import = [];
128
+ swcConfig.rspackExperiments ?? (swcConfig.rspackExperiments = {});
129
+ (_a = swcConfig.rspackExperiments).import ?? (_a.import = []);
130
130
  swcConfig.rspackExperiments.import.push(...pluginImport);
131
131
  }
132
132
  }
133
133
  function applyDecorator(swcConfig, enableLatestDecorators) {
134
- var _a, _b;
134
+ var _a;
135
135
  if (enableLatestDecorators) {
136
136
  import_shared.logger.warn("Cannot use latestDecorator in Rspack mode.");
137
137
  }
138
- (_b = (_a = swcConfig.jsc).transform) != null ? _b : _a.transform = {};
138
+ (_a = swcConfig.jsc).transform ?? (_a.transform = {});
139
139
  swcConfig.jsc.transform.legacyDecorator = true;
140
140
  swcConfig.jsc.transform.decoratorMetadata = true;
141
141
  }
@@ -1,6 +1,6 @@
1
- import { type RsbuildProvider, type RspackConfig, type RspackCompiler, type RspackMultiCompiler } from '@rsbuild/shared';
1
+ import { type RsbuildProvider, type RspackConfig } from '@rsbuild/shared';
2
2
  import type { RsbuildConfig, NormalizedConfig } from '../types';
3
- export type RspackProvider = RsbuildProvider<RsbuildConfig, RspackConfig, NormalizedConfig, RspackCompiler | RspackMultiCompiler>;
3
+ export type RspackProvider = RsbuildProvider<RsbuildConfig, RspackConfig, NormalizedConfig>;
4
4
  export declare function rspackProvider({
5
5
  rsbuildConfig: originalRsbuildConfig
6
6
  }: {
@@ -41,13 +41,6 @@ function rspackProvider({
41
41
  }) {
42
42
  const rsbuildConfig = (0, import_shared.pickRsbuildConfig)(originalRsbuildConfig);
43
43
  return async ({ pluginStore, rsbuildOptions, plugins }) => {
44
- if (!await (0, import_shared2.isSatisfyRspackMinimumVersion)()) {
45
- throw new Error(
46
- `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared.color.green(
47
- import_shared2.supportedRspackMinimumVersion
48
- )}`
49
- );
50
- }
51
44
  const context = await (0, import_createContext.createContext)(rsbuildOptions, rsbuildConfig);
52
45
  const pluginAPI = (0, import_initPlugins.getPluginAPI)({ context, pluginStore });
53
46
  context.pluginAPI = pluginAPI;
@@ -73,6 +66,7 @@ function rspackProvider({
73
66
  async startDevServer(options) {
74
67
  const { startDevServer } = await Promise.resolve().then(() => __toESM(require("../server/devServer")));
75
68
  const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
69
+ await (0, import_initConfigs.initRsbuildConfig)({ context, pluginStore });
76
70
  return startDevServer(
77
71
  { context, pluginStore, rsbuildOptions },
78
72
  createDevMiddleware,
@@ -81,6 +75,7 @@ function rspackProvider({
81
75
  },
82
76
  async preview(options) {
83
77
  const { startProdServer } = await Promise.resolve().then(() => __toESM(require("../server/prodServer")));
78
+ await (0, import_initConfigs.initRsbuildConfig)({ context, pluginStore });
84
79
  return startProdServer(context, context.config, options);
85
80
  },
86
81
  async build(options) {
@@ -2,7 +2,7 @@ import { RsbuildPlugin } from '../types';
2
2
  import { Plugins } from '@rsbuild/shared';
3
3
  export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
4
4
  export declare const getRspackVersion: () => Promise<string>;
5
- export declare const supportedRspackMinimumVersion = "0.3.6";
6
- export declare const isSatisfyRspackMinimumVersion: (customVersion?: string) => Promise<boolean>;
5
+ export declare const rspackMinVersion = "0.3.6";
6
+ export declare const isSatisfyRspackVersion: (version: string) => Promise<boolean>;
7
7
  export declare const getCompiledPath: (packageName: string) => string;
8
8
  export declare const BUILTIN_LOADER = "builtin:";
@@ -32,8 +32,8 @@ __export(shared_exports, {
32
32
  applyDefaultPlugins: () => applyDefaultPlugins,
33
33
  getCompiledPath: () => getCompiledPath,
34
34
  getRspackVersion: () => getRspackVersion,
35
- isSatisfyRspackMinimumVersion: () => isSatisfyRspackMinimumVersion,
36
- supportedRspackMinimumVersion: () => supportedRspackMinimumVersion
35
+ isSatisfyRspackVersion: () => isSatisfyRspackVersion,
36
+ rspackMinVersion: () => rspackMinVersion
37
37
  });
38
38
  module.exports = __toCommonJS(shared_exports);
39
39
  var import_path = require("path");
@@ -81,20 +81,19 @@ const getRspackVersion = async () => {
81
81
  try {
82
82
  const core = require.resolve("@rspack/core");
83
83
  const pkg = await Promise.resolve().then(() => __toESM(require((0, import_path.join)(core, "../../package.json"))));
84
- return pkg == null ? void 0 : pkg.version;
84
+ return pkg?.version;
85
85
  } catch (err) {
86
86
  console.error(err);
87
87
  return "";
88
88
  }
89
89
  };
90
- const supportedRspackMinimumVersion = "0.3.6";
91
- const isSatisfyRspackMinimumVersion = async (customVersion) => {
92
- let version = customVersion || await getRspackVersion();
90
+ const rspackMinVersion = "0.3.6";
91
+ const isSatisfyRspackVersion = async (version) => {
93
92
  const semver = await Promise.resolve().then(() => __toESM(require("semver")));
94
93
  if (version.includes("-canary")) {
95
94
  version = version.split("-canary")[0];
96
95
  }
97
- return version ? semver.lte(supportedRspackMinimumVersion, version) : true;
96
+ return version ? semver.lte(rspackMinVersion, version) : true;
98
97
  };
99
98
  const getCompiledPath = (packageName) => {
100
99
  const providerCompilerPath = (0, import_path.join)(__dirname, "../../compiled", packageName);
@@ -111,6 +110,6 @@ const BUILTIN_LOADER = "builtin:";
111
110
  applyDefaultPlugins,
112
111
  getCompiledPath,
113
112
  getRspackVersion,
114
- isSatisfyRspackMinimumVersion,
115
- supportedRspackMinimumVersion
113
+ isSatisfyRspackVersion,
114
+ rspackMinVersion
116
115
  });
@@ -36,10 +36,10 @@ var import_socketServer = __toESM(require("./socketServer"));
36
36
  const noop = () => {
37
37
  };
38
38
  function getHMRClientPath(client) {
39
- const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
40
- const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
41
- const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
42
- const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
39
+ const protocol = client?.protocol ? `&protocol=${client.protocol}` : "";
40
+ const host = client?.host ? `&host=${client.host}` : "";
41
+ const path = client?.path ? `&path=${client.path}` : "";
42
+ const port = client?.port ? `&port=${client.port}` : "";
43
43
  const clientEntry = `${require.resolve("@rsbuild/core/client/hmr")}?${host}${path}${port}${protocol}`;
44
44
  return clientEntry;
45
45
  }
@@ -63,9 +63,8 @@ class DevMiddleware extends import_events.EventEmitter {
63
63
  });
64
64
  }
65
65
  close() {
66
- var _a;
67
66
  this.socketServer.close();
68
- (_a = this.middleware) == null ? void 0 : _a.close(noop);
67
+ this.middleware?.close(noop);
69
68
  }
70
69
  sockWrite(type, data) {
71
70
  this.socketServer.sockWrite(type, data);
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
- import { Server } from 'http';
3
- import ws from 'ws';
4
- import { Stats, DevConfig } from '@rsbuild/shared';
2
+ import type { Server } from 'http';
3
+ import ws from '../../../compiled/ws';
4
+ import { type Stats, type DevConfig } from '@rsbuild/shared';
5
5
  export default class SocketServer {
6
6
  private wsServer;
7
7
  private readonly sockets;
@@ -31,7 +31,7 @@ __export(socketServer_exports, {
31
31
  default: () => SocketServer
32
32
  });
33
33
  module.exports = __toCommonJS(socketServer_exports);
34
- var import_ws = __toESM(require("ws"));
34
+ var import_ws = __toESM(require("../../../compiled/ws"));
35
35
  var import_shared = require("@rsbuild/shared");
36
36
  class SocketServer {
37
37
  constructor(options) {
@@ -41,11 +41,10 @@ class SocketServer {
41
41
  }
42
42
  // create socket, install socket handler, bind socket event
43
43
  prepare(app) {
44
- var _a;
45
44
  this.app = app;
46
45
  this.wsServer = new import_ws.default.Server({
47
46
  noServer: true,
48
- path: (_a = this.options.client) == null ? void 0 : _a.path
47
+ path: this.options.client?.path
49
48
  });
50
49
  this.app.on("upgrade", (req, sock, head) => {
51
50
  if (!this.wsServer.shouldHandle(req)) {
@@ -3,8 +3,9 @@
3
3
  /// <reference types="node" />
4
4
  import { Server } from 'http';
5
5
  import type { ListenOptions } from 'net';
6
- import { RsbuildDevServerOptions, CreateDevMiddlewareReturns, DevServerContext, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
6
+ import { RsbuildDevServerOptions, CreateDevMiddlewareReturns, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
7
7
  import connect from '@rsbuild/shared/connect';
8
+ import type { Context } from '../types';
8
9
  export declare class RsbuildDevServer {
9
10
  private readonly dev;
10
11
  private readonly devMiddleware;
@@ -21,9 +22,8 @@ export declare class RsbuildDevServer {
21
22
  close(): void;
22
23
  }
23
24
  export declare function startDevServer<Options extends {
24
- context: DevServerContext;
25
+ context: Context;
25
26
  }>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevMiddlewareReturns>, {
26
- open,
27
27
  compiler: customCompiler,
28
28
  printURLs,
29
29
  strictPort,
@@ -94,7 +94,7 @@ class RsbuildDevServer {
94
94
  this.middlewares.use((req, res, next) => {
95
95
  res.setHeader("Access-Control-Allow-Origin", "*");
96
96
  const path = req.url ? import_url.default.parse(req.url).pathname : "";
97
- if (path == null ? void 0 : path.includes("hot-update")) {
97
+ if (path?.includes("hot-update")) {
98
98
  res.setHeader("Access-Control-Allow-Credentials", "false");
99
99
  }
100
100
  const confHeaders = dev.headers;
@@ -143,7 +143,7 @@ class RsbuildDevServer {
143
143
  }
144
144
  listen(options, listener) {
145
145
  const callback = () => {
146
- listener == null ? void 0 : listener();
146
+ listener?.();
147
147
  };
148
148
  if (typeof options === "object") {
149
149
  this.app.listen(options, callback);
@@ -157,19 +157,17 @@ class RsbuildDevServer {
157
157
  }
158
158
  }
159
159
  async function startDevServer(options, createDevMiddleware, {
160
- open,
161
160
  compiler: customCompiler,
162
161
  printURLs = true,
163
162
  strictPort = false,
164
163
  logger: customLogger,
165
164
  getPortSilently
166
165
  } = {}) {
167
- var _a, _b, _c, _d;
168
166
  if (!process.env.NODE_ENV) {
169
167
  process.env.NODE_ENV = "development";
170
168
  }
171
169
  const rsbuildConfig = options.context.config;
172
- const logger = customLogger != null ? customLogger : import_shared.logger;
170
+ const logger = customLogger ?? import_shared.logger;
173
171
  const { devServerConfig, port, host, https } = await (0, import_shared.getDevOptions)({
174
172
  rsbuildConfig,
175
173
  strictPort,
@@ -178,14 +176,13 @@ async function startDevServer(options, createDevMiddleware, {
178
176
  options.context.devServer = {
179
177
  hostname: host,
180
178
  port,
181
- https,
182
- open
179
+ https
183
180
  };
184
181
  const protocol = https ? "https" : "http";
185
182
  let urls = (0, import_shared.getAddressUrls)(protocol, port, host);
186
183
  const routes = (0, import_shared.formatRoutes)(
187
184
  options.context.entry,
188
- (_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.html
185
+ rsbuildConfig.output?.distPath?.html
189
186
  );
190
187
  (0, import_shared.debug)("create dev server");
191
188
  const { devMiddleware, compiler } = await createDevMiddleware(
@@ -198,7 +195,7 @@ async function startDevServer(options, createDevMiddleware, {
198
195
  devMiddleware,
199
196
  dev: devServerConfig,
200
197
  output: {
201
- distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
198
+ distPath: rsbuildConfig.output?.distPath?.root || import_shared.ROOT_DIST_DIR,
202
199
  publicPaths
203
200
  }
204
201
  });
@@ -67,8 +67,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
67
67
  outputFileSystem = devMiddleware.outputFileSystem;
68
68
  }
69
69
  const rewrite = (newUrl) => {
70
- var _a;
71
- (_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
70
+ (0, import_shared.debug)?.(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
72
71
  req.url = newUrl;
73
72
  if (callback) {
74
73
  return callback(req, res, (...args) => {
@@ -4,7 +4,8 @@
4
4
  import type { ListenOptions } from 'net';
5
5
  import { Server } from 'http';
6
6
  import connect from '@rsbuild/shared/connect';
7
- import { type Context, type ServerConfig, type RsbuildConfig, type StartServerResult, type PreviewServerOptions } from '@rsbuild/shared';
7
+ import { type ServerConfig, type RsbuildConfig, type StartServerResult, type PreviewServerOptions } from '@rsbuild/shared';
8
+ import type { Context } from '../types';
8
9
  type RsbuildProdServerOptions = {
9
10
  pwd: string;
10
11
  output: {
@@ -22,7 +23,7 @@ export declare class RsbuildProdServer {
22
23
  private applyDefaultMiddlewares;
23
24
  private applyStaticAssetMiddleware;
24
25
  createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
25
- listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
26
+ listen(options?: number | ListenOptions | undefined, listener?: () => Promise<void>): void;
26
27
  close(): void;
27
28
  }
28
29
  export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig, {
@@ -100,7 +100,7 @@ class RsbuildProdServer {
100
100
  });
101
101
  this.middlewares.use((req, res, next) => {
102
102
  const url = req.url;
103
- if (assetPrefix && (url == null ? void 0 : url.startsWith(assetPrefix))) {
103
+ if (assetPrefix && url?.startsWith(assetPrefix)) {
104
104
  req.url = url.slice(assetPrefix.length);
105
105
  assetMiddleware(req, res, (...args) => {
106
106
  req.url = url;
@@ -122,7 +122,7 @@ class RsbuildProdServer {
122
122
  }
123
123
  listen(options, listener) {
124
124
  const callback = () => {
125
- listener == null ? void 0 : listener();
125
+ listener?.();
126
126
  };
127
127
  if (typeof options === "object") {
128
128
  this.app.listen(options, callback);
@@ -139,7 +139,6 @@ async function startProdServer(context, rsbuildConfig, {
139
139
  strictPort = false,
140
140
  getPortSilently
141
141
  } = {}) {
142
- var _a, _b, _c;
143
142
  if (!process.env.NODE_ENV) {
144
143
  process.env.NODE_ENV = "production";
145
144
  }
@@ -151,11 +150,12 @@ async function startProdServer(context, rsbuildConfig, {
151
150
  const server = new RsbuildProdServer({
152
151
  pwd: context.rootPath,
153
152
  output: {
154
- path: ((_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.root) || import_shared.ROOT_DIST_DIR,
155
- assetPrefix: (_c = rsbuildConfig.output) == null ? void 0 : _c.assetPrefix
153
+ path: rsbuildConfig.output?.distPath?.root || import_shared.ROOT_DIST_DIR,
154
+ assetPrefix: rsbuildConfig.output?.assetPrefix
156
155
  },
157
156
  serverConfig
158
157
  });
158
+ await context.hooks.onBeforeStartProdServerHook.call();
159
159
  const httpServer = await server.createHTTPServer();
160
160
  await server.onInit(httpServer);
161
161
  return new Promise((resolve) => {
@@ -164,14 +164,17 @@ async function startProdServer(context, rsbuildConfig, {
164
164
  host,
165
165
  port
166
166
  },
167
- () => {
168
- var _a2, _b2;
167
+ async () => {
168
+ const routes = (0, import_shared.formatRoutes)(
169
+ context.entry,
170
+ rsbuildConfig.output?.distPath?.html
171
+ );
172
+ await context.hooks.onAfterStartProdServerHook.call({
173
+ port,
174
+ routes
175
+ });
169
176
  const urls = (0, import_shared.getAddressUrls)(https ? "https" : "http", port);
170
177
  if (printURLs) {
171
- const routes = (0, import_shared.formatRoutes)(
172
- context.entry,
173
- (_b2 = (_a2 = rsbuildConfig.output) == null ? void 0 : _a2.distPath) == null ? void 0 : _b2.html
174
- );
175
178
  (0, import_shared.printServerURLs)(
176
179
  (0, import_shared.isFunction)(printURLs) ? printURLs(urls) : urls,
177
180
  routes
@@ -25,7 +25,6 @@ module.exports = __toCommonJS(proxy_exports);
25
25
  var import_http_proxy_middleware = require("@rsbuild/shared/http-proxy-middleware");
26
26
  var import_shared = require("@rsbuild/shared");
27
27
  function formatProxyOptions(proxyOptions) {
28
- var _a;
29
28
  const ret = [];
30
29
  if (Array.isArray(proxyOptions)) {
31
30
  ret.push(...proxyOptions);
@@ -48,7 +47,7 @@ function formatProxyOptions(proxyOptions) {
48
47
  }
49
48
  const handleError = (err) => import_shared.logger.error(err);
50
49
  for (const opts of ret) {
51
- (_a = opts.onError) != null ? _a : opts.onError = handleError;
50
+ opts.onError ?? (opts.onError = handleError);
52
51
  }
53
52
  return ret;
54
53
  }
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Context as BaseContext, RsbuildConfig, NormalizedConfig, DefaultRsbuildPluginAPI, RsbuildPlugin as BaseRsbuildPlugin } from '@rsbuild/shared';
2
2
  import type { Hooks } from './rspack-provider/core/initHooks';
3
- import type { RspackConfig, RspackCompiler, RspackMultiCompiler } from '@rsbuild/shared';
4
- export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, RspackConfig, RspackCompiler | RspackMultiCompiler> {}
3
+ import type { RspackConfig } from '@rsbuild/shared';
4
+ export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, RspackConfig> {}
5
5
  export type RsbuildPlugin<T = RsbuildPluginAPI> = BaseRsbuildPlugin<T>;
6
6
  /** The inner context. */
7
7
  export type Context = BaseContext & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Unleash the power of Rspack with the out-of-the-box build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -63,12 +63,10 @@
63
63
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
64
64
  "postcss": "8.4.31",
65
65
  "semver": "^7.5.4",
66
- "ws": "^8.2.0",
67
- "@rsbuild/shared": "0.1.1"
66
+ "@rsbuild/shared": "0.1.3"
68
67
  },
69
68
  "devDependencies": {
70
69
  "@types/node": "^16",
71
- "@types/ws": "^8.2.0",
72
70
  "@types/semver": "^7.5.4",
73
71
  "typescript": "^5.3.0"
74
72
  },