@rsbuild/core 1.0.9 → 1.0.11

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.
@@ -24,7 +24,7 @@ export declare function defineConfig(config: RsbuildConfig): RsbuildConfig;
24
24
  export declare function defineConfig(config: RsbuildConfigSyncFn): RsbuildConfigSyncFn;
25
25
  export declare function defineConfig(config: RsbuildConfigAsyncFn): RsbuildConfigAsyncFn;
26
26
  export declare function defineConfig(config: RsbuildConfigExport): RsbuildConfigExport;
27
- export declare function watchFiles(files: string[], watchOptions?: WatchOptions): Promise<void>;
27
+ export declare function watchFilesForRestart(files: string[], watchOptions?: WatchOptions): Promise<void>;
28
28
  export declare function loadConfig({ cwd, path, envMode, }?: {
29
29
  cwd?: string;
30
30
  path?: string;
@@ -18,6 +18,7 @@ export declare const DEFAULT_DATA_URL_SIZE = 4096;
18
18
  export declare const DEFAULT_MOUNT_ID = "root";
19
19
  export declare const DEFAULT_DEV_HOST = "0.0.0.0";
20
20
  export declare const DEFAULT_ASSET_PREFIX = "/";
21
+ export declare const DEFAULT_BASE_URL = "/";
21
22
  export declare const DEFAULT_WEB_BROWSERSLIST: string[];
22
23
  export declare const DEFAULT_BROWSERSLIST: Record<string, string[]>;
23
24
  export declare const HTML_REGEX: RegExp;
@@ -15,7 +15,7 @@ export { logger } from './logger';
15
15
  export { mergeRsbuildConfig } from './mergeConfig';
16
16
  export { ensureAssetPrefix } from './helpers';
17
17
  export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME } from './constants';
18
- export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, CacheGroup, CacheGroups, Charset, ClientConfig, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateCompilerOptions, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, LegalComments, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSPlugin, PreconnectOption, ProxyConfig, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildTarget, RspackChain, RspackRule, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
18
+ export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, CacheGroup, CacheGroups, Charset, ClientConfig, CliShortcut, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, LegalComments, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProxyConfig, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildTarget, RspackChain, RspackRule, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
19
19
  export type { ChainIdentifier } from './configChain';
20
20
  export {
21
21
  /**
@@ -0,0 +1,9 @@
1
+ import type { CliShortcut, NormalizedDevConfig } from '../types/config';
2
+ export declare const isCliShortcutsEnabled: (devConfig: NormalizedDevConfig) => boolean;
3
+ export declare function setupCliShortcuts({ openPage, closeServer, printUrls, restartServer, customShortcuts, }: {
4
+ openPage: () => Promise<void>;
5
+ closeServer: () => Promise<void>;
6
+ printUrls: () => void;
7
+ restartServer?: () => Promise<void>;
8
+ customShortcuts?: (shortcuts: CliShortcut[]) => CliShortcut[];
9
+ }): void;
@@ -14,9 +14,11 @@ export type StartServerResult = {
14
14
  };
15
15
  };
16
16
  export declare const normalizeUrl: (url: string) => string;
17
+ export declare const joinUrlSegments: (s1: string, s2: string) => string;
18
+ export declare const stripBase: (path: string, base: string) => string;
17
19
  export declare const getRoutes: (context: InternalContext) => Routes;
18
- export declare const formatRoutes: (entry: RsbuildEntry, prefix: string | undefined, outputStructure: OutputStructure | undefined) => Routes;
19
- export declare function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, }: {
20
+ export declare const formatRoutes: (entry: RsbuildEntry, base: string, distPathPrefix: string | undefined, outputStructure: OutputStructure | undefined) => Routes;
21
+ export declare function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, trailingLineBreak, }: {
20
22
  urls: Array<{
21
23
  url: string;
22
24
  label: string;
@@ -25,6 +27,7 @@ export declare function printServerURLs({ urls: originalUrls, port, routes, prot
25
27
  routes: Routes;
26
28
  protocol: string;
27
29
  printUrls?: PrintUrls;
30
+ trailingLineBreak?: boolean;
28
31
  }): string | null;
29
32
  /**
30
33
  * Get available free port.
@@ -11,6 +11,12 @@ export declare const getHtmlCompletionMiddleware: (params: {
11
11
  callback: Middleware;
12
12
  outputFileSystem: Rspack.OutputFileSystem;
13
13
  }) => Middleware;
14
+ /**
15
+ * handle `server.base`
16
+ */
17
+ export declare const getBaseMiddleware: (params: {
18
+ base: string;
19
+ }) => Middleware;
14
20
  /**
15
21
  * support HTML fallback in some edge cases
16
22
  */
@@ -1,7 +1,7 @@
1
1
  import type { Server } from 'node:http';
2
2
  import type { Http2SecureServer } from 'node:http2';
3
3
  import type Connect from '../../compiled/connect';
4
- import type { InternalContext, NormalizedConfig, PreviewServerOptions, ServerConfig } from '../types';
4
+ import type { InternalContext, NormalizedConfig, PreviewOptions, ServerConfig } from '../types';
5
5
  import { type StartServerResult } from './helper';
6
6
  type RsbuildProdServerOptions = {
7
7
  pwd: string;
@@ -21,5 +21,5 @@ export declare class RsbuildProdServer {
21
21
  private applyStaticAssetMiddleware;
22
22
  close(): Promise<void>;
23
23
  }
24
- export declare function startProdServer(context: InternalContext, config: NormalizedConfig, { getPortSilently }?: PreviewServerOptions): Promise<StartServerResult>;
24
+ export declare function startProdServer(context: InternalContext, config: NormalizedConfig, { getPortSilently }?: PreviewOptions): Promise<StartServerResult>;
25
25
  export {};
@@ -3,7 +3,8 @@ type Cleaner = () => Promise<unknown> | unknown;
3
3
  * Add a cleaner to handle side effects
4
4
  */
5
5
  export declare const onBeforeRestartServer: (cleaner: Cleaner) => void;
6
- export declare const restartDevServer: ({ filePath, }: {
7
- filePath: string;
6
+ export declare const restartDevServer: ({ filePath, clear, }?: {
7
+ filePath?: string;
8
+ clear?: boolean;
8
9
  }) => Promise<void>;
9
10
  export {};
@@ -220,6 +220,12 @@ export type PublicDirOptions = {
220
220
  };
221
221
  export type PublicDir = false | PublicDirOptions | PublicDirOptions[];
222
222
  export interface ServerConfig {
223
+ /**
224
+ * Configure the base path of the server.
225
+ *
226
+ * @default '/'
227
+ */
228
+ base?: string;
223
229
  /**
224
230
  * Whether to enable gzip compression
225
231
  */
@@ -273,7 +279,7 @@ export interface ServerConfig {
273
279
  */
274
280
  printUrls?: PrintUrls;
275
281
  }
276
- export type NormalizedServerConfig = ServerConfig & Required<Pick<ServerConfig, 'htmlFallback' | 'port' | 'host' | 'compress' | 'strictPort' | 'printUrls' | 'open'>>;
282
+ export type NormalizedServerConfig = ServerConfig & Required<Pick<ServerConfig, 'htmlFallback' | 'port' | 'host' | 'compress' | 'strictPort' | 'printUrls' | 'open' | 'base'>>;
277
283
  export type SriAlgorithm = 'sha256' | 'sha384' | 'sha512';
278
284
  export type SriOptions = {
279
285
  algorithm?: SriAlgorithm;
@@ -933,6 +939,20 @@ export type WatchFiles = {
933
939
  options?: WatchOptions;
934
940
  type?: 'reload-page' | 'reload-server';
935
941
  };
942
+ export type CliShortcut = {
943
+ /**
944
+ * The key to trigger the shortcut.
945
+ */
946
+ key: string;
947
+ /**
948
+ * The description of the shortcut.
949
+ */
950
+ description: string;
951
+ /**
952
+ * The action to execute when the shortcut is triggered.
953
+ */
954
+ action: () => void | Promise<void>;
955
+ };
936
956
  export interface DevConfig {
937
957
  /**
938
958
  * Whether to enable Hot Module Replacement.
@@ -955,6 +975,17 @@ export interface DevConfig {
955
975
  * Config for Rsbuild client code.
956
976
  */
957
977
  client?: ClientConfig;
978
+ /**
979
+ * Whether to enable CLI shortcuts.
980
+ */
981
+ cliShortcuts?: boolean | {
982
+ /**
983
+ * Customize the CLI shortcuts.
984
+ * @param shortcuts - The default CLI shortcuts.
985
+ * @returns - The customized CLI shortcuts.
986
+ */
987
+ custom?: (shortcuts?: CliShortcut[]) => CliShortcut[];
988
+ };
958
989
  /**
959
990
  * Provides the ability to execute a custom function and apply custom middlewares.
960
991
  */
@@ -967,14 +998,14 @@ export interface DevConfig {
967
998
  /**
968
999
  * This option allows you to configure a list of globs/directories/files to watch for file changes.
969
1000
  */
970
- watchFiles?: WatchFiles;
1001
+ watchFiles?: WatchFiles | WatchFiles[];
971
1002
  /**
972
1003
  * Enable lazy compilation.
973
1004
  * @default false
974
1005
  */
975
1006
  lazyCompilation?: boolean | Rspack.LazyCompilationOptions;
976
1007
  }
977
- export type NormalizedDevConfig = DevConfig & Required<Pick<DevConfig, 'hmr' | 'liveReload' | 'assetPrefix' | 'writeToDisk'>> & {
1008
+ export type NormalizedDevConfig = DevConfig & Required<Pick<DevConfig, 'hmr' | 'liveReload' | 'assetPrefix' | 'writeToDisk' | 'cliShortcuts'>> & {
978
1009
  client: NormalizedClientConfig;
979
1010
  };
980
1011
  export type ModuleFederationConfig = {
@@ -8,11 +8,15 @@ import type { PluginManager, RsbuildPluginAPI } from './plugin';
8
8
  import type { Rspack } from './rspack';
9
9
  import type { WebpackConfig } from './thirdParty';
10
10
  export type Bundler = 'rspack' | 'webpack';
11
- export type CreateCompilerOptions = {
12
- watch?: boolean;
13
- };
14
11
  export type StartDevServerOptions = {
12
+ /**
13
+ * Using a custom Rspack Compiler object.
14
+ */
15
15
  compiler?: Compiler | MultiCompiler;
16
+ /**
17
+ * Whether to get port silently and not print any logs.
18
+ * @default false
19
+ */
16
20
  getPortSilently?: boolean;
17
21
  };
18
22
  export type CreateDevServerOptions = StartDevServerOptions & {
@@ -23,8 +27,17 @@ export type CreateDevServerOptions = StartDevServerOptions & {
23
27
  */
24
28
  runCompile?: boolean;
25
29
  };
26
- export type PreviewServerOptions = {
30
+ export type PreviewOptions = {
31
+ /**
32
+ * Whether to get port silently and not print any logs.
33
+ * @default false
34
+ */
27
35
  getPortSilently?: boolean;
36
+ /**
37
+ * Whether to check if the dist directory exists and is not empty.
38
+ * @default true
39
+ */
40
+ checkDistDir?: boolean;
28
41
  };
29
42
  export type BuildOptions = {
30
43
  /**
@@ -67,7 +80,7 @@ export type InspectConfigResult<B extends 'rspack' | 'webpack' = 'rspack'> = {
67
80
  bundlerConfigs: B extends 'rspack' ? Rspack.Configuration[] : WebpackConfig[];
68
81
  };
69
82
  };
70
- export type CreateCompiler = <C = Compiler | MultiCompiler>(options?: CreateCompilerOptions) => Promise<C>;
83
+ export type CreateCompiler = <C = Compiler | MultiCompiler>() => Promise<C>;
71
84
  export type CreateRsbuildOptions = {
72
85
  /** The root path of current project. */
73
86
  cwd?: string;
@@ -104,7 +117,7 @@ export type RsbuildInstance = {
104
117
  removePlugins: PluginManager['removePlugins'];
105
118
  isPluginExists: PluginManager['isPluginExists'];
106
119
  build: ProviderInstance['build'];
107
- preview: (options?: PreviewServerOptions) => Promise<StartServerResult>;
120
+ preview: (options?: PreviewOptions) => Promise<StartServerResult>;
108
121
  initConfigs: ProviderInstance['initConfigs'];
109
122
  inspectConfig: ProviderInstance['inspectConfig'];
110
123
  createCompiler: ProviderInstance['createCompiler'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -88,7 +88,7 @@
88
88
  "sirv": "^2.0.4",
89
89
  "style-loader": "3.3.4",
90
90
  "tsc-alias": "^1.8.10",
91
- "typescript": "^5.5.2",
91
+ "typescript": "^5.6.2",
92
92
  "webpack": "^5.95.0",
93
93
  "webpack-bundle-analyzer": "^4.10.2",
94
94
  "webpack-merge": "6.0.1",