@rsbuild/core 0.0.18 → 0.0.20

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 (42) hide show
  1. package/bin/rsbuild.js +11 -0
  2. package/dist/plugins/asset.d.ts +1 -1
  3. package/dist/plugins/asset.js +19 -13
  4. package/dist/plugins/index.d.ts +1 -1
  5. package/dist/plugins/index.js +1 -5
  6. package/dist/plugins/inlineChunk.js +2 -7
  7. package/dist/plugins/splitChunks.js +0 -5
  8. package/dist/plugins/startUrl.js +5 -1
  9. package/dist/rspack-provider/core/createCompiler.d.ts +4 -1
  10. package/dist/rspack-provider/core/createCompiler.js +19 -2
  11. package/dist/rspack-provider/core/initHooks.d.ts +2 -2
  12. package/dist/rspack-provider/core/initPlugins.js +5 -1
  13. package/dist/rspack-provider/index.d.ts +1 -1
  14. package/dist/rspack-provider/provider.js +3 -3
  15. package/dist/rspack-provider/shared/plugin.js +1 -4
  16. package/dist/rspack-provider/types/index.d.ts +0 -1
  17. package/dist/rspack-provider/types/index.js +0 -2
  18. package/dist/rspack-provider/types/plugin.d.ts +1 -4
  19. package/dist/server/dev-middleware/hmr-client/createSocketUrl.d.ts +1 -1
  20. package/dist/server/dev-middleware/hmr-client/createSocketUrl.js +1 -1
  21. package/dist/server/dev-middleware/index.d.ts +2 -2
  22. package/dist/server/dev-middleware/index.js +1 -1
  23. package/dist/server/dev-middleware/socketServer.d.ts +2 -2
  24. package/dist/server/dev-middleware/socketServer.js +1 -4
  25. package/dist/server/devServer.d.ts +15 -4
  26. package/dist/server/devServer.js +98 -30
  27. package/dist/server/index.d.ts +1 -1
  28. package/dist/server/index.js +2 -2
  29. package/dist/server/middlewares.d.ts +8 -0
  30. package/dist/server/middlewares.js +103 -0
  31. package/dist/server/prodServer.d.ts +1 -0
  32. package/dist/server/prodServer.js +6 -3
  33. package/dist/server/proxy.d.ts +9 -0
  34. package/dist/server/proxy.js +92 -0
  35. package/package.json +4 -3
  36. package/types.d.ts +63 -23
  37. package/dist/rspack-provider/core/startDevServer.d.ts +0 -5
  38. package/dist/rspack-provider/core/startDevServer.js +0 -59
  39. package/dist/rspack-provider/types/hooks.d.ts +0 -3
  40. package/dist/rspack-provider/types/hooks.js +0 -16
  41. package/dist/server/constants.d.ts +0 -6
  42. package/dist/server/constants.js +0 -49
package/bin/rsbuild.js CHANGED
@@ -1,7 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  const { logger } = require('rslog');
3
3
 
4
+ function initNodeEnv() {
5
+ if (!process.env.NODE_ENV) {
6
+ const command = process.argv[2];
7
+ process.env.NODE_ENV = ['build', 'preview'].includes(command)
8
+ ? 'production'
9
+ : 'development';
10
+ }
11
+ }
12
+
4
13
  async function main() {
14
+ initNodeEnv();
15
+
5
16
  const { version } = require('../package.json');
6
17
 
7
18
  // If not called through a package manager,
@@ -1,3 +1,3 @@
1
1
  import type { DefaultRsbuildPlugin } from '@rsbuild/shared';
2
2
  export declare function getRegExpForExts(exts: string[]): RegExp;
3
- export declare const pluginAsset: (assetType: 'image' | 'media' | 'font' | 'svg', exts: string[]) => DefaultRsbuildPlugin;
3
+ export declare const pluginAsset: () => DefaultRsbuildPlugin;
@@ -41,22 +41,28 @@ function getRegExpForExts(exts) {
41
41
  "i"
42
42
  );
43
43
  }
44
- const pluginAsset = (assetType, exts) => ({
45
- name: `plugin-${assetType}`,
44
+ const pluginAsset = () => ({
45
+ name: "plugin-asset",
46
46
  setup(api) {
47
47
  api.modifyBundlerChain((chain, { isProd }) => {
48
48
  const config = api.getNormalizedConfig();
49
- const regExp = getRegExpForExts(exts);
50
- const distDir = (0, import_shared.getDistPath)(config.output, assetType);
51
- const filename = (0, import_shared.getFilename)(config.output, assetType, isProd);
52
- const maxSize = config.output.dataUriLimit[assetType];
53
- const rule = chain.module.rule(assetType).test(regExp);
54
- (0, import_shared.chainStaticAssetRule)({
55
- rule,
56
- maxSize,
57
- filename: import_path.default.posix.join(distDir, filename),
58
- assetType
59
- });
49
+ const createAssetRule = (assetType, exts) => {
50
+ const regExp = getRegExpForExts(exts);
51
+ const distDir = (0, import_shared.getDistPath)(config.output, assetType);
52
+ const filename = (0, import_shared.getFilename)(config.output, assetType, isProd);
53
+ const maxSize = config.output.dataUriLimit[assetType];
54
+ const rule = chain.module.rule(assetType).test(regExp);
55
+ (0, import_shared.chainStaticAssetRule)({
56
+ rule,
57
+ maxSize,
58
+ filename: import_path.default.posix.join(distDir, filename),
59
+ assetType
60
+ });
61
+ };
62
+ createAssetRule("image", import_shared.IMAGE_EXTENSIONS);
63
+ createAssetRule("svg", ["svg"]);
64
+ createAssetRule("media", import_shared.MEDIA_EXTENSIONS);
65
+ createAssetRule("font", import_shared.FONT_EXTENSIONS);
60
66
  });
61
67
  }
62
68
  });
@@ -1,2 +1,2 @@
1
- import { Plugins } from '@rsbuild/shared';
1
+ import type { Plugins } from '@rsbuild/shared';
2
2
  export declare const plugins: Plugins;
@@ -31,7 +31,6 @@ __export(plugins_exports, {
31
31
  plugins: () => plugins
32
32
  });
33
33
  module.exports = __toCommonJS(plugins_exports);
34
- var import_shared = require("@rsbuild/shared");
35
34
  const plugins = {
36
35
  html: () => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.pluginHtml()),
37
36
  cleanOutput: () => Promise.resolve().then(() => __toESM(require("./cleanOutput"))).then((m) => m.pluginCleanOutput()),
@@ -46,10 +45,7 @@ const plugins = {
46
45
  splitChunks: () => Promise.resolve().then(() => __toESM(require("./splitChunks"))).then((m) => m.pluginSplitChunks()),
47
46
  inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.pluginInlineChunk()),
48
47
  bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.pluginBundleAnalyzer()),
49
- svg: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("svg", ["svg"])),
50
- font: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("font", import_shared.FONT_EXTENSIONS)),
51
- image: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("image", import_shared.IMAGE_EXTENSIONS)),
52
- media: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("media", import_shared.MEDIA_EXTENSIONS)),
48
+ asset: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset()),
53
49
  rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.pluginRem()),
54
50
  wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
55
51
  moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
@@ -43,7 +43,6 @@ const pluginInlineChunk = () => ({
43
43
  }
44
44
  const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
45
45
  const {
46
- disableInlineRuntimeChunk,
47
46
  enableInlineStyles,
48
47
  // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
49
48
  enableInlineScripts
@@ -60,12 +59,8 @@ const pluginInlineChunk = () => ({
60
59
  enableInlineStyles === true ? import_shared.CSS_REGEX : enableInlineStyles
61
60
  );
62
61
  }
63
- if (!disableInlineRuntimeChunk) {
64
- scriptTests.push(
65
- // RegExp like /bundler-runtime([.].+)?\.js$/
66
- // matches bundler-runtime.js and bundler-runtime.123456.js
67
- new RegExp(`${import_shared.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`)
68
- );
62
+ if (!scriptTests.length && !styleTests.length) {
63
+ return;
69
64
  }
70
65
  chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
71
66
  HtmlPlugin,
@@ -226,11 +226,6 @@ function pluginSplitChunks() {
226
226
  polyfill: config.output.polyfill
227
227
  });
228
228
  chain.optimization.splitChunks(splitChunksOptions);
229
- if (chunkSplit.strategy !== "all-in-one") {
230
- chain.optimization.runtimeChunk({
231
- name: import_shared.RUNTIME_CHUNK_NAME
232
- });
233
- }
234
229
  }
235
230
  );
236
231
  }
@@ -106,8 +106,12 @@ function pluginStartUrl() {
106
106
  }
107
107
  const urls = [];
108
108
  if (startUrl === true || !startUrl) {
109
+ const { entry } = api.context;
110
+ const routes = (0, import_shared.formatRoutes)(entry);
109
111
  const protocol = https ? "https" : "http";
110
- urls.push(`${protocol}://localhost:${port}`);
112
+ urls.push(
113
+ (0, import_shared.normalizeUrl)(`${protocol}://localhost:${port}/${routes[0].route}`)
114
+ );
111
115
  } else {
112
116
  urls.push(
113
117
  ...(0, import_shared.castArray)(startUrl).map(
@@ -1,4 +1,6 @@
1
1
  import { type RspackConfig } from '@rsbuild/shared';
2
+ import { type RspackCompiler, type RspackMultiCompiler } from '@rsbuild/shared';
3
+ import { type InitConfigsOptions } from './initConfigs';
2
4
  import type { Context } from '../types';
3
5
  export declare function createCompiler({
4
6
  context,
@@ -6,4 +8,5 @@ export declare function createCompiler({
6
8
  }: {
7
9
  context: Context;
8
10
  rspackConfigs: RspackConfig[];
9
- }): Promise<import("@rspack/core").MultiCompiler>;
11
+ }): Promise<import("@rspack/core").MultiCompiler>;
12
+ export declare function startDevCompile(options: InitConfigsOptions, customCompiler?: RspackCompiler | RspackMultiCompiler): Promise<import("@rsbuild/shared").DevMiddleware>;
@@ -28,10 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var createCompiler_exports = {};
30
30
  __export(createCompiler_exports, {
31
- createCompiler: () => createCompiler
31
+ createCompiler: () => createCompiler,
32
+ startDevCompile: () => startDevCompile
32
33
  });
33
34
  module.exports = __toCommonJS(createCompiler_exports);
34
35
  var import_shared = require("@rsbuild/shared");
36
+ var import_devMiddleware = require("./devMiddleware");
37
+ var import_initConfigs = require("./initConfigs");
35
38
  async function createCompiler({
36
39
  context,
37
40
  rspackConfigs
@@ -79,7 +82,21 @@ async function createCompiler({
79
82
  (0, import_shared.debug)("create compiler done");
80
83
  return compiler;
81
84
  }
85
+ async function startDevCompile(options, customCompiler) {
86
+ let compiler;
87
+ if (customCompiler) {
88
+ compiler = customCompiler;
89
+ } else {
90
+ const { rspackConfigs } = await (0, import_initConfigs.initConfigs)(options);
91
+ compiler = await createCompiler({
92
+ context: options.context,
93
+ rspackConfigs
94
+ });
95
+ }
96
+ return (0, import_devMiddleware.getDevMiddleware)(compiler);
97
+ }
82
98
  // Annotate the CommonJS export names for ESM import in node:
83
99
  0 && (module.exports = {
84
- createCompiler
100
+ createCompiler,
101
+ startDevCompile
85
102
  });
@@ -1,5 +1,5 @@
1
- import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig } from '@rsbuild/shared';
2
- import type { RsbuildConfig, ModifyRspackConfigFn } from '../types';
1
+ import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig, type ModifyRspackConfigFn } from '@rsbuild/shared';
2
+ import type { RsbuildConfig } from '../types';
3
3
  export declare function initHooks(): {
4
4
  /** parameters are not bundler-related */
5
5
  onExitHook: import("@rsbuild/shared").AsyncHook<OnExitFn>;
@@ -73,7 +73,11 @@ function getPluginAPI({
73
73
  onAfterCreateCompiler: hooks.onAfterCreateCompilerHook.tap,
74
74
  onBeforeCreateCompiler: hooks.onBeforeCreateCompilerHook.tap,
75
75
  onAfterStartDevServer: hooks.onAfterStartDevServerHook.tap,
76
- onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap
76
+ onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap,
77
+ modifyWebpackChain: () => {
78
+ },
79
+ modifyWebpackConfig: () => {
80
+ }
77
81
  };
78
82
  }
79
83
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,5 +1,5 @@
1
1
  export { getRspackVersion } from './shared/rspackVersion';
2
2
  export { rspackProvider } from './provider';
3
3
  export type { RspackProvider } from './provider';
4
- export type { RsbuildConfig, NormalizedConfig, ModifyRspackConfigFn, RsbuildPluginAPI } from './types';
4
+ export type { RsbuildConfig, NormalizedConfig, RsbuildPluginAPI } from './types';
5
5
  export type { Rspack, RspackConfig } from '@rsbuild/shared';
@@ -73,10 +73,10 @@ function rspackProvider({
73
73
  });
74
74
  },
75
75
  async startDevServer(options) {
76
- const { createDevServer } = await Promise.resolve().then(() => __toESM(require("./core/startDevServer")));
77
- return (0, import_shared.startDevServer)(
76
+ const { startDevCompile } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
77
+ return (0, import_server.startDevServer)(
78
78
  { context, pluginStore, rsbuildOptions },
79
- createDevServer,
79
+ startDevCompile,
80
80
  options
81
81
  );
82
82
  },
@@ -44,10 +44,7 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
44
44
  plugins.fileSize(),
45
45
  // cleanOutput plugin should before the html plugin
46
46
  plugins.cleanOutput(),
47
- plugins.font(),
48
- plugins.image(),
49
- plugins.media(),
50
- plugins.svg(),
47
+ plugins.asset(),
51
48
  plugins.html(),
52
49
  plugins.wasm(),
53
50
  plugins.moment(),
@@ -1,4 +1,3 @@
1
- export * from './hooks';
2
1
  export * from './plugin';
3
2
  export * from './context';
4
3
  export type { RsbuildConfig, NormalizedConfig, DevConfig, HtmlConfig, ToolsConfig, SourceConfig, OutputConfig, SecurityConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedToolsConfig, NormalizedSourceConfig, NormalizedOutputConfig, NormalizedSecurityConfig, NormalizedPerformanceConfig } from '@rsbuild/shared';
@@ -15,12 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var types_exports = {};
17
17
  module.exports = __toCommonJS(types_exports);
18
- __reExport(types_exports, require("./hooks"), module.exports);
19
18
  __reExport(types_exports, require("./plugin"), module.exports);
20
19
  __reExport(types_exports, require("./context"), module.exports);
21
20
  // Annotate the CommonJS export names for ESM import in node:
22
21
  0 && (module.exports = {
23
- ...require("./hooks"),
24
22
  ...require("./plugin"),
25
23
  ...require("./context")
26
24
  });
@@ -1,7 +1,4 @@
1
1
  import type { RsbuildConfig, NormalizedConfig, DefaultRsbuildPluginAPI, RsbuildPlugin as BaseRsbuildPlugin } from '@rsbuild/shared';
2
- import type { ModifyRspackConfigFn } from './hooks';
3
2
  import type { RspackConfig, RspackCompiler, RspackMultiCompiler } from '@rsbuild/shared';
4
- export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, RspackConfig, RspackCompiler | RspackMultiCompiler> {
5
- modifyRspackConfig: (fn: ModifyRspackConfigFn) => void;
6
- }
3
+ export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, RspackConfig, RspackCompiler | RspackMultiCompiler> {}
7
4
  export type RsbuildPlugin = BaseRsbuildPlugin<RsbuildPluginAPI>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * hmr socket connect path
3
3
  */
4
- export declare const HMR_SOCK_PATH = "/webpack-hmr";
4
+ export declare const HMR_SOCK_PATH = "/rsbuild-hmr";
5
5
  export declare function createSocketUrl(resourceQuery: string): string;
6
6
  export declare function formatURL({
7
7
  port,
@@ -23,7 +23,7 @@ __export(createSocketUrl_exports, {
23
23
  formatURL: () => formatURL
24
24
  });
25
25
  module.exports = __toCommonJS(createSocketUrl_exports);
26
- const HMR_SOCK_PATH = "/webpack-hmr";
26
+ const HMR_SOCK_PATH = "/rsbuild-hmr";
27
27
  function createSocketUrl(resourceQuery) {
28
28
  const searchParams = resourceQuery.substr(1).split("&");
29
29
  const options = {};
@@ -2,9 +2,9 @@
2
2
  /// <reference types="node" />
3
3
  import { Server } from 'http';
4
4
  import { EventEmitter } from 'events';
5
- import type { DevServerOptions, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
5
+ import type { DevConfig, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
6
6
  type Options = {
7
- dev: DevServerOptions;
7
+ dev: DevConfig;
8
8
  devMiddleware?: CustomDevMiddleware;
9
9
  };
10
10
  export default class DevMiddleware extends EventEmitter {
@@ -76,7 +76,7 @@ class DevMiddleware extends import_events.EventEmitter {
76
76
  this.emit("change", stats);
77
77
  }
78
78
  };
79
- const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
79
+ const enableHMR = this.devOptions.hmr;
80
80
  const middleware = devMiddleware({
81
81
  headers: devOptions.headers,
82
82
  stats: false,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Server } from 'http';
3
3
  import ws from 'ws';
4
- import { Stats, DevServerOptions } from '@rsbuild/shared';
4
+ import { Stats, DevConfig } from '@rsbuild/shared';
5
5
  export default class SocketServer {
6
6
  private wsServer;
7
7
  private readonly sockets;
@@ -9,7 +9,7 @@ export default class SocketServer {
9
9
  private app?;
10
10
  private stats?;
11
11
  private timer;
12
- constructor(options: DevServerOptions);
12
+ constructor(options: DevConfig);
13
13
  prepare(app: Server): void;
14
14
  updateStats(stats: Stats): void;
15
15
  sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
@@ -112,12 +112,9 @@ class SocketServer {
112
112
  this.sockets.splice(idx, 1);
113
113
  }
114
114
  });
115
- if (this.options.hot || this.options.hot === "only") {
115
+ if (this.options.hmr) {
116
116
  this.singleWrite(connection, "hot");
117
117
  }
118
- if (this.options.liveReload) {
119
- this.singleWrite(connection, "liveReload");
120
- }
121
118
  if (this.stats) {
122
119
  this.sendStats(true);
123
120
  }
@@ -3,21 +3,32 @@
3
3
  /// <reference types="node" />
4
4
  import { Server } from 'http';
5
5
  import type { ListenOptions } from 'net';
6
- import { RsbuildDevServerOptions, CreateDevServerOptions, ServerApi } from '@rsbuild/shared';
6
+ import { RsbuildDevServerOptions, CreateDevServerOptions, DevServerContext, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
7
7
  import connect from 'connect';
8
8
  export declare class RsbuildDevServer {
9
9
  private readonly dev;
10
10
  private readonly devMiddleware;
11
11
  private pwd;
12
12
  private app;
13
+ private output;
13
14
  middlewares: connect.Server;
14
15
  constructor(options: RsbuildDevServerOptions);
15
- private getDevOptions;
16
16
  private applySetupMiddlewares;
17
17
  onInit(app: Server): Promise<void>;
18
18
  private applyDefaultMiddlewares;
19
19
  createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
20
- listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
20
+ listen(options?: number | ListenOptions | undefined, listener?: (err?: Error) => Promise<void>): void;
21
21
  close(): void;
22
22
  }
23
- export declare function createDevServer(options: CreateDevServerOptions): Promise<ServerApi>;
23
+ export declare function startDevServer<Options extends {
24
+ context: DevServerContext;
25
+ }>(options: Options, startDevCompile: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevServerOptions['devMiddleware']>, {
26
+ open,
27
+ compiler,
28
+ printURLs,
29
+ strictPort,
30
+ logger: customLogger,
31
+ getPortSilently
32
+ }?: StartDevServerOptions & {
33
+ defaultPort?: number;
34
+ }): Promise<StartServerResult>;
@@ -29,32 +29,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var devServer_exports = {};
30
30
  __export(devServer_exports, {
31
31
  RsbuildDevServer: () => RsbuildDevServer,
32
- createDevServer: () => createDevServer
32
+ startDevServer: () => startDevServer
33
33
  });
34
34
  module.exports = __toCommonJS(devServer_exports);
35
35
  var import_http = require("http");
36
36
  var import_https = require("https");
37
37
  var import_url = __toESM(require("url"));
38
38
  var import_shared = require("@rsbuild/shared");
39
- var import_constants = require("./constants");
40
39
  var import_dev_middleware = __toESM(require("./dev-middleware"));
41
- var import_deepmerge = require("@rsbuild/shared/deepmerge");
42
40
  var import_connect = __toESM(require("connect"));
41
+ var import_proxy = require("./proxy");
42
+ var import_middlewares = require("./middlewares");
43
+ var import_path = require("path");
43
44
  class RsbuildDevServer {
44
45
  constructor(options) {
45
46
  this.middlewares = (0, import_connect.default)();
46
47
  this.pwd = options.pwd;
47
- this.dev = this.getDevOptions(options);
48
+ this.dev = options.dev;
49
+ this.output = options.output;
48
50
  this.devMiddleware = new import_dev_middleware.default({
49
51
  dev: this.dev,
50
52
  devMiddleware: options.devMiddleware
51
53
  });
52
54
  }
53
- getDevOptions(options) {
54
- const devOptions = typeof options.dev === "boolean" ? {} : options.dev;
55
- const defaultOptions = (0, import_constants.getDefaultDevOptions)();
56
- return (0, import_deepmerge.deepmerge)(defaultOptions, devOptions);
57
- }
58
55
  applySetupMiddlewares() {
59
56
  const setupMiddlewares = this.dev.setupMiddlewares || [];
60
57
  const serverOptions = {
@@ -106,8 +103,22 @@ class RsbuildDevServer {
106
103
  }
107
104
  next();
108
105
  });
106
+ if (dev.proxy) {
107
+ const { middlewares, handleUpgrade } = (0, import_proxy.createProxyMiddleware)(dev.proxy);
108
+ app && handleUpgrade(app);
109
+ middlewares.forEach((middleware) => {
110
+ this.middlewares.use(middleware);
111
+ });
112
+ }
109
113
  devMiddleware.init(app);
110
114
  devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
115
+ this.middlewares.use(
116
+ (0, import_middlewares.getHtmlFallbackMiddleware)({
117
+ distPath: (0, import_path.join)(this.pwd, this.output.distPath),
118
+ assetPrefix: this.output.assetPrefix,
119
+ callback: devMiddleware.middleware
120
+ })
121
+ );
111
122
  if (dev.historyApiFallback) {
112
123
  const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("connect-history-api-fallback")));
113
124
  const historyApiFallbackMiddleware = connectHistoryApiFallback(
@@ -117,6 +128,8 @@ class RsbuildDevServer {
117
128
  this.middlewares.use(historyApiFallbackMiddleware);
118
129
  devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
119
130
  }
131
+ this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
132
+ this.middlewares.use(import_middlewares.notFoundMiddleware);
120
133
  }
121
134
  async createHTTPServer() {
122
135
  const { dev } = this;
@@ -143,30 +156,85 @@ class RsbuildDevServer {
143
156
  this.app.close();
144
157
  }
145
158
  }
146
- async function createDevServer(options) {
147
- var _a;
148
- const { server: serverOptions = {}, ...devOptions } = options;
149
- const logger = (_a = serverOptions.logger) != null ? _a : import_shared.logger;
150
- const devServer = new RsbuildDevServer(devOptions);
151
- const httpServer = serverOptions.customApp || await devServer.createHTTPServer();
152
- const server = {
153
- middlewares: devServer.middlewares,
154
- init: async () => {
155
- await devServer.onInit(httpServer);
156
- },
157
- // resolvedConfig,
158
- listen: (options2, cb) => {
159
- devServer.listen(options2, cb);
160
- },
161
- logger,
162
- close: () => {
163
- devServer.close();
164
- }
159
+ async function startDevServer(options, startDevCompile, {
160
+ open,
161
+ compiler,
162
+ printURLs = true,
163
+ strictPort = false,
164
+ logger: customLogger,
165
+ getPortSilently
166
+ } = {}) {
167
+ var _a, _b, _c;
168
+ if (!process.env.NODE_ENV) {
169
+ process.env.NODE_ENV = "development";
170
+ }
171
+ const rsbuildConfig = options.context.config;
172
+ const logger = customLogger != null ? customLogger : import_shared.logger;
173
+ const { devServerConfig, port, host, https } = await (0, import_shared.getDevOptions)({
174
+ rsbuildConfig,
175
+ strictPort,
176
+ getPortSilently
177
+ });
178
+ options.context.devServer = {
179
+ hostname: host,
180
+ port,
181
+ https,
182
+ open
165
183
  };
166
- return server;
184
+ const protocol = https ? "https" : "http";
185
+ let urls = (0, import_shared.getAddressUrls)(protocol, port, (_a = rsbuildConfig.dev) == null ? void 0 : _a.host);
186
+ if (printURLs) {
187
+ if ((0, import_shared.isFunction)(printURLs)) {
188
+ urls = printURLs(urls);
189
+ if (!Array.isArray(urls)) {
190
+ throw new Error("Please return an array in the `printURLs` function.");
191
+ }
192
+ }
193
+ (0, import_shared.printServerURLs)(urls, options.context.entry, logger);
194
+ }
195
+ (0, import_shared.debug)("create dev server");
196
+ const devMiddleware = await startDevCompile(options, compiler);
197
+ const server = new RsbuildDevServer({
198
+ pwd: options.context.rootPath,
199
+ devMiddleware,
200
+ dev: devServerConfig,
201
+ output: {
202
+ distPath: ((_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.root) || import_shared.ROOT_DIST_DIR,
203
+ assetPrefix: typeof devServerConfig.assetPrefix === "string" && !(0, import_shared.isURL)(devServerConfig.assetPrefix) ? devServerConfig.assetPrefix : ""
204
+ }
205
+ });
206
+ (0, import_shared.debug)("create dev server done");
207
+ await options.context.hooks.onBeforeStartDevServerHook.call();
208
+ const httpServer = await server.createHTTPServer();
209
+ await server.onInit(httpServer);
210
+ (0, import_shared.debug)("listen dev server");
211
+ return new Promise((resolve) => {
212
+ server.listen(
213
+ {
214
+ host,
215
+ port
216
+ },
217
+ async (err) => {
218
+ if (err) {
219
+ throw err;
220
+ }
221
+ (0, import_shared.debug)("listen dev server done");
222
+ await options.context.hooks.onAfterStartDevServerHook.call({ port });
223
+ resolve({
224
+ port,
225
+ urls: urls.map((item) => item.url),
226
+ server: {
227
+ close: () => {
228
+ server.close();
229
+ }
230
+ }
231
+ });
232
+ }
233
+ );
234
+ });
167
235
  }
168
236
  // Annotate the CommonJS export names for ESM import in node:
169
237
  0 && (module.exports = {
170
238
  RsbuildDevServer,
171
- createDevServer
239
+ startDevServer
172
240
  });
@@ -1,2 +1,2 @@
1
- export { createDevServer } from './devServer';
1
+ export { startDevServer } from './devServer';
2
2
  export { startProdServer } from './prodServer';
@@ -18,7 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var server_exports = {};
20
20
  __export(server_exports, {
21
- createDevServer: () => import_devServer.createDevServer,
21
+ startDevServer: () => import_devServer.startDevServer,
22
22
  startProdServer: () => import_prodServer.startProdServer
23
23
  });
24
24
  module.exports = __toCommonJS(server_exports);
@@ -26,6 +26,6 @@ var import_devServer = require("./devServer");
26
26
  var import_prodServer = require("./prodServer");
27
27
  // Annotate the CommonJS export names for ESM import in node:
28
28
  0 && (module.exports = {
29
- createDevServer,
29
+ startDevServer,
30
30
  startProdServer
31
31
  });
@@ -0,0 +1,8 @@
1
+ import { RequestHandler as Middleware } from '@rsbuild/shared';
2
+ export declare const faviconFallbackMiddleware: Middleware;
3
+ export declare const notFoundMiddleware: Middleware;
4
+ export declare const getHtmlFallbackMiddleware: (params: {
5
+ distPath: string;
6
+ assetPrefix: string;
7
+ callback?: Middleware;
8
+ }) => Middleware;
@@ -0,0 +1,103 @@
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 middlewares_exports = {};
30
+ __export(middlewares_exports, {
31
+ faviconFallbackMiddleware: () => faviconFallbackMiddleware,
32
+ getHtmlFallbackMiddleware: () => getHtmlFallbackMiddleware,
33
+ notFoundMiddleware: () => notFoundMiddleware
34
+ });
35
+ module.exports = __toCommonJS(middlewares_exports);
36
+ var import_shared = require("@rsbuild/shared");
37
+ var import_path = __toESM(require("path"));
38
+ var import_fs = __toESM(require("fs"));
39
+ const faviconFallbackMiddleware = (req, res, next) => {
40
+ if (req.url === "/favicon.ico") {
41
+ res.statusCode = 204;
42
+ res.end();
43
+ } else {
44
+ next();
45
+ }
46
+ };
47
+ const notFoundMiddleware = (_req, res, _next) => {
48
+ res.statusCode = 404;
49
+ res.end();
50
+ };
51
+ const getHtmlFallbackMiddleware = ({ assetPrefix, distPath, callback }) => {
52
+ return (req, res, next) => {
53
+ if (
54
+ // Only accept GET or HEAD
55
+ req.method !== "GET" && req.method !== "HEAD" || // Require Accept header
56
+ !req.headers || typeof req.headers.accept !== "string" || // Ignore JSON requests
57
+ req.headers.accept.includes("application/json") || // Require Accept: text/html or */*
58
+ !(req.headers.accept.includes("text/html") || req.headers.accept.includes("*/*")) || !req.url
59
+ ) {
60
+ return next();
61
+ }
62
+ const { url } = req;
63
+ const pathname = decodeURIComponent(url);
64
+ let outputFileSystem = import_fs.default;
65
+ if (res.locals.webpack) {
66
+ const { devMiddleware } = res.locals.webpack;
67
+ outputFileSystem = devMiddleware.outputFileSystem;
68
+ }
69
+ const tryRewrite = (filePath, newUrl) => {
70
+ var _a;
71
+ if (outputFileSystem.existsSync(filePath) && callback) {
72
+ newUrl = (0, import_shared.urlJoin)(assetPrefix, newUrl);
73
+ (_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
74
+ req.url = newUrl;
75
+ return callback(req, res, (...args) => {
76
+ req.url = url;
77
+ next(...args);
78
+ });
79
+ }
80
+ };
81
+ if (pathname.endsWith("/")) {
82
+ const newUrl = url + "index.html";
83
+ const filePath = import_path.default.join(distPath, pathname, "index.html");
84
+ tryRewrite(filePath, newUrl);
85
+ } else if (
86
+ // '/main' => '/main.html'
87
+ !pathname.endsWith(".html")
88
+ ) {
89
+ const newUrl = url + ".html";
90
+ const filePath = import_path.default.join(distPath, pathname + ".html");
91
+ tryRewrite(filePath, newUrl);
92
+ } else {
93
+ tryRewrite(import_path.default.join(distPath, pathname), url);
94
+ }
95
+ next();
96
+ };
97
+ };
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ faviconFallbackMiddleware,
101
+ getHtmlFallbackMiddleware,
102
+ notFoundMiddleware
103
+ });
@@ -18,6 +18,7 @@ export declare class RsbuildProdServer {
18
18
  constructor(options: RsbuildProdServerOptions);
19
19
  onInit(app: Server): Promise<void>;
20
20
  private applyDefaultMiddlewares;
21
+ private applyStaticAssetMiddleware;
21
22
  createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
22
23
  listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
23
24
  close(): void;
@@ -37,6 +37,7 @@ var import_connect = __toESM(require("connect"));
37
37
  var import_path = require("path");
38
38
  var import_sirv = __toESM(require("sirv"));
39
39
  var import_shared = require("@rsbuild/shared");
40
+ var import_middlewares = require("./middlewares");
40
41
  class RsbuildProdServer {
41
42
  constructor(options) {
42
43
  this.middlewares = (0, import_connect.default)();
@@ -48,6 +49,10 @@ class RsbuildProdServer {
48
49
  await this.applyDefaultMiddlewares();
49
50
  }
50
51
  async applyDefaultMiddlewares() {
52
+ this.applyStaticAssetMiddleware();
53
+ this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
54
+ }
55
+ applyStaticAssetMiddleware() {
51
56
  const {
52
57
  output: { path, assetPrefix },
53
58
  pwd
@@ -110,16 +115,14 @@ async function startProdServer(context, rsbuildConfig) {
110
115
  },
111
116
  () => {
112
117
  const urls = (0, import_shared.getAddressUrls)("http", port);
113
- (0, import_shared.printServerURLs)(urls);
118
+ (0, import_shared.printServerURLs)(urls, context.entry);
114
119
  resolve({
115
120
  port,
116
121
  urls: urls.map((item) => item.url),
117
122
  server: {
118
- middlewares: server.middlewares,
119
123
  close: () => {
120
124
  server.close();
121
125
  }
122
- // TODO: decouple with Modern.js server
123
126
  }
124
127
  });
125
128
  }
@@ -0,0 +1,9 @@
1
+ import http from 'http';
2
+ import { RequestHandler } from 'http-proxy-middleware';
3
+ import { ProxyDetail, RequestHandler as Middleware, RsbuildProxyOptions } from '@rsbuild/shared';
4
+ export declare function formatProxyOptions(proxyOptions: RsbuildProxyOptions): ProxyDetail[];
5
+ export type HttpUpgradeHandler = NonNullable<RequestHandler['upgrade']>;
6
+ export declare const createProxyMiddleware: (proxyOptions: RsbuildProxyOptions) => {
7
+ middlewares: Middleware[];
8
+ handleUpgrade: (server: http.Server) => void;
9
+ };
@@ -0,0 +1,92 @@
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 proxy_exports = {};
20
+ __export(proxy_exports, {
21
+ createProxyMiddleware: () => createProxyMiddleware,
22
+ formatProxyOptions: () => formatProxyOptions
23
+ });
24
+ module.exports = __toCommonJS(proxy_exports);
25
+ var import_http_proxy_middleware2 = require("http-proxy-middleware/dist/http-proxy-middleware");
26
+ function formatProxyOptions(proxyOptions) {
27
+ var _a;
28
+ const ret = [];
29
+ if (Array.isArray(proxyOptions)) {
30
+ ret.push(...proxyOptions);
31
+ } else if ("target" in proxyOptions) {
32
+ ret.push(proxyOptions);
33
+ } else {
34
+ for (const [context, options] of Object.entries(proxyOptions)) {
35
+ const opts = {
36
+ context,
37
+ changeOrigin: true,
38
+ logLevel: "warn"
39
+ };
40
+ if (typeof options === "string") {
41
+ opts.target = options;
42
+ } else {
43
+ Object.assign(opts, options);
44
+ }
45
+ ret.push(opts);
46
+ }
47
+ }
48
+ const handleError = (err, _req, _res, _target) => {
49
+ console.error(err);
50
+ };
51
+ for (const opts of ret) {
52
+ (_a = opts.onError) != null ? _a : opts.onError = handleError;
53
+ }
54
+ return ret;
55
+ }
56
+ const createProxyMiddleware = (proxyOptions) => {
57
+ const formattedOptionsList = formatProxyOptions(proxyOptions);
58
+ const proxies = [];
59
+ const middlewares = [];
60
+ for (const opts of formattedOptionsList) {
61
+ const proxy = new import_http_proxy_middleware2.HttpProxyMiddleware(opts.context, opts);
62
+ const middleware = async (req, res, next) => {
63
+ const bypassUrl = typeof opts.bypass === "function" ? opts.bypass(req, res, opts) : null;
64
+ if (typeof bypassUrl === "boolean") {
65
+ res.statusCode = 404;
66
+ next();
67
+ } else if (typeof bypassUrl === "string") {
68
+ req.url = bypassUrl;
69
+ next();
70
+ } else {
71
+ proxy.middleware(req, res, next);
72
+ }
73
+ };
74
+ proxies.push(proxy);
75
+ middlewares.push(middleware);
76
+ }
77
+ const handleUpgrade = (server) => {
78
+ for (const proxy of proxies) {
79
+ const raw = proxy;
80
+ if (raw.proxyOptions.ws === true && !raw.wsInternalSubscribed) {
81
+ server.on("upgrade", raw.handleUpgrade);
82
+ raw.wsInternalSubscribed = true;
83
+ }
84
+ }
85
+ };
86
+ return { middlewares, handleUpgrade };
87
+ };
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ createProxyMiddleware,
91
+ formatProxyOptions
92
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
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": {
@@ -86,8 +86,9 @@
86
86
  "core-js": "~3.32.2",
87
87
  "filesize": "^8.0.7",
88
88
  "gzip-size": "^6.0.0",
89
- "html-webpack-plugin": "5.5.3",
89
+ "html-webpack-plugin": "npm:html-rspack-plugin@5.5.4",
90
90
  "http-compression": "1.0.6",
91
+ "http-proxy-middleware": "^2.0.1",
91
92
  "jiti": "^1.20.0",
92
93
  "lodash": "^4.17.21",
93
94
  "open": "^8.4.0",
@@ -97,7 +98,7 @@
97
98
  "sirv": "^2.0.3",
98
99
  "strip-ansi": "^6.0.1",
99
100
  "ws": "^8.2.0",
100
- "@rsbuild/shared": "0.0.18"
101
+ "@rsbuild/shared": "0.0.20"
101
102
  },
102
103
  "devDependencies": {
103
104
  "@types/connect": "3.4.35",
package/types.d.ts CHANGED
@@ -5,99 +5,139 @@ declare module '*.bmp' {
5
5
  const src: string;
6
6
  export default src;
7
7
  }
8
- declare module '*.bmp?url' {
8
+ declare module '*.gif' {
9
9
  const src: string;
10
10
  export default src;
11
11
  }
12
- declare module '*.bmp?inline' {
12
+ declare module '*.jpg' {
13
13
  const src: string;
14
14
  export default src;
15
15
  }
16
- declare module '*.gif' {
16
+ declare module '*.jpeg' {
17
17
  const src: string;
18
18
  export default src;
19
19
  }
20
- declare module '*.gif?url' {
20
+ declare module '*.png' {
21
21
  const src: string;
22
22
  export default src;
23
23
  }
24
- declare module '*.gif?inline' {
24
+ declare module '*.ico' {
25
25
  const src: string;
26
26
  export default src;
27
27
  }
28
- declare module '*.jpg' {
28
+ declare module '*.webp' {
29
29
  const src: string;
30
30
  export default src;
31
31
  }
32
- declare module '*.jpg?url' {
32
+ declare module '*.svg' {
33
33
  const src: string;
34
34
  export default src;
35
35
  }
36
- declare module '*.jpg?inline' {
36
+ declare module '*.apng' {
37
37
  const src: string;
38
38
  export default src;
39
39
  }
40
- declare module '*.jpeg' {
40
+ declare module '*.avif' {
41
41
  const src: string;
42
42
  export default src;
43
43
  }
44
- declare module '*.jpeg?url' {
44
+ declare module '*.tiff' {
45
45
  const src: string;
46
46
  export default src;
47
47
  }
48
- declare module '*.jpeg?inline' {
48
+
49
+ /**
50
+ * Font assets
51
+ */
52
+ declare module '*.woff' {
49
53
  const src: string;
50
54
  export default src;
51
55
  }
52
- declare module '*.png' {
56
+ declare module '*.woff2' {
53
57
  const src: string;
54
58
  export default src;
55
59
  }
56
- declare module '*.png?url' {
60
+ declare module '*.eot' {
57
61
  const src: string;
58
62
  export default src;
59
63
  }
60
- declare module '*.png?inline' {
64
+ declare module '*.ttf' {
61
65
  const src: string;
62
66
  export default src;
63
67
  }
64
- declare module '*.ico' {
68
+ declare module '*.otf' {
69
+ const src: string;
70
+ export default src;
71
+ }
72
+ declare module '*.ttc' {
65
73
  const src: string;
66
74
  export default src;
67
75
  }
68
- declare module '*.ico?url' {
76
+
77
+ /**
78
+ * Media assets
79
+ */
80
+ declare module '*.mp4' {
69
81
  const src: string;
70
82
  export default src;
71
83
  }
72
- declare module '*.ico?inline' {
84
+ declare module '*.webm' {
73
85
  const src: string;
74
86
  export default src;
75
87
  }
76
- declare module '*.webp' {
88
+ declare module '*.ogg' {
77
89
  const src: string;
78
90
  export default src;
79
91
  }
80
- declare module '*.webp?url' {
92
+ declare module '*.mp3' {
81
93
  const src: string;
82
94
  export default src;
83
95
  }
84
- declare module '*.webp?inline' {
96
+ declare module '*.wav' {
85
97
  const src: string;
86
98
  export default src;
87
99
  }
88
- declare module '*.svg' {
100
+ declare module '*.flac' {
89
101
  const src: string;
90
102
  export default src;
91
103
  }
92
- declare module '*.svg?url' {
104
+ declare module '*.aac' {
93
105
  const src: string;
94
106
  export default src;
95
107
  }
96
- declare module '*.svg?inline' {
108
+ declare module '*.mov' {
97
109
  const src: string;
98
110
  export default src;
99
111
  }
100
112
 
113
+ /**
114
+ * Configuration files
115
+ */
116
+ declare module '*.yaml' {
117
+ const content: Record<string, any>;
118
+ export default content;
119
+ }
120
+ declare module '*.yml' {
121
+ const content: Record<string, any>;
122
+ export default content;
123
+ }
124
+ declare module '*.toml' {
125
+ const content: Record<string, any>;
126
+ export default content;
127
+ }
128
+
129
+ /**
130
+ * Queries
131
+ */
132
+ declare module '*?url' {
133
+ const content: string;
134
+ export default content;
135
+ }
136
+ declare module '*?inline' {
137
+ const content: string;
138
+ export default content;
139
+ }
140
+
101
141
  /**
102
142
  * CSS Modules
103
143
  */
@@ -1,5 +0,0 @@
1
- import { StartDevServerOptions, type RspackCompiler, type RspackMultiCompiler } from '@rsbuild/shared';
2
- import { type InitConfigsOptions } from './initConfigs';
3
- type ServerOptions = Exclude<StartDevServerOptions['serverOptions'], undefined>;
4
- export declare function createDevServer(options: InitConfigsOptions, port: number, serverOptions: ServerOptions, customCompiler?: RspackCompiler | RspackMultiCompiler): Promise<import("@rsbuild/shared").ServerApi>;
5
- export {};
@@ -1,59 +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 startDevServer_exports = {};
20
- __export(startDevServer_exports, {
21
- createDevServer: () => createDevServer
22
- });
23
- module.exports = __toCommonJS(startDevServer_exports);
24
- var import_shared = require("@rsbuild/shared");
25
- var import_createCompiler = require("./createCompiler");
26
- var import_devMiddleware = require("./devMiddleware");
27
- var import_initConfigs = require("./initConfigs");
28
- var import_server = require("../../server");
29
- async function createDevServer(options, port, serverOptions, customCompiler) {
30
- let compiler;
31
- if (customCompiler) {
32
- compiler = customCompiler;
33
- } else {
34
- const { rspackConfigs } = await (0, import_initConfigs.initConfigs)(options);
35
- compiler = await (0, import_createCompiler.createCompiler)({
36
- context: options.context,
37
- rspackConfigs
38
- });
39
- }
40
- (0, import_shared.debug)("create dev server");
41
- const rsbuildConfig = options.context.config;
42
- const { devConfig } = await (0, import_shared.getDevServerOptions)({
43
- rsbuildConfig,
44
- serverOptions,
45
- port
46
- });
47
- const server = await (0, import_server.createDevServer)({
48
- pwd: options.context.rootPath,
49
- devMiddleware: (0, import_devMiddleware.getDevMiddleware)(compiler),
50
- ...serverOptions,
51
- dev: devConfig
52
- });
53
- (0, import_shared.debug)("create dev server done");
54
- return server;
55
- }
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- createDevServer
59
- });
@@ -1,3 +0,0 @@
1
- import type { ModifyRspackConfigUtils } from '@rsbuild/shared';
2
- import type { RspackConfig } from '@rsbuild/shared';
3
- export type ModifyRspackConfigFn = (config: RspackConfig, utils: ModifyRspackConfigUtils) => Promise<RspackConfig | void> | RspackConfig | void;
@@ -1,16 +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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var hooks_exports = {};
16
- module.exports = __toCommonJS(hooks_exports);
@@ -1,6 +0,0 @@
1
- import type { DevServerOptions } from '@rsbuild/shared';
2
- /**
3
- * hmr socket connect path
4
- */
5
- export declare const HMR_SOCK_PATH = "/webpack-hmr";
6
- export declare const getDefaultDevOptions: () => DevServerOptions;
@@ -1,49 +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 constants_exports = {};
20
- __export(constants_exports, {
21
- HMR_SOCK_PATH: () => HMR_SOCK_PATH,
22
- getDefaultDevOptions: () => getDefaultDevOptions
23
- });
24
- module.exports = __toCommonJS(constants_exports);
25
- const HMR_SOCK_PATH = "/webpack-hmr";
26
- const getDefaultDevOptions = () => {
27
- return {
28
- client: {
29
- path: HMR_SOCK_PATH,
30
- // By default it is set to the port number of the dev server
31
- port: "",
32
- // By default it is set to "location.hostname"
33
- host: "",
34
- // By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
35
- protocol: ""
36
- },
37
- https: false,
38
- devMiddleware: { writeToDisk: true },
39
- watch: true,
40
- hot: true,
41
- compress: true,
42
- liveReload: true
43
- };
44
- };
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- HMR_SOCK_PATH,
48
- getDefaultDevOptions
49
- });