@rsbuild/core 1.0.0-alpha.2 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/compiled/autoprefixer/index.d.ts +95 -0
  2. package/compiled/autoprefixer/index.js +10217 -0
  3. package/compiled/autoprefixer/license +20 -0
  4. package/compiled/autoprefixer/package.json +1 -0
  5. package/compiled/browserslist/index.d.ts +201 -0
  6. package/compiled/browserslist/index.js +2017 -0
  7. package/compiled/browserslist/license +20 -0
  8. package/compiled/browserslist/package.json +1 -0
  9. package/compiled/chokidar/index.d.ts +198 -0
  10. package/compiled/chokidar/index.js +6692 -0
  11. package/compiled/chokidar/license +21 -0
  12. package/compiled/chokidar/package.json +1 -0
  13. package/compiled/gzip-size/index.d.ts +1 -0
  14. package/compiled/gzip-size/index.js +242 -0
  15. package/compiled/gzip-size/package.json +1 -0
  16. package/compiled/http-proxy-middleware/index.d.ts +315 -0
  17. package/compiled/http-proxy-middleware/index.js +7503 -0
  18. package/compiled/http-proxy-middleware/license +22 -0
  19. package/compiled/http-proxy-middleware/package.json +1 -0
  20. package/compiled/launch-editor-middleware/index.js +9 -9
  21. package/compiled/rspack-chain/index.d.ts +600 -0
  22. package/compiled/rspack-chain/index.js +2192 -0
  23. package/compiled/rspack-chain/license +373 -0
  24. package/compiled/rspack-chain/package.json +1 -0
  25. package/compiled/webpack-bundle-analyzer/index.d.ts +160 -0
  26. package/compiled/webpack-bundle-analyzer/index.js +14968 -0
  27. package/compiled/webpack-bundle-analyzer/license +20 -0
  28. package/compiled/webpack-bundle-analyzer/package.json +1 -0
  29. package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
  30. package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
  31. package/compiled/webpack-merge/index.d.ts +31 -0
  32. package/compiled/webpack-merge/index.js +1239 -0
  33. package/compiled/webpack-merge/license +20 -0
  34. package/compiled/webpack-merge/package.json +1 -0
  35. package/dist/index.cjs +882 -2519
  36. package/dist/index.js +966 -2647
  37. package/dist-types/cli/commands.d.ts +1 -1
  38. package/dist-types/config.d.ts +1 -1
  39. package/dist-types/configChain.d.ts +158 -2
  40. package/dist-types/constants.d.ts +1 -0
  41. package/dist-types/createContext.d.ts +1 -2
  42. package/dist-types/helpers.d.ts +7 -4
  43. package/dist-types/index.d.ts +2 -2
  44. package/dist-types/initHooks.d.ts +1 -1
  45. package/dist-types/initPlugins.d.ts +1 -2
  46. package/dist-types/internal.d.ts +1 -1
  47. package/dist-types/loader/transformLoader.d.ts +1 -1
  48. package/dist-types/mergeConfig.d.ts +1 -1
  49. package/dist-types/pluginManager.d.ts +1 -1
  50. package/dist-types/plugins/css.d.ts +1 -2
  51. package/dist-types/plugins/html.d.ts +1 -2
  52. package/dist-types/plugins/minimize.d.ts +1 -2
  53. package/dist-types/provider/build.d.ts +1 -1
  54. package/dist-types/provider/createCompiler.d.ts +1 -2
  55. package/dist-types/provider/initConfigs.d.ts +1 -2
  56. package/dist-types/provider/inspectConfig.d.ts +1 -1
  57. package/dist-types/provider/rspackConfig.d.ts +2 -2
  58. package/dist-types/rspack/HtmlBasicPlugin.d.ts +1 -1
  59. package/dist-types/rspack/InlineChunkHtmlPlugin.d.ts +1 -1
  60. package/dist-types/rspack/preload/HtmlPreloadOrPrefetchPlugin.d.ts +1 -1
  61. package/dist-types/rspack/preload/helpers/doesChunkBelongToHtml.d.ts +1 -1
  62. package/dist-types/rspack/preload/helpers/extractChunks.d.ts +1 -1
  63. package/dist-types/server/compilerDevMiddleware.d.ts +1 -1
  64. package/dist-types/server/devMiddleware.d.ts +4 -1
  65. package/dist-types/server/devServer.d.ts +1 -2
  66. package/dist-types/server/environment.d.ts +1 -1
  67. package/dist-types/server/getDevMiddlewares.d.ts +1 -1
  68. package/dist-types/server/helper.d.ts +1 -2
  69. package/dist-types/server/httpServer.d.ts +1 -1
  70. package/dist-types/server/middlewares.d.ts +1 -1
  71. package/dist-types/server/prodServer.d.ts +1 -2
  72. package/dist-types/server/proxy.d.ts +3 -3
  73. package/dist-types/server/socketServer.d.ts +1 -1
  74. package/dist-types/server/watchFiles.d.ts +1 -1
  75. package/dist-types/types/config/dev.d.ts +85 -0
  76. package/dist-types/types/config/html.d.ts +107 -0
  77. package/dist-types/types/config/index.d.ts +134 -0
  78. package/dist-types/types/config/output.d.ts +301 -0
  79. package/dist-types/types/config/performance.d.ts +122 -0
  80. package/dist-types/types/config/security.d.ts +18 -0
  81. package/dist-types/types/config/server.d.ts +106 -0
  82. package/dist-types/types/config/source.d.ts +79 -0
  83. package/dist-types/types/config/tools.d.ts +86 -0
  84. package/dist-types/types/context.d.ts +38 -0
  85. package/dist-types/types/hooks.d.ts +125 -0
  86. package/dist-types/types/index.d.ts +9 -0
  87. package/dist-types/types/plugin.d.ts +194 -0
  88. package/dist-types/{types.d.ts → types/rsbuild.d.ts} +56 -33
  89. package/dist-types/types/rspack.d.ts +28 -0
  90. package/dist-types/types/stats.d.ts +17 -0
  91. package/dist-types/types/thirdParty.d.ts +169 -0
  92. package/dist-types/types/utils.d.ts +14 -0
  93. package/package.json +18 -3
