@rsbuild/core 2.0.0-beta.1 → 2.0.0-beta.10

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 (131) hide show
  1. package/compiled/chokidar/index.d.ts +197 -29
  2. package/compiled/chokidar/package.json +1 -1
  3. package/compiled/connect-next/index.d.ts +56 -0
  4. package/compiled/connect-next/license +26 -0
  5. package/compiled/connect-next/package.json +1 -0
  6. package/compiled/cors/index.d.ts +56 -0
  7. package/compiled/cors/license +22 -0
  8. package/compiled/cors/package.json +1 -0
  9. package/compiled/css-loader/index.js +2 -2
  10. package/compiled/css-loader/package.json +1 -1
  11. package/compiled/html-rspack-plugin/index.js +15 -15
  12. package/compiled/html-rspack-plugin/package.json +1 -1
  13. package/compiled/jiti/LICENSE +21 -0
  14. package/compiled/jiti/README.md +243 -0
  15. package/compiled/jiti/dist/babel.cjs +46699 -0
  16. package/compiled/jiti/dist/jiti.cjs +4842 -0
  17. package/compiled/jiti/lib/jiti-cli.mjs +19 -0
  18. package/compiled/jiti/lib/jiti-hooks.mjs +89 -0
  19. package/compiled/jiti/lib/jiti-native.mjs +76 -0
  20. package/compiled/jiti/lib/jiti-register.d.mts +1 -0
  21. package/compiled/jiti/lib/jiti-register.mjs +2 -0
  22. package/compiled/jiti/lib/jiti.cjs +24 -0
  23. package/compiled/jiti/lib/jiti.d.cts +8 -0
  24. package/compiled/jiti/lib/jiti.d.mts +8 -0
  25. package/compiled/jiti/lib/jiti.mjs +23 -0
  26. package/compiled/jiti/lib/types.d.ts +363 -0
  27. package/compiled/jiti/package.json +133 -0
  28. package/compiled/postcss/index.js +1 -1
  29. package/compiled/postcss/lib/at-rule.d.ts +1 -1
  30. package/compiled/postcss/lib/comment.d.ts +1 -1
  31. package/compiled/postcss/lib/container.d.ts +1 -1
  32. package/compiled/postcss/lib/css-syntax-error.d.ts +1 -1
  33. package/compiled/postcss/lib/declaration.d.ts +1 -1
  34. package/compiled/postcss/lib/document.d.ts +1 -1
  35. package/compiled/postcss/lib/input.d.ts +1 -1
  36. package/compiled/postcss/lib/lazy-result.d.ts +1 -1
  37. package/compiled/postcss/lib/no-work-result.d.ts +1 -1
  38. package/compiled/postcss/lib/node.d.ts +1 -1
  39. package/compiled/postcss/lib/previous-map.d.ts +1 -1
  40. package/compiled/postcss/lib/processor.d.ts +1 -1
  41. package/compiled/postcss/lib/result.d.ts +1 -1
  42. package/compiled/postcss/lib/root.d.ts +1 -1
  43. package/compiled/postcss/lib/rule.d.ts +1 -1
  44. package/compiled/postcss/lib/stringifier.d.ts +1 -1
  45. package/compiled/postcss/lib/warning.d.ts +1 -1
  46. package/compiled/postcss/package.json +1 -1
  47. package/compiled/postcss-loader/index.js +10 -9
  48. package/compiled/postcss-loader/package.json +1 -1
  49. package/compiled/rslog/index.d.ts +33 -2
  50. package/compiled/rslog/package.json +1 -1
  51. package/compiled/rspack-chain/package.json +1 -1
  52. package/compiled/rspack-chain/types/index.d.ts +0 -5
  53. package/compiled/rspack-manifest-plugin/index.d.ts +48 -0
  54. package/compiled/rspack-manifest-plugin/license +21 -0
  55. package/compiled/rspack-manifest-plugin/package.json +1 -0
  56. package/compiled/style-loader/index.js +37 -94
  57. package/compiled/style-loader/package.json +1 -1
  58. package/dist/{131.js → 958.js} +1690 -1642
  59. package/dist/chokidar.js +59 -57
  60. package/dist/client/hmr.js +3 -3
  61. package/dist/client/overlay.js +2 -2
  62. package/dist/connect-next.js +268 -0
  63. package/dist/{connect.js.LICENSE.txt → connect-next.js.LICENSE.txt} +3 -13
  64. package/dist/cors.js +2 -2
  65. package/dist/http-proxy-middleware.js +2985 -0
  66. package/dist/http-proxy-middleware.js.LICENSE.txt +69 -0
  67. package/dist/index.js +1 -1
  68. package/dist/launch-editor-middleware.js +96 -16
  69. package/dist/manifest-plugin.js +18 -18
  70. package/dist/memfs.js +241 -776
  71. package/dist/{710.js → mrmime.js} +2 -1
  72. package/dist/open.js +32 -28
  73. package/dist/range-parser.js +2 -2
  74. package/dist/remapping.js +2 -2
  75. package/dist/rslib-runtime.js +4 -4
  76. package/dist/sirv.js +14 -14
  77. package/dist/src.js +510 -0
  78. package/dist/tinyglobby.js +114 -69
  79. package/dist/transformLoader.mjs +38 -1
  80. package/dist/transformRawLoader.mjs +1 -1
  81. package/dist/ws.js +1549 -0
  82. package/dist-types/createContext.d.ts +3 -2
  83. package/dist-types/helpers/format.d.ts +2 -1
  84. package/dist-types/helpers/fs.d.ts +2 -1
  85. package/dist-types/helpers/index.d.ts +1 -1
  86. package/dist-types/helpers/stats.d.ts +4 -3
  87. package/dist-types/helpers/vendors.d.ts +0 -2
  88. package/dist-types/hooks.d.ts +3 -3
  89. package/dist-types/index.d.ts +4 -3
  90. package/dist-types/initPlugins.d.ts +2 -1
  91. package/dist-types/logger.d.ts +9 -3
  92. package/dist-types/pluginManager.d.ts +2 -1
  93. package/dist-types/restart.d.ts +4 -2
  94. package/dist-types/server/assets-middleware/index.d.ts +3 -2
  95. package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +2 -1
  96. package/dist-types/server/cliShortcuts.d.ts +4 -1
  97. package/dist-types/server/devMiddlewares.d.ts +4 -6
  98. package/dist-types/server/devServer.d.ts +8 -42
  99. package/dist-types/server/helper.d.ts +50 -16
  100. package/dist-types/server/historyApiFallback.d.ts +2 -1
  101. package/dist-types/server/middlewares.d.ts +5 -3
  102. package/dist-types/server/open.d.ts +4 -2
  103. package/dist-types/server/previewServer.d.ts +4 -0
  104. package/dist-types/server/proxy.d.ts +3 -2
  105. package/dist-types/server/runner/asModule.d.ts +1 -1
  106. package/dist-types/server/serverSetup.d.ts +2 -0
  107. package/dist-types/server/socketServer.d.ts +4 -1
  108. package/dist-types/server/watchFiles.d.ts +1 -1
  109. package/dist-types/types/config.d.ts +109 -16
  110. package/dist-types/types/context.d.ts +3 -0
  111. package/dist-types/types/hooks.d.ts +17 -15
  112. package/dist-types/types/plugin.d.ts +14 -11
  113. package/dist-types/types/rsbuild.d.ts +11 -4
  114. package/dist-types/types/thirdParty.d.ts +15 -6
  115. package/package.json +22 -24
  116. package/compiled/chokidar/handler.d.ts +0 -90
  117. package/compiled/http-proxy-middleware/index.js +0 -6132
  118. package/compiled/ws/index.d.ts +0 -437
  119. package/compiled/ws/index.js +0 -3166
  120. package/compiled/ws/license +0 -20
  121. package/compiled/ws/package.json +0 -1
  122. package/dist/397.js +0 -11
  123. package/dist/7.js +0 -1
  124. package/dist/743.js +0 -7
  125. package/dist/88.js +0 -40
  126. package/dist/connect.js +0 -581
  127. package/dist-types/server/prodServer.d.ts +0 -24
  128. /package/compiled/html-rspack-plugin/{loader.js → htmlLoader.js} +0 -0
  129. /package/dist/{131.js.LICENSE.txt → 958.js.LICENSE.txt} +0 -0
  130. /package/dist/client/{59.js → 797.js} +0 -0
  131. /package/dist/{31.js → trace-mapping.js} +0 -0
@@ -3,12 +3,14 @@ import type { SecureServerSessionOptions } from 'node:http2';
3
3
  import type { ServerOptions as HttpsServerOptions } from 'node:https';
4
4
  import type { URL } from 'node:url';
5
5
  import type { CopyRspackPluginOptions, DefinePluginOptions, Externals, LightningCssMinimizerRspackPluginOptions, ModuleFederationPluginOptions, RuleSetCondition, SwcJsMinimizerRspackPluginOptions, SwcLoaderOptions } from '@rspack/core';
6
- import type { CorsOptions } from 'cors';
6
+ import type { ChokidarOptions } from '../../compiled/chokidar';
7
+ import type Cors from '../../compiled/cors';
8
+ import type { Options as HttpProxyOptions, Filter as ProxyFilter } from '../../compiled/http-proxy-middleware';
7
9
  import type RspackChain from '../../compiled/rspack-chain/types';
8
- import type { FileDescriptor } from 'rspack-manifest-plugin';
9
- import type { ChokidarOptions } from '../../compiled/chokidar/index.js';
10
- import type { Options as HttpProxyOptions, Filter as ProxyFilter } from '../../compiled/http-proxy-middleware/index.js';
10
+ import type { FileDescriptor } from '../../compiled/rspack-manifest-plugin';
11
11
  import type { RsbuildDevServer } from '../server/devServer';
12
+ import type { RsbuildPreviewServer } from '../server/previewServer';
13
+ import type { Logger } from '../logger';
12
14
  import type { EnvironmentContext, ModifyBundlerChainUtils, ModifyChainUtils, Routes } from './hooks';
13
15
  import type { RsbuildPlugins } from './plugin';
14
16
  import type { RsbuildEntry, RsbuildMode, RsbuildTarget } from './rsbuild';
@@ -309,8 +311,9 @@ export type PublicDirOptions = {
309
311
  */
310
312
  watch?: boolean;
311
313
  /**
312
- * Glob patterns of files to ignore when copying from the public directory.
313
- * @default undefined
314
+ * Glob patterns for files or directories to ignore when copying the public directory
315
+ * during production builds.
316
+ * @default []
314
317
  */
315
318
  ignore?: string[];
316
319
  };
@@ -413,7 +416,7 @@ export interface ServerConfig {
413
416
  *
414
417
  * @link https://github.com/expressjs/cors
415
418
  */
416
- cors?: boolean | CorsOptions;
419
+ cors?: boolean | Cors.CorsOptions;
417
420
  /**
418
421
  * Configure proxy rules for the dev server or preview server to proxy requests to
419
422
  * the specified service.
@@ -435,11 +438,53 @@ export interface ServerConfig {
435
438
  * @default false
436
439
  */
437
440
  middlewareMode?: boolean;
441
+ /**
442
+ * Run setup logic when the Rsbuild dev server or preview server starts,
443
+ * such as registering custom middleware or running pre-start tasks.
444
+ *
445
+ * When `server.setup` is called, Rsbuild built-in middlewares are not registered yet,
446
+ * so middlewares you add run earlier than built-ins.
447
+ *
448
+ * `server.setup` can return a callback function. After built-in middlewares are registered,
449
+ * Rsbuild will execute that callback. Middlewares registered in the callback run later than built-ins.
450
+ *
451
+ * @default undefined
452
+ */
453
+ setup?: ServerSetupFn | ServerSetupFn[];
438
454
  }
439
455
  export type NormalizedServerConfig = {
440
456
  host: string;
441
457
  publicDir: Required<PublicDirOptions>[];
442
- } & Omit<Optional<Required<ServerConfig>, 'headers' | 'https' | 'historyApiFallback' | 'proxy'>, 'host' | 'publicDir'>;
458
+ } & Omit<Optional<Required<ServerConfig>, 'headers' | 'https' | 'historyApiFallback' | 'proxy' | 'setup'>, 'host' | 'publicDir'>;
459
+ export type ServerSetupContext = {
460
+ /**
461
+ * Environment contexts of all environments.
462
+ */
463
+ environments: Record<string, EnvironmentContext>;
464
+ } & ({
465
+ /**
466
+ * Action type of current server.
467
+ */
468
+ action: 'dev';
469
+ /**
470
+ * Dev server instance, only available in dev mode.
471
+ */
472
+ server: RsbuildDevServer;
473
+ } | {
474
+ /**
475
+ * Action type of current server.
476
+ */
477
+ action: 'preview';
478
+ /**
479
+ * Preview server instance, only available in preview mode.
480
+ */
481
+ server: RsbuildPreviewServer;
482
+ });
483
+ /**
484
+ * Server setup function.
485
+ * Return a callback to run after built-in middlewares are registered.
486
+ */
487
+ export type ServerSetupFn = (context: ServerSetupContext) => MaybePromise<(() => MaybePromise<void>) | void>;
443
488
  export type SriAlgorithm = 'sha256' | 'sha384' | 'sha512';
444
489
  export type SriOptions = {
445
490
  /**
@@ -771,34 +816,34 @@ export type FilenameConfig = {
771
816
  * The name of the JavaScript files.
772
817
  * @default
773
818
  * - dev: '[name].js'
774
- * - prod: '[name].[contenthash:8].js'
819
+ * - prod: '[name].[contenthash:10].js'
775
820
  */
776
821
  js?: Rspack.Filename;
777
822
  /**
778
823
  * The name of the CSS files.
779
824
  * @default
780
825
  * - dev: '[name].css'
781
- * - prod: '[name].[contenthash:8].css'
826
+ * - prod: '[name].[contenthash:10].css'
782
827
  */
783
828
  css?: Rspack.CssFilename;
784
829
  /**
785
830
  * The name of the SVG images.
786
- * @default '[name].[contenthash:8].svg'
831
+ * @default '[name].[contenthash:10].svg'
787
832
  */
788
833
  svg?: Rspack.AssetModuleFilename;
789
834
  /**
790
835
  * The name of the font files.
791
- * @default '[name].[contenthash:8][ext]'
836
+ * @default '[name].[contenthash:10][ext]'
792
837
  */
793
838
  font?: Rspack.AssetModuleFilename;
794
839
  /**
795
840
  * The name of non-SVG images.
796
- * @default '[name].[contenthash:8][ext]'
841
+ * @default '[name].[contenthash:10][ext]'
797
842
  */
798
843
  image?: Rspack.AssetModuleFilename;
799
844
  /**
800
845
  * The name of media assets, such as video.
801
- * @default '[name].[contenthash:8][ext]'
846
+ * @default '[name].[contenthash:10][ext]'
802
847
  */
803
848
  media?: Rspack.AssetModuleFilename;
804
849
  /**
@@ -808,7 +853,7 @@ export type FilenameConfig = {
808
853
  wasm?: Rspack.WebassemblyModuleFilename;
809
854
  /**
810
855
  * The name of other assets, except for above (image, svg, font, html, wasm...)
811
- * @default '[name].[contenthash:8][ext]'
856
+ * @default '[name].[contenthash:10][ext]'
812
857
  */
813
858
  assets?: Rspack.AssetModuleFilename;
814
859
  };
@@ -843,6 +888,33 @@ export type Charset = 'ascii' | 'utf8';
843
888
  export type LegalComments = 'none' | 'inline' | 'linked';
844
889
  export type NormalizedDataUriLimit = Required<DataUriLimit>;
845
890
  export type Polyfill = 'usage' | 'entry' | 'off';
891
+ export type SourceMapExtractTarget = {
892
+ /**
893
+ * Include matched JavaScript files whose existing source maps should be
894
+ * extracted.
895
+ */
896
+ include?: RuleSetCondition[];
897
+ /**
898
+ * Exclude matched JavaScript files whose existing source maps should not be
899
+ * extracted.
900
+ */
901
+ exclude?: RuleSetCondition[];
902
+ };
903
+ export type SourceMapExtract = boolean | {
904
+ /**
905
+ * Whether to extract existing source maps from matching JavaScript files.
906
+ * This is useful when a third-party package already ships both `.js` and
907
+ * `.js.map` files.
908
+ *
909
+ * `true` means extract from all JavaScript files. You can also use `include`
910
+ * or `exclude` to limit extraction to specific files.
911
+ *
912
+ * This option is implemented based on Rspack's
913
+ * `module.rules[].extractSourceMap` and can replace `source-map-loader`.
914
+ * @default false
915
+ */
916
+ js?: boolean | SourceMapExtractTarget;
917
+ };
846
918
  export type SourceMap = {
847
919
  /**
848
920
  * The source map type for JavaScript files.
@@ -854,6 +926,12 @@ export type SourceMap = {
854
926
  * @default false
855
927
  */
856
928
  css?: boolean;
929
+ /**
930
+ * Whether to extract existing source maps from matching input files.
931
+ * Currently only JavaScript files are supported.
932
+ * @default false
933
+ */
934
+ extract?: SourceMapExtract;
857
935
  };
858
936
  export type CSSModulesLocalsConvention = 'asIs' | 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
859
937
  export type CSSModules = {
@@ -1109,6 +1187,7 @@ export interface OutputConfig {
1109
1187
  * const defaultSourceMap = {
1110
1188
  * js: isDev ? 'cheap-module-source-map' : false,
1111
1189
  * css: false,
1190
+ * extract: false,
1112
1191
  * };
1113
1192
  * ```
1114
1193
  */
@@ -1169,6 +1248,7 @@ export interface NormalizedOutputConfig extends OutputConfig {
1169
1248
  sourceMap: boolean | {
1170
1249
  js?: Rspack.Configuration['devtool'];
1171
1250
  css: boolean;
1251
+ extract: SourceMapExtract;
1172
1252
  };
1173
1253
  cleanDistPath: CleanDistPath;
1174
1254
  filenameHash: boolean | string;
@@ -1576,6 +1656,13 @@ export type CliShortcut = {
1576
1656
  };
1577
1657
  export type WriteToDisk = boolean | ((filename: string) => boolean);
1578
1658
  export type BrowserLogsStackTrace = 'summary' | 'full' | 'none';
1659
+ export type LiveReload = boolean | {
1660
+ /**
1661
+ * Whether to trigger a full page reload when the HTML template changes.
1662
+ * @default true
1663
+ */
1664
+ html?: boolean;
1665
+ };
1579
1666
  export interface DevConfig {
1580
1667
  /**
1581
1668
  * Controls whether to forward browser runtime errors to the terminal. When `true`, the dev
@@ -1604,7 +1691,7 @@ export interface DevConfig {
1604
1691
  * Whether to reload the page when file changes are detected.
1605
1692
  * @default true
1606
1693
  */
1607
- liveReload?: boolean;
1694
+ liveReload?: LiveReload;
1608
1695
  /**
1609
1696
  * Set the URL prefix of static assets in development mode,
1610
1697
  * similar to the [output.publicPath](https://rspack.rs/config/output#outputpublicpath)
@@ -1643,6 +1730,7 @@ export interface DevConfig {
1643
1730
  };
1644
1731
  /**
1645
1732
  * Used to add custom middleware to the dev server.
1733
+ * @deprecated Use `server.setup` instead
1646
1734
  * @default undefined
1647
1735
  */
1648
1736
  setupMiddlewares?: SetupMiddlewaresFn | SetupMiddlewaresFn[];
@@ -1803,6 +1891,11 @@ export interface RsbuildConfig extends EnvironmentConfig {
1803
1891
  * @default 'info'
1804
1892
  */
1805
1893
  logLevel?: LogLevel;
1894
+ /**
1895
+ * Use a custom logger instance for the current Rsbuild instance.
1896
+ * You can create one via `createLogger()`.
1897
+ */
1898
+ customLogger?: Logger;
1806
1899
  /**
1807
1900
  * Options for local development.
1808
1901
  */
@@ -1,4 +1,5 @@
1
1
  import type { Hooks } from '../hooks';
2
+ import type { Logger } from '../logger';
2
3
  import type { SocketServer } from '../server/socketServer';
3
4
  import type { NormalizedConfig, RsbuildConfig } from './config';
4
5
  import type { EnvironmentContext } from './hooks';
@@ -79,6 +80,8 @@ export type BuildState = {
79
80
  };
80
81
  /** The inner context. */
81
82
  export type InternalContext = RsbuildContext & {
83
+ /** The logger associated with current Rsbuild instance. */
84
+ logger: Logger;
82
85
  /** All hooks. */
83
86
  hooks: Readonly<Hooks>;
84
87
  /** Current Rsbuild config. */
@@ -1,6 +1,7 @@
1
1
  import type { rspack } from '@rspack/core';
2
2
  import type { ChainIdentifier, ManifestData } from '..';
3
3
  import type { RsbuildDevServer } from '../server/devServer';
4
+ import type { RsbuildPreviewServer } from '../server/previewServer';
4
5
  import type { RspackChain } from '../types';
5
6
  import type { EnvironmentConfig, HtmlBasicTag, MergedEnvironmentConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
6
7
  import type { RsbuildEntry, RsbuildTarget } from './rsbuild';
@@ -67,8 +68,17 @@ export type OnBeforeStartDevServerFn = (params: {
67
68
  * Context information for all environments.
68
69
  */
69
70
  environments: Record<string, EnvironmentContext>;
70
- }) => MaybePromise<(() => void) | void>;
71
- export type OnBeforeStartProdServerFn = () => MaybePromise<void>;
71
+ }) => MaybePromise<(() => MaybePromise<void>) | void>;
72
+ export type OnBeforeStartPreviewServerFn = (params: {
73
+ /**
74
+ * The preview server instance.
75
+ */
76
+ server: RsbuildPreviewServer;
77
+ /**
78
+ * Context information for all environments.
79
+ */
80
+ environments: Record<string, EnvironmentContext>;
81
+ }) => MaybePromise<void>;
72
82
  export type Routes = {
73
83
  entryName: string;
74
84
  pathname: string;
@@ -81,7 +91,7 @@ export type OnAfterStartDevServerFn = (params: {
81
91
  */
82
92
  environments: Record<string, EnvironmentContext>;
83
93
  }) => MaybePromise<void>;
84
- export type OnAfterStartProdServerFn = (params: {
94
+ export type OnAfterStartPreviewServerFn = (params: {
85
95
  port: number;
86
96
  routes: Routes;
87
97
  /**
@@ -253,19 +263,11 @@ export type ModifyChainUtils = {
253
263
  */
254
264
  HtmlPlugin: typeof HtmlRspackPlugin;
255
265
  };
256
- interface PluginInstance {
257
- apply: (compiler: any) => void;
258
- [k: string]: any;
259
- }
260
266
  export type ModifyBundlerChainUtils = ModifyChainUtils & {
261
- bundler: {
262
- BannerPlugin: PluginInstance;
263
- DefinePlugin: PluginInstance;
264
- IgnorePlugin: PluginInstance;
265
- ProvidePlugin: PluginInstance;
266
- SourceMapDevToolPlugin: PluginInstance;
267
- HotModuleReplacementPlugin: PluginInstance;
268
- };
267
+ /**
268
+ * @deprecated Use `rspack` instead.
269
+ */
270
+ bundler: typeof rspack;
269
271
  };
270
272
  export type ModifyBundlerChainFn = (chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>;
271
273
  export type CreateAsyncHook<Callback extends (...args: any[]) => any> = {
@@ -1,7 +1,7 @@
1
1
  import type { Logger } from '../logger';
2
2
  import type { ModifyRspackConfigUtils, NarrowedRspackConfig, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
3
3
  import type { RsbuildContext } from './context';
4
- import type { EnvironmentContext, ModifyBundlerChainFn, ModifyEnvironmentConfigFn, ModifyHTMLFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDevCompileFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDevCompileFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnExitFn } from './hooks';
4
+ import type { EnvironmentContext, ModifyBundlerChainFn, ModifyEnvironmentConfigFn, ModifyHTMLFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDevCompileFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartPreviewServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDevCompileFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartPreviewServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnExitFn } from './hooks';
5
5
  import type { AddPluginsOptions, RsbuildInstance, RsbuildTarget } from './rsbuild';
6
6
  import type { Rspack } from './rspack';
7
7
  import type { Falsy, MaybePromise } from './utils';
@@ -365,10 +365,12 @@ export type ResolveHandler = (context: {
365
365
  }) => Promise<void> | void;
366
366
  export type ResolveHook = (handler: ResolveHandler) => void;
367
367
  export type ProcessAssetsHook = (descriptor: ProcessAssetsDescriptor, handler: ProcessAssetsHandler) => void;
368
- declare function getNormalizedConfig(): NormalizedConfig;
369
- declare function getNormalizedConfig(options: {
370
- environment: string;
371
- }): NormalizedEnvironmentConfig;
368
+ export type GetNormalizedConfig = {
369
+ (): NormalizedConfig;
370
+ (options: {
371
+ environment: string;
372
+ }): NormalizedEnvironmentConfig;
373
+ };
372
374
  /**
373
375
  * The API interface provided to Rsbuild plugins through the `setup` function.
374
376
  * It allows plugins to interact with the build process, modify configurations,
@@ -394,11 +396,12 @@ export type RsbuildPluginAPI = Readonly<{
394
396
  * environment, this method must be called after the
395
397
  * `modifyRsbuildConfig` hook is executed.
396
398
  */
397
- getNormalizedConfig: typeof getNormalizedConfig;
399
+ getNormalizedConfig: GetNormalizedConfig;
398
400
  /**
399
401
  * A logger instance used to output log information in a unified format.
400
402
  * Use this instead of `console.log` to maintain consistent logging with Rsbuild.
401
- * Equivalent to `import { logger } from '@rsbuild/core'`.
403
+ * It is associated with the current Rsbuild instance and reflects
404
+ * `config.customLogger` when provided.
402
405
  */
403
406
  logger: Logger;
404
407
  /**
@@ -471,11 +474,11 @@ export type RsbuildPluginAPI = Readonly<{
471
474
  */
472
475
  onAfterStartDevServer: PluginHook<OnAfterStartDevServerFn>;
473
476
  /**
474
- * Called after starting the production preview server, you can get the port
477
+ * Called after starting the preview server, you can get the port
475
478
  * number with the `port` parameter, and the page routes info with the
476
479
  * `routes` parameter.
477
480
  */
478
- onAfterStartProdServer: PluginHook<OnAfterStartProdServerFn>;
481
+ onAfterStartPreviewServer: PluginHook<OnAfterStartPreviewServerFn>;
479
482
  /**
480
483
  * A callback function that is triggered before the production build is executed.
481
484
  */
@@ -499,9 +502,9 @@ export type RsbuildPluginAPI = Readonly<{
499
502
  */
500
503
  onBeforeStartDevServer: PluginHook<OnBeforeStartDevServerFn>;
501
504
  /**
502
- * Called before starting the production preview server.
505
+ * Called before starting the preview server.
503
506
  */
504
- onBeforeStartProdServer: PluginHook<OnBeforeStartProdServerFn>;
507
+ onBeforeStartPreviewServer: PluginHook<OnBeforeStartPreviewServerFn>;
505
508
  /**
506
509
  * Called when closing the build instance. Can be used to perform cleanup
507
510
  * operations when the building is closed.
@@ -1,7 +1,8 @@
1
1
  import type { Compiler, MultiCompiler } from '@rspack/core';
2
2
  import type { LoadEnvOptions } from '../loadEnv';
3
+ import type { Logger } from '../logger';
3
4
  import type { RsbuildDevServer } from '../server/devServer';
4
- import type { StartServerResult } from '../server/helper';
5
+ import type { StartDevServerResult, StartPreviewServerResult } from '../server/helper';
5
6
  import type { NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
6
7
  import type { RsbuildContext } from './context';
7
8
  import type { RsbuildPlugin, RsbuildPluginAPI } from './plugin';
@@ -141,7 +142,7 @@ export type ResolvedCreateRsbuildOptions = Required<Pick<CreateRsbuildOptions, '
141
142
  rsbuildConfig: RsbuildConfig;
142
143
  };
143
144
  export type CreateDevServer = (options?: CreateDevServerOptions) => Promise<RsbuildDevServer>;
144
- export type StartDevServer = (options?: StartDevServerOptions) => Promise<StartServerResult>;
145
+ export type StartDevServer = (options?: StartDevServerOptions) => Promise<StartDevServerResult>;
145
146
  export type InspectConfig = (options?: InspectConfigOptions) => Promise<InspectConfigResult>;
146
147
  export type AddPluginsOptions = {
147
148
  /**
@@ -157,6 +158,12 @@ export type AddPluginsOptions = {
157
158
  };
158
159
  export type AddPlugins = (plugins: (RsbuildPlugin | Falsy)[], options?: AddPluginsOptions) => void;
159
160
  export type RsbuildInstance = {
161
+ /**
162
+ * The logger associated with the current Rsbuild instance.
163
+ * It reflects `config.customLogger` when provided, otherwise uses a logger
164
+ * created specifically for the current Rsbuild instance.
165
+ */
166
+ logger: Logger;
160
167
  /**
161
168
  * Register one or more Rsbuild plugins, which can be called multiple times.
162
169
  * This method needs to be called before compiling. If it is called after
@@ -194,7 +201,7 @@ export type RsbuildInstance = {
194
201
  * Start a server to preview the production build locally.
195
202
  * This method should be executed after `rsbuild.build`.
196
203
  */
197
- preview: (options?: PreviewOptions) => Promise<StartServerResult>;
204
+ preview: (options?: PreviewOptions) => Promise<StartPreviewServerResult>;
198
205
  /**
199
206
  * Initialize and return the internal Rspack configurations used by Rsbuild.
200
207
  * This method processes all plugins and configurations to generate the final
@@ -240,7 +247,7 @@ export type RsbuildInstance = {
240
247
  * 2. Watch for file changes and trigger recompilation.
241
248
  */
242
249
  startDevServer: StartDevServer;
243
- } & Pick<RsbuildPluginAPI, 'context' | 'expose' | 'getNormalizedConfig' | 'getRsbuildConfig' | 'isPluginExists' | 'modifyEnvironmentConfig' | 'modifyRsbuildConfig' | 'onAfterBuild' | 'onAfterCreateCompiler' | 'onAfterDevCompile' | 'onAfterEnvironmentCompile' | 'onAfterStartDevServer' | 'onAfterStartProdServer' | 'onBeforeBuild' | 'onBeforeCreateCompiler' | 'onBeforeDevCompile' | 'onBeforeEnvironmentCompile' | 'onBeforeStartDevServer' | 'onBeforeStartProdServer' | 'onCloseBuild' | 'onCloseDevServer' | 'onDevCompileDone' | 'onExit'>;
250
+ } & Pick<RsbuildPluginAPI, 'context' | 'expose' | 'getNormalizedConfig' | 'getRsbuildConfig' | 'isPluginExists' | 'modifyEnvironmentConfig' | 'modifyRsbuildConfig' | 'onAfterBuild' | 'onAfterCreateCompiler' | 'onAfterDevCompile' | 'onAfterEnvironmentCompile' | 'onAfterStartDevServer' | 'onAfterStartPreviewServer' | 'onBeforeBuild' | 'onBeforeCreateCompiler' | 'onBeforeDevCompile' | 'onBeforeEnvironmentCompile' | 'onBeforeStartDevServer' | 'onBeforeStartPreviewServer' | 'onCloseBuild' | 'onCloseDevServer' | 'onDevCompileDone' | 'onExit'>;
244
251
  export type RsbuildTarget = 'web' | 'node' | 'web-worker';
245
252
  export type RsbuildEntryDescription = Rspack.EntryDescription & {
246
253
  /**
@@ -1,6 +1,6 @@
1
1
  import type { CssExtractRspackLoaderOptions, CssExtractRspackPluginOptions } from '@rspack/core';
2
- import type Connect from 'connect';
3
- import type HtmlRspackPlugin from '../../compiled/html-rspack-plugin/index.js';
2
+ import type * as Connect from '../../compiled/connect-next';
3
+ import type HtmlRspackPlugin from '../../compiled/html-rspack-plugin';
4
4
  import type { AcceptedPlugin, ProcessOptions } from '../../compiled/postcss';
5
5
  import type { Rspack } from './rspack';
6
6
  import type { LiteralUnion } from './utils';
@@ -169,15 +169,24 @@ export interface StyleLoaderOptions {
169
169
  */
170
170
  attributes?: Record<string, string>;
171
171
  /**
172
- * By default, the style-loader appends <style>/<link> elements to the end of the style target, which is the <head> tag of the page unless specified by insert.
172
+ * By default, style-loader appends <style>/<link> elements to the end of the style target,
173
+ * which is the <head> tag of the page unless specified by insert.
173
174
  * This will cause CSS created by the loader to take priority over CSS already present in the target.
174
175
  * You can use other values if the standard behavior is not suitable for you, but we do not recommend doing this.
176
+ * If you target an iframe, make sure you have sufficient access rights.
177
+ *
178
+ * Supports:
179
+ * - a CSS selector where styles are injected
180
+ * - an absolute path to a custom insert module
175
181
  *
176
182
  * @default 'head'
177
183
  */
178
- insert?: LiteralUnion<'head' | 'body', string> | ((element: HTMLElement) => void);
184
+ insert?: LiteralUnion<'head' | 'body', string>;
179
185
  /**
180
- * Allows to setup absolute path to custom function that allows to override default behavior styleTagTransform.
186
+ * Allows to setup an absolute path to a custom module that overrides
187
+ * the default styleTagTransform behavior.
188
+ *
189
+ * @default undefined
181
190
  */
182
- styleTagTransform?: string | ((css: string, styleElement: HTMLStyleElement, options: Record<string, any>) => void);
191
+ styleTagTransform?: string;
183
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.10",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -36,9 +36,8 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rspack/core": "2.0.0-alpha.1",
40
- "@swc/helpers": "^0.5.18",
41
- "jiti": "^2.6.1"
39
+ "@rspack/core": "2.0.0-beta.8",
40
+ "@swc/helpers": "^0.5.19"
42
41
  },
43
42
  "peerDependencies": {
44
43
  "core-js": ">= 3.0.0"
@@ -51,46 +50,45 @@
51
50
  "devDependencies": {
52
51
  "@jridgewell/remapping": "^2.3.5",
53
52
  "@jridgewell/trace-mapping": "^0.3.31",
54
- "@rslib/core": "0.19.4",
55
- "@types/connect": "3.4.38",
53
+ "@rslib/core": "0.20.0",
56
54
  "@types/cors": "^2.8.19",
57
- "@types/node": "^24.10.9",
55
+ "@types/node": "^24.12.0",
58
56
  "@types/on-finished": "2.3.5",
59
57
  "@types/range-parser": "^1.2.7",
60
58
  "@types/ws": "^8.18.1",
61
59
  "browserslist-load-config": "1.0.1",
62
- "cac": "^6.7.14",
60
+ "cac": "^7.0.0",
63
61
  "chokidar": "^5.0.0",
64
- "connect": "3.7.0",
62
+ "connect-next": "4.0.0",
65
63
  "cors": "^2.8.6",
66
- "css-loader": "7.1.3",
64
+ "css-loader": "7.1.4",
67
65
  "deepmerge": "^4.3.1",
68
66
  "dotenv-expand": "12.0.3",
69
- "html-rspack-plugin": "6.1.6",
67
+ "html-rspack-plugin": "6.1.7",
70
68
  "http-proxy-middleware": "^3.0.5",
71
- "launch-editor-middleware": "^2.12.0",
72
- "memfs": "^4.56.10",
69
+ "jiti": "^2.6.1",
70
+ "launch-editor-middleware": "^2.13.2",
71
+ "memfs": "^4.57.1",
73
72
  "mrmime": "^2.0.1",
74
73
  "on-finished": "2.4.1",
75
74
  "open": "^11.0.0",
76
- "picocolors": "^1.1.1",
77
- "postcss": "^8.5.6",
75
+ "postcss": "^8.5.8",
78
76
  "postcss-load-config": "6.0.1",
79
- "postcss-loader": "8.2.0",
80
- "prebundle": "1.6.2",
77
+ "postcss-loader": "8.2.1",
78
+ "prebundle": "1.6.4",
81
79
  "range-parser": "^1.2.1",
82
80
  "reduce-configs": "^1.1.1",
83
- "rslog": "^1.3.2",
84
- "rspack-chain": "^2.0.0-alpha.0",
81
+ "rslog": "^2.1.0",
82
+ "rspack-chain": "^2.0.0-beta.1",
85
83
  "rspack-manifest-plugin": "5.2.1",
86
84
  "sirv": "^3.0.2",
87
85
  "stacktrace-parser": "^0.1.11",
88
- "style-loader": "3.3.4",
89
- "tinyglobby": "0.2.14",
90
- "typescript": "^5.9.3",
91
- "webpack": "^5.104.1",
86
+ "style-loader": "^4.0.0",
87
+ "supports-color": "^10.2.2",
88
+ "tinyglobby": "^0.2.15",
89
+ "typescript": "^6.0.2",
92
90
  "webpack-merge": "6.0.1",
93
- "ws": "^8.19.0"
91
+ "ws": "^8.20.0"
94
92
  },
95
93
  "engines": {
96
94
  "node": "^20.19.0 || >=22.12.0"
@@ -1,90 +0,0 @@
1
- import type { FSWatcher as NativeFsWatcher, Stats, WatchEventType } from 'node:fs';
2
- import type { EntryInfo } from 'readdirp';
3
- import type { FSWatcher, Throttler, WatchHelper } from './index.js';
4
- export type Path = string;
5
- export declare const STR_DATA = "data";
6
- export declare const STR_END = "end";
7
- export declare const STR_CLOSE = "close";
8
- export declare const EMPTY_FN: () => void;
9
- export declare const IDENTITY_FN: (val: unknown) => unknown;
10
- export declare const isWindows: boolean;
11
- export declare const isMacos: boolean;
12
- export declare const isLinux: boolean;
13
- export declare const isFreeBSD: boolean;
14
- export declare const isIBMi: boolean;
15
- export declare const EVENTS: {
16
- readonly ALL: "all";
17
- readonly READY: "ready";
18
- readonly ADD: "add";
19
- readonly CHANGE: "change";
20
- readonly ADD_DIR: "addDir";
21
- readonly UNLINK: "unlink";
22
- readonly UNLINK_DIR: "unlinkDir";
23
- readonly RAW: "raw";
24
- readonly ERROR: "error";
25
- };
26
- export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
27
- export type FsWatchContainer = {
28
- listeners: (path: string) => void | Set<any>;
29
- errHandlers: (err: unknown) => void | Set<any>;
30
- rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
31
- watcher: NativeFsWatcher;
32
- watcherUnusable?: boolean;
33
- };
34
- export interface WatchHandlers {
35
- listener: (path: string) => void;
36
- errHandler: (err: unknown) => void;
37
- rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
38
- }
39
- /**
40
- * @mixin
41
- */
42
- export declare class NodeFsHandler {
43
- fsw: FSWatcher;
44
- _boundHandleError: (error: unknown) => void;
45
- constructor(fsW: FSWatcher);
46
- /**
47
- * Watch file for changes with fs_watchFile or fs_watch.
48
- * @param path to file or dir
49
- * @param listener on fs change
50
- * @returns closer for the watcher instance
51
- */
52
- _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
53
- /**
54
- * Watch a file and emit add event if warranted.
55
- * @returns closer for the watcher instance
56
- */
57
- _handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
58
- /**
59
- * Handle symlinks encountered while reading a dir.
60
- * @param entry returned by readdirp
61
- * @param directory path of dir being read
62
- * @param path of this item
63
- * @param item basename of this item
64
- * @returns true if no more processing is needed for this entry.
65
- */
66
- _handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
67
- _handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path | undefined, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
68
- /**
69
- * Read directory to add / remove files from `@watched` list and re-read it on change.
70
- * @param dir fs path
71
- * @param stats
72
- * @param initialAdd
73
- * @param depth relative to user-supplied path
74
- * @param target child path targeted for watch
75
- * @param wh Common watch helpers for this path
76
- * @param realpath
77
- * @returns closer for the watcher instance.
78
- */
79
- _handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string | undefined, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
80
- /**
81
- * Handle added file, directory, or glob pattern.
82
- * Delegates call to _handleFile / _handleDir after checks.
83
- * @param path to file or ir
84
- * @param initialAdd was the file added at watch instantiation?
85
- * @param priorWh depth relative to user-supplied path
86
- * @param depth Child path actually targeted for watch
87
- * @param target Child path actually targeted for watch
88
- */
89
- _addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
90
- }