@@ -0,0 +1,106 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import type { SecureServerSessionOptions } from 'node:http2';
3
+ import type { ServerOptions as HttpsServerOptions } from 'node:https';
4
+ import type { Options as BaseProxyOptions, Filter as ProxyFilter } from '../../../compiled/http-proxy-middleware';
5
+ import type { Routes } from '../hooks';
6
+ export type HtmlFallback = false | 'index';
7
+ export type ProxyDetail = BaseProxyOptions & {
8
+ bypass?: (req: IncomingMessage, res: ServerResponse, proxyOptions: ProxyOptions) => string | undefined | null | boolean;
9
+ context?: ProxyFilter;
10
+ };
11
+ export type ProxyOptions = Record<string, string> | Record<string, ProxyDetail> | ProxyDetail[] | ProxyDetail;
12
+ export type HistoryApiFallbackContext = {
13
+ match: RegExpMatchArray;
14
+ parsedUrl: import('node:url').Url;
15
+ request: Request;
16
+ };
17
+ export type HistoryApiFallbackOptions = {
18
+ index?: string;
19
+ verbose?: boolean;
20
+ logger?: typeof console.log;
21
+ htmlAcceptHeaders?: string[];
22
+ disableDotRule?: true;
23
+ rewrites?: Array<{
24
+ from: RegExp;
25
+ to: string | RegExp | ((context: HistoryApiFallbackContext) => string);
26
+ }>;
27
+ };
28
+ export type PrintUrls = boolean | ((params: {
29
+ urls: string[];
30
+ port: number;
31
+ routes: Routes;
32
+ protocol: string;
33
+ }) => string[] | void);
34
+ export type PublicDirOptions = {
35
+ /**
36
+ * The name of the public directory, can be set as a relative path or an absolute path.
37
+ * @default 'public'
38
+ */
39
+ name?: string;
40
+ /**
41
+ * Whether to copy files from the publicDir to the distDir on production build
42
+ * @default true
43
+ */
44
+ copyOnBuild?: boolean;
45
+ /**
46
+ * whether to watch the public directory and reload the page when the files change
47
+ * @default false
48
+ */
49
+ watch?: boolean;
50
+ };
51
+ export type PublicDir = false | PublicDirOptions | PublicDirOptions[];
52
+ export interface ServerConfig {
53
+ /**
54
+ * Whether to enable gzip compression
55
+ */
56
+ compress?: boolean;
57
+ /**
58
+ * Serving static files from the directory (by default 'public' directory)
59
+ */
60
+ publicDir?: PublicDir;
61
+ /**
62
+ * Specify a port number for Rsbuild Server to listen.
63
+ */
64
+ port?: number;
65
+ /**
66
+ * After configuring this option, you can enable HTTPS Server, and disabling the HTTP Server.
67
+ */
68
+ https?: HttpsServerOptions | SecureServerSessionOptions;
69
+ /**
70
+ * Used to set the host of Rsbuild Server.
71
+ */
72
+ host?: string;
73
+ /**
74
+ * Adds headers to all responses.
75
+ */
76
+ headers?: Record<string, string | string[]>;
77
+ /**
78
+ * Whether to support html fallback.
79
+ */
80
+ htmlFallback?: HtmlFallback;
81
+ /**
82
+ * Provide alternative pages for some 404 responses or other requests.
83
+ * see https://github.com/bripkens/connect-history-api-fallback
84
+ */
85
+ historyApiFallback?: boolean | HistoryApiFallbackOptions;
86
+ /**
87
+ * Set the page URL to open when the server starts.
88
+ */
89
+ open?: boolean | string | string[] | {
90
+ target?: string | string[];
91
+ before?: () => Promise<void> | void;
92
+ };
93
+ /**
94
+ * Configure proxy rules for the dev server or preview server to proxy requests to the specified service.
95
+ */
96
+ proxy?: ProxyOptions;
97
+ /**
98
+ * Whether to throw an error when the port is occupied.
99
+ */
100
+ strictPort?: boolean;
101
+ /**
102
+ * Whether to print the server urls when the server is started.
103
+ */
104
+ printUrls?: PrintUrls;
105
+ }
106
+ export type NormalizedServerConfig = ServerConfig & Required<Pick<ServerConfig, 'htmlFallback' | 'port' | 'host' | 'compress' | 'strictPort' | 'printUrls' | 'open'>>;
@@ -0,0 +1,79 @@
1
+ import type { RuleSetCondition } from '@rspack/core';
2
+ import type { RsbuildEntry } from '../rsbuild';
3
+ import type { ConfigChain } from '../utils';
4
+ export type Alias = Record<string, string | false | (string | false)[]>;
5
+ export type Define = Record<string, any>;
6
+ export type AliasStrategy = 'prefer-tsconfig' | 'prefer-alias';
7
+ export type Decorators = {
8
+ /**
9
+ * Specify the version of decorators to use.
10
+ * @default 'legacy''
11
+ */
12
+ version?: 'legacy' | '2022-03';
13
+ };
14
+ export interface SourceConfig {
15
+ /**
16
+ * Create aliases to import or require certain modules,
17
+ * same as the [resolve.alias](https://rspack.dev/config/resolve) config of Rspack.
18
+ */
19
+ alias?: ConfigChain<Alias>;
20
+ /**
21
+ * Used to control the priority between the `paths` option in `tsconfig.json`
22
+ * and the `alias` option in the bundler.
23
+ */
24
+ aliasStrategy?: AliasStrategy;
25
+ /**
26
+ * Specify directories or modules that need additional compilation.
27
+ * In order to maintain faster compilation speed, Rsbuild will not compile files under node_modules through
28
+ * `babel-loader` or `ts-loader` by default, as will as the files outside the current project directory.
29
+ */
30
+ include?: RuleSetCondition[];
31
+ /**
32
+ * Set the entry modules.
33
+ */
34
+ entry?: RsbuildEntry;
35
+ /**
36
+ * Specifies that certain files that will be excluded from compilation.
37
+ */
38
+ exclude?: RuleSetCondition[];
39
+ /**
40
+ * Add a script before the entry file of each page.
41
+ * This script will be executed before the page code.
42
+ * It can be used to execute global logics, such as polyfill injection.
43
+ */
44
+ preEntry?: string | string[];
45
+ /**
46
+ * Used to replaces variables in your code with other values or expressions at compile time.
47
+ */
48
+ define?: Define;
49
+ /**
50
+ * Configuring decorators syntax.
51
+ */
52
+ decorators?: Decorators;
53
+ /**
54
+ * Used to import the code and style of the component library on demand.
55
+ */
56
+ transformImport?: false | TransformImport[];
57
+ /**
58
+ * Configure a custom tsconfig.json file path to use, can be a relative or absolute path.
59
+ * @default 'tsconfig.json'
60
+ */
61
+ tsconfigPath?: string;
62
+ }
63
+ export type TransformImport = {
64
+ libraryName: string;
65
+ libraryDirectory?: string;
66
+ style?: string | boolean;
67
+ styleLibraryDirectory?: string;
68
+ camelToDashComponentName?: boolean;
69
+ transformToDefaultImport?: boolean;
70
+ customName?: any;
71
+ customStyleName?: any;
72
+ };
73
+ export interface NormalizedSourceConfig extends SourceConfig {
74
+ define: Define;
75
+ alias: ConfigChain<Alias>;
76
+ aliasStrategy: AliasStrategy;
77
+ preEntry: string[];
78
+ decorators: Required<Decorators>;
79
+ }
@@ -0,0 +1,86 @@
1
+ import type { rspack } from '@rspack/core';
2
+ import type { SwcLoaderOptions } from '@rspack/core';
3
+ import type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
4
+ import type RspackChain from '../../../compiled/rspack-chain';
5
+ import type { ModifyBundlerChainUtils, ModifyChainUtils } from '../hooks';
6
+ import type { ModifyWebpackChainUtils, ModifyWebpackConfigUtils } from '../plugin';
7
+ import type { BundlerPluginInstance, Rspack, RspackConfig, RspackRule } from '../rspack';
8
+ import type { AutoprefixerOptions, CSSExtractOptions, CSSLoaderOptions, PostCSSLoaderOptions, PostCSSPlugin, StyleLoaderOptions, WebpackConfig } from '../thirdParty';
9
+ import type { ConfigChain, ConfigChainAsyncWithContext, ConfigChainWithContext } from '../utils';
10
+ import type { MaybePromise, OneOrMany } from '../utils';
11
+ export type { HTMLPluginOptions };
12
+ export type ToolsSwcConfig = ConfigChain<SwcLoaderOptions>;
13
+ export type ToolsAutoprefixerConfig = ConfigChain<AutoprefixerOptions>;
14
+ export type ToolsBundlerChainConfig = OneOrMany<(chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>>;
15
+ export type ToolsPostCSSLoaderConfig = ConfigChainWithContext<PostCSSLoaderOptions, {
16
+ addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
17
+ }>;
18
+ export type ToolsCSSLoaderConfig = ConfigChain<CSSLoaderOptions>;
19
+ export type ToolsStyleLoaderConfig = ConfigChain<StyleLoaderOptions>;
20
+ export type ToolsHtmlPluginConfig = ConfigChainWithContext<HTMLPluginOptions, {
21
+ entryName: string;
22
+ entryValue: (string | string[] | Rspack.EntryDescription)[];
23
+ }>;
24
+ export type ModifyRspackConfigUtils = ModifyChainUtils & {
25
+ addRules: (rules: RspackRule | RspackRule[]) => void;
26
+ prependPlugins: (plugins: BundlerPluginInstance | BundlerPluginInstance[]) => void;
27
+ appendPlugins: (plugins: BundlerPluginInstance | BundlerPluginInstance[]) => void;
28
+ removePlugin: (pluginName: string) => void;
29
+ mergeConfig: typeof import('../../../compiled/webpack-merge').merge;
30
+ rspack: typeof rspack;
31
+ };
32
+ export type ToolsRspackConfig = ConfigChainAsyncWithContext<RspackConfig, ModifyRspackConfigUtils>;
33
+ export type ToolsWebpackConfig = ConfigChainWithContext<WebpackConfig, ModifyWebpackConfigUtils>;
34
+ export type ToolsWebpackChainConfig = OneOrMany<(chain: RspackChain, utils: ModifyWebpackChainUtils) => void>;
35
+ export interface ToolsConfig {
36
+ /**
37
+ * Configure bundler config base on [rspack-chain](https://github.com/rspack-contrib/rspack-chain)
38
+ */
39
+ bundlerChain?: ToolsBundlerChainConfig;
40
+ /**
41
+ * Modify the config of [autoprefixer](https://github.com/postcss/autoprefixer)
42
+ */
43
+ autoprefixer?: ToolsAutoprefixerConfig;
44
+ /**
45
+ * Modify the options of [css-loader](https://github.com/webpack-contrib/css-loader).
46
+ */
47
+ cssLoader?: ToolsCSSLoaderConfig;
48
+ /**
49
+ * Modify the options of [postcss-loader](https://github.com/webpack-contrib/postcss-loader).
50
+ */
51
+ postcss?: ToolsPostCSSLoaderConfig;
52
+ /**
53
+ * Modify the options of [style-loader](https://github.com/webpack-contrib/style-loader).
54
+ */
55
+ styleLoader?: ToolsStyleLoaderConfig;
56
+ /**
57
+ * Configure the html-webpack-plugin.
58
+ */
59
+ htmlPlugin?: boolean | ToolsHtmlPluginConfig;
60
+ /**
61
+ * Configure the `builtin:swc-loader` of Rspack.
62
+ */
63
+ swc?: ToolsSwcConfig;
64
+ /**
65
+ * Modify the options of [CssExtractRspackPlugin](https://rspack.dev/plugins/rspack/css-extract-rspack-plugin).
66
+ */
67
+ cssExtract?: CSSExtractOptions;
68
+ /**
69
+ * Configure Rspack.
70
+ * @requires rspack
71
+ */
72
+ rspack?: ToolsRspackConfig;
73
+ /**
74
+ * Configure [webpack](https://webpack.js.org/).
75
+ * @requires webpack
76
+ */
77
+ webpack?: ToolsWebpackConfig;
78
+ /**
79
+ * Configure webpack by [rspack-chain](https://github.com/rspack-contrib/rspack-chain).
80
+ * @requires webpack
81
+ */
82
+ webpackChain?: ToolsWebpackChainConfig;
83
+ }
84
+ export type NormalizedToolsConfig = ToolsConfig & {
85
+ cssExtract: Required<CSSExtractOptions>;
86
+ };
@@ -0,0 +1,38 @@
1
+ import type { Hooks } from '../initHooks';
2
+ import type { NormalizedConfig, RsbuildConfig } from './config';
3
+ import type { EnvironmentContext } from './hooks';
4
+ import type { RsbuildPluginAPI } from './plugin';
5
+ export type BundlerType = 'rspack' | 'webpack';
6
+ /** The public context */
7
+ export type RsbuildContext = {
8
+ /** The Rsbuild core version. */
9
+ version: string;
10
+ /** The root path of current project. */
11
+ rootPath: string;
12
+ /** Absolute path of output files. */
13
+ distPath: string;
14
+ /** Absolute path of cache files. */
15
+ cachePath: string;
16
+ /** Info of dev server */
17
+ devServer?: {
18
+ hostname: string;
19
+ port: number;
20
+ https: boolean;
21
+ };
22
+ bundlerType: BundlerType;
23
+ };
24
+ /** The inner context. */
25
+ export type InternalContext = RsbuildContext & {
26
+ /** All hooks. */
27
+ hooks: Readonly<Hooks>;
28
+ /** Current Rsbuild config. */
29
+ config: Readonly<RsbuildConfig>;
30
+ /** The original Rsbuild config passed from the createRsbuild method. */
31
+ originalConfig: Readonly<RsbuildConfig>;
32
+ /** The normalized Rsbuild config. */
33
+ normalizedConfig?: NormalizedConfig;
34
+ /** The plugin API. */
35
+ pluginAPI?: RsbuildPluginAPI;
36
+ /** The environment context. */
37
+ environments: Record<string, EnvironmentContext>;
38
+ };
@@ -0,0 +1,125 @@
1
+ import type HtmlWebpackPlugin from 'html-webpack-plugin';
2
+ import type RspackChain from '../../compiled/rspack-chain';
3
+ import type { ChainIdentifier } from '..';
4
+ import type { EnvironmentConfig, HtmlBasicTag, MergedEnvironmentConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
5
+ import type { RsbuildEntry, RsbuildTarget } from './rsbuild';
6
+ import type { Rspack } from './rspack';
7
+ import type { MultiStats, Stats } from './stats';
8
+ import type { WebpackConfig } from './thirdParty';
9
+ import type { MaybePromise, NodeEnv } from './utils';
10
+ export type OnBeforeBuildFn<B = 'rspack'> = (params: {
11
+ bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : WebpackConfig[];
12
+ environments: Record<string, EnvironmentContext>;
13
+ }) => MaybePromise<void>;
14
+ export type OnAfterBuildFn = (params: {
15
+ isFirstCompile: boolean;
16
+ stats?: Stats | MultiStats;
17
+ environments: Record<string, EnvironmentContext>;
18
+ }) => MaybePromise<void>;
19
+ export type OnCloseDevServerFn = () => MaybePromise<void>;
20
+ export type OnDevCompileDoneFn = (params: {
21
+ isFirstCompile: boolean;
22
+ stats: Stats | MultiStats;
23
+ environments: Record<string, EnvironmentContext>;
24
+ }) => MaybePromise<void>;
25
+ export type OnBeforeStartDevServerFn = (params: {
26
+ environments: Record<string, EnvironmentContext>;
27
+ }) => MaybePromise<void>;
28
+ export type OnBeforeStartProdServerFn = () => MaybePromise<void>;
29
+ export type Routes = Array<{
30
+ entryName: string;
31
+ pathname: string;
32
+ }>;
33
+ export type OnAfterStartDevServerFn = (params: {
34
+ port: number;
35
+ routes: Routes;
36
+ environments: Record<string, EnvironmentContext>;
37
+ }) => MaybePromise<void>;
38
+ export type OnAfterStartProdServerFn = (params: {
39
+ port: number;
40
+ routes: Routes;
41
+ }) => MaybePromise<void>;
42
+ export type OnBeforeCreateCompilerFn<B = 'rspack'> = (params: {
43
+ bundlerConfigs: B extends 'rspack' ? Rspack.Configuration[] : WebpackConfig[];
44
+ environments: Record<string, EnvironmentContext>;
45
+ }) => MaybePromise<void>;
46
+ export type OnAfterCreateCompilerFn<Compiler = Rspack.Compiler | Rspack.MultiCompiler> = (params: {
47
+ compiler: Compiler;
48
+ environments: Record<string, EnvironmentContext>;
49
+ }) => MaybePromise<void>;
50
+ export type OnExitFn = () => void;
51
+ type HTMLTags = {
52
+ headTags: HtmlBasicTag[];
53
+ bodyTags: HtmlBasicTag[];
54
+ };
55
+ export type ModifyHTMLTagsContext = {
56
+ /**
57
+ * The Compilation object of Rspack.
58
+ */
59
+ compilation: Rspack.Compilation;
60
+ /**
61
+ * URL prefix of assets.
62
+ * @example 'https://example.com/'
63
+ */
64
+ assetPrefix: string;
65
+ /**
66
+ * The name of the HTML file, relative to the dist directory.
67
+ * @example 'index.html'
68
+ */
69
+ filename: string;
70
+ /** The related environment context. */
71
+ environment: EnvironmentContext;
72
+ };
73
+ export type ModifyHTMLTagsFn = (tags: HTMLTags, context: ModifyHTMLTagsContext) => MaybePromise<HTMLTags>;
74
+ export type ModifyRsbuildConfigUtils = {
75
+ /** Merge multiple Rsbuild config objects into one. */
76
+ mergeRsbuildConfig: (...configs: RsbuildConfig[]) => RsbuildConfig;
77
+ };
78
+ export type ModifyEnvironmentConfigUtils = {
79
+ /** environment name. */
80
+ name: string;
81
+ /** Merge multiple Rsbuild environment config objects into one. */
82
+ mergeEnvironmentConfig: (config: MergedEnvironmentConfig, ...configs: EnvironmentConfig[]) => MergedEnvironmentConfig;
83
+ };
84
+ export type ModifyRsbuildConfigFn = (config: RsbuildConfig, utils: ModifyRsbuildConfigUtils) => MaybePromise<RsbuildConfig | void>;
85
+ export type ModifyEnvironmentConfigFn = (config: MergedEnvironmentConfig, utils: ModifyEnvironmentConfigUtils) => MaybePromise<MergedEnvironmentConfig | void>;
86
+ export type EnvironmentContext = {
87
+ index: number;
88
+ name: string;
89
+ entry: RsbuildEntry;
90
+ htmlPaths: Record<string, string>;
91
+ distPath: string;
92
+ browserslist: string[];
93
+ tsconfigPath?: string;
94
+ config: NormalizedEnvironmentConfig;
95
+ };
96
+ export type ModifyChainUtils = {
97
+ env: NodeEnv;
98
+ isDev: boolean;
99
+ isProd: boolean;
100
+ target: RsbuildTarget;
101
+ isServer: boolean;
102
+ isWebWorker: boolean;
103
+ CHAIN_ID: ChainIdentifier;
104
+ environment: EnvironmentContext;
105
+ HtmlPlugin: typeof HtmlWebpackPlugin;
106
+ };
107
+ interface PluginInstance {
108
+ apply: (compiler: any) => void;
109
+ [k: string]: any;
110
+ }
111
+ export type ModifyBundlerChainUtils = ModifyChainUtils & {
112
+ bundler: {
113
+ BannerPlugin: PluginInstance;
114
+ DefinePlugin: PluginInstance;
115
+ IgnorePlugin: PluginInstance;
116
+ ProvidePlugin: PluginInstance;
117
+ HotModuleReplacementPlugin: PluginInstance;
118
+ };
119
+ };
120
+ export type ModifyBundlerChainFn = (chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>;
121
+ export type CreateAsyncHook<Callback extends (...args: any[]) => any> = {
122
+ tap: (cb: Callback) => void;
123
+ call: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
124
+ };
125
+ export {};
@@ -0,0 +1,9 @@
1
+ export * from './rspack';
2
+ export * from './rsbuild';
3
+ export * from './context';
4
+ export * from './utils';
5
+ export * from './plugin';
6
+ export * from './config';
7
+ export * from './stats';
8
+ export * from './hooks';
9
+ export * from './thirdParty';
@@ -0,0 +1,194 @@
1
+ import type { RuleSetCondition } from '@rspack/core';
2
+ import type HtmlWebpackPlugin from 'html-webpack-plugin';
3
+ import type RspackChain from '../../compiled/rspack-chain';
4
+ import type { RuleSetRule, Configuration as WebpackConfig, WebpackPluginInstance } from 'webpack';
5
+ import type { ChainIdentifier } from '../configChain';
6
+ import type { ModifyRspackConfigUtils, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
7
+ import type { RsbuildContext } from './context';
8
+ import type { ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn } from './hooks';
9
+ import type { RsbuildTarget } from './rsbuild';
10
+ import type { RspackConfig, RspackSourceMap } from './rspack';
11
+ import type { Falsy } from './utils';
12
+ import type { MaybePromise } from './utils';
13
+ type HookOrder = 'pre' | 'post' | 'default';
14
+ export type HookDescriptor<T extends (...args: any[]) => any> = {
15
+ handler: T;
16
+ order: HookOrder;
17
+ };
18
+ export type AsyncHook<Callback extends (...args: any[]) => any> = {
19
+ tap: (cb: Callback | HookDescriptor<Callback>) => void;
20
+ call: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
21
+ };
22
+ export type ModifyRspackConfigFn = (config: RspackConfig, utils: ModifyRspackConfigUtils) => Promise<RspackConfig | void> | RspackConfig | void;
23
+ export type ModifyWebpackChainUtils = ModifyChainUtils & {
24
+ webpack: typeof import('webpack');
25
+ CHAIN_ID: ChainIdentifier;
26
+ /**
27
+ * @deprecated Use target instead.
28
+ * */
29
+ name: string;
30
+ /**
31
+ * @deprecated Use HtmlPlugin instead.
32
+ */
33
+ HtmlWebpackPlugin: typeof HtmlWebpackPlugin;
34
+ };
35
+ export type ModifyWebpackConfigUtils = ModifyWebpackChainUtils & {
36
+ addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
37
+ prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
38
+ appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
39
+ removePlugin: (pluginName: string) => void;
40
+ mergeConfig: typeof import('..').merge;
41
+ };
42
+ export type ModifyWebpackChainFn = (chain: RspackChain, utils: ModifyWebpackChainUtils) => Promise<void> | void;
43
+ export type ModifyWebpackConfigFn = (config: WebpackConfig, utils: ModifyWebpackConfigUtils) => Promise<WebpackConfig | void> | WebpackConfig | void;
44
+ export type PluginManager = {
45
+ getPlugins: () => RsbuildPlugin[];
46
+ addPlugins: (plugins: Array<RsbuildPlugin | Falsy>, options?: {
47
+ before?: string;
48
+ }) => void;
49
+ removePlugins: (pluginNames: string[]) => void;
50
+ isPluginExists: (pluginName: string) => boolean;
51
+ /** The plugin API. */
52
+ pluginAPI?: RsbuildPluginAPI;
53
+ };
54
+ /**
55
+ * The type of the Rsbuild plugin object.
56
+ */
57
+ export type RsbuildPlugin = {
58
+ /**
59
+ * The name of the plugin, a unique identifier.
60
+ */
61
+ name: string;
62
+ /**
63
+ * The setup function of the plugin, which can be an async function.
64
+ * This function is called once when the plugin is initialized.
65
+ * @param api provides the context info, utility functions and lifecycle hooks.
66
+ */
67
+ setup: (api: RsbuildPluginAPI) => MaybePromise<void>;
68
+ /**
69
+ * Declare the names of pre-plugins, which will be executed before the current plugin.
70
+ */
71
+ pre?: string[];
72
+ /**
73
+ * Declare the names of post-plugins, which will be executed after the current plugin.
74
+ */
75
+ post?: string[];
76
+ /**
77
+ * Declare the plugins that need to be removed, you can pass an array of plugin names.
78
+ */
79
+ remove?: string[];
80
+ };
81
+ export type RsbuildPlugins = (RsbuildPlugin | Falsy | Promise<RsbuildPlugin | Falsy>)[];
82
+ export type GetRsbuildConfig = {
83
+ (): Readonly<RsbuildConfig>;
84
+ (type: 'original' | 'current'): Readonly<RsbuildConfig>;
85
+ (type: 'normalized'): NormalizedConfig;
86
+ };
87
+ type PluginHook<T extends (...args: any[]) => any> = (options: T | HookDescriptor<T>) => void;
88
+ type TransformResult = string | {
89
+ code: string;
90
+ map?: string | RspackSourceMap | null;
91
+ };
92
+ export type TransformContext = {
93
+ /**
94
+ * The code of the module.
95
+ */
96
+ code: string;
97
+ /**
98
+ * The absolute path of the module, including the query.
99
+ * @example '/home/user/project/src/index.js?foo=123'
100
+ */
101
+ resource: string;
102
+ /**
103
+ * The absolute path of the module, without the query.
104
+ * @example '/home/user/project/src/index.js'
105
+ */
106
+ resourcePath: string;
107
+ /**
108
+ * The query of the module.
109
+ * @example '?foo=123'
110
+ */
111
+ resourceQuery: string;
112
+ /**
113
+ * Add an additional file as the dependency.
114
+ * The file will be watched and changes to the file will trigger rebuild.
115
+ * @param file The absolute path of the module
116
+ */
117
+ addDependency: (file: string) => void;
118
+ /**
119
+ * Emits a file to the build output.
120
+ * @param name file name of the asset
121
+ * @param content the source of the asset
122
+ * @param sourceMap source map of the asset
123
+ * @param assetInfo additional asset information
124
+ */
125
+ emitFile: (name: string, content: string | Buffer, sourceMap?: string, assetInfo?: Record<string, any>) => void;
126
+ };
127
+ export type TransformHandler = (context: TransformContext) => MaybePromise<TransformResult>;
128
+ export type TransformDescriptor = {
129
+ /**
130
+ * Include modules that match the test assertion, the same as `rule.test`
131
+ * @see https://rspack.dev/config/module#ruletest
132
+ */
133
+ test?: RuleSetCondition;
134
+ /**
135
+ * A condition that matches the resource query.
136
+ * @see https://rspack.dev/config/module#ruleresourcequery
137
+ */
138
+ resourceQuery?: RuleSetCondition;
139
+ /**
140
+ * Match based on the Rsbuild targets and only apply the transform to certain targets.
141
+ * @see https://rsbuild.dev/config/output/targets
142
+ */
143
+ targets?: RsbuildTarget[];
144
+ /**
145
+ * If raw is `true`, the transform handler will receive the Buffer type code instead of the string type.
146
+ * @see https://rspack.dev/api/loader-api#raw-loader
147
+ */
148
+ raw?: boolean;
149
+ };
150
+ export type TransformFn = (descriptor: TransformDescriptor, handler: TransformHandler) => void;
151
+ declare function getNormalizedConfig(): NormalizedConfig;
152
+ declare function getNormalizedConfig(options: {
153
+ environment: string;
154
+ }): NormalizedEnvironmentConfig;
155
+ /**
156
+ * Define a generic Rsbuild plugin API that provider can extend as needed.
157
+ */
158
+ export type RsbuildPluginAPI = Readonly<{
159
+ context: Readonly<RsbuildContext>;
160
+ isPluginExists: PluginManager['isPluginExists'];
161
+ onExit: PluginHook<OnExitFn>;
162
+ onAfterBuild: PluginHook<OnAfterBuildFn>;
163
+ onBeforeBuild: PluginHook<OnBeforeBuildFn>;
164
+ onCloseDevServer: PluginHook<OnCloseDevServerFn>;
165
+ onDevCompileDone: PluginHook<OnDevCompileDoneFn>;
166
+ onAfterStartDevServer: PluginHook<OnAfterStartDevServerFn>;
167
+ onBeforeStartDevServer: PluginHook<OnBeforeStartDevServerFn>;
168
+ onAfterStartProdServer: PluginHook<OnAfterStartProdServerFn>;
169
+ onBeforeStartProdServer: PluginHook<OnBeforeStartProdServerFn>;
170
+ onAfterCreateCompiler: PluginHook<OnAfterCreateCompilerFn>;
171
+ onBeforeCreateCompiler: PluginHook<OnBeforeCreateCompilerFn>;
172
+ modifyHTMLTags: PluginHook<ModifyHTMLTagsFn>;
173
+ modifyRsbuildConfig: PluginHook<ModifyRsbuildConfigFn>;
174
+ modifyEnvironmentConfig: PluginHook<ModifyEnvironmentConfigFn>;
175
+ modifyBundlerChain: PluginHook<ModifyBundlerChainFn>;
176
+ /** Only works when bundler is Rspack */
177
+ modifyRspackConfig: PluginHook<ModifyRspackConfigFn>;
178
+ /** Only works when bundler is Webpack */
179
+ modifyWebpackChain: PluginHook<ModifyWebpackChainFn>;
180
+ /** Only works when bundler is Webpack */
181
+ modifyWebpackConfig: PluginHook<ModifyWebpackConfigFn>;
182
+ getRsbuildConfig: GetRsbuildConfig;
183
+ getNormalizedConfig: typeof getNormalizedConfig;
184
+ /**
185
+ * For plugin communication
186
+ */
187
+ expose: <T = any>(id: string | symbol, api: T) => void;
188
+ useExposed: <T = any>(id: string | symbol) => T | undefined;
189
+ /**
190
+ * Used to transform the code of modules.
191
+ */
192
+ transform: TransformFn;
193
+ }>;
194
+ export {};