@ohos-ports/rsbuild-core 2.2.9-beta.0
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.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/bin/rsbuild.js +20 -0
- package/compiled/@rstackjs/load-config/index.d.ts +87 -0
- package/compiled/@rstackjs/load-config/license +21 -0
- package/compiled/@rstackjs/load-config/package.json +1 -0
- package/compiled/chokidar/index.d.ts +385 -0
- package/compiled/chokidar/license +21 -0
- package/compiled/chokidar/package.json +1 -0
- package/compiled/connect-next/index.d.ts +57 -0
- package/compiled/connect-next/license +26 -0
- package/compiled/connect-next/package.json +1 -0
- package/compiled/cors/index.d.ts +56 -0
- package/compiled/cors/license +22 -0
- package/compiled/cors/package.json +1 -0
- package/compiled/css-loader/api.js +85 -0
- package/compiled/css-loader/getUrl.js +26 -0
- package/compiled/css-loader/index.d.ts +1 -0
- package/compiled/css-loader/index.js +2 -0
- package/compiled/css-loader/license +20 -0
- package/compiled/css-loader/noSourceMaps.js +5 -0
- package/compiled/css-loader/package.json +1 -0
- package/compiled/css-loader/sourceMaps.js +16 -0
- package/compiled/html-rspack-plugin/default_index.ejs +9 -0
- package/compiled/html-rspack-plugin/htmlLoader.js +157 -0
- package/compiled/html-rspack-plugin/index.d.ts +395 -0
- package/compiled/html-rspack-plugin/index.js +2400 -0
- package/compiled/html-rspack-plugin/license +20 -0
- package/compiled/html-rspack-plugin/package.json +1 -0
- package/compiled/http-proxy-middleware/index.d.ts +455 -0
- package/compiled/http-proxy-middleware/license +22 -0
- package/compiled/http-proxy-middleware/package.json +1 -0
- package/compiled/jiti/LICENSE +21 -0
- package/compiled/jiti/README.md +258 -0
- package/compiled/jiti/dist/babel.cjs +47446 -0
- package/compiled/jiti/dist/jiti.cjs +5990 -0
- package/compiled/jiti/lib/jiti-cli.mjs +19 -0
- package/compiled/jiti/lib/jiti-hooks.mjs +89 -0
- package/compiled/jiti/lib/jiti-native.mjs +76 -0
- package/compiled/jiti/lib/jiti-register.d.mts +1 -0
- package/compiled/jiti/lib/jiti-register.mjs +2 -0
- package/compiled/jiti/lib/jiti-static.mjs +19 -0
- package/compiled/jiti/lib/jiti.cjs +24 -0
- package/compiled/jiti/lib/jiti.d.cts +8 -0
- package/compiled/jiti/lib/jiti.d.mts +8 -0
- package/compiled/jiti/lib/jiti.mjs +23 -0
- package/compiled/jiti/lib/types.d.ts +420 -0
- package/compiled/jiti/package.json +146 -0
- package/compiled/postcss/index.js +1 -0
- package/compiled/postcss/lib/at-rule.d.ts +139 -0
- package/compiled/postcss/lib/comment.d.ts +67 -0
- package/compiled/postcss/lib/container.d.ts +474 -0
- package/compiled/postcss/lib/css-syntax-error.d.ts +247 -0
- package/compiled/postcss/lib/declaration.d.ts +150 -0
- package/compiled/postcss/lib/document.d.ts +68 -0
- package/compiled/postcss/lib/fromJSON.d.ts +9 -0
- package/compiled/postcss/lib/input.d.ts +226 -0
- package/compiled/postcss/lib/lazy-result.d.ts +189 -0
- package/compiled/postcss/lib/list.d.ts +60 -0
- package/compiled/postcss/lib/no-work-result.d.ts +45 -0
- package/compiled/postcss/lib/node.d.ts +555 -0
- package/compiled/postcss/lib/parse.d.ts +9 -0
- package/compiled/postcss/lib/postcss.d.ts +464 -0
- package/compiled/postcss/lib/previous-map.d.ts +80 -0
- package/compiled/postcss/lib/processor.d.ts +114 -0
- package/compiled/postcss/lib/result.d.ts +204 -0
- package/compiled/postcss/lib/root.d.ts +86 -0
- package/compiled/postcss/lib/rule.d.ts +126 -0
- package/compiled/postcss/lib/source-map-js.d.ts +4 -0
- package/compiled/postcss/lib/stringifier.d.ts +45 -0
- package/compiled/postcss/lib/stringify.d.ts +9 -0
- package/compiled/postcss/lib/warning.d.ts +146 -0
- package/compiled/postcss/license +20 -0
- package/compiled/postcss/package.json +1 -0
- package/compiled/postcss-loader/index.d.ts +1 -0
- package/compiled/postcss-loader/index.js +721 -0
- package/compiled/postcss-loader/license +20 -0
- package/compiled/postcss-loader/package.json +1 -0
- package/compiled/rslog/index.d.ts +98 -0
- package/compiled/rslog/license +21 -0
- package/compiled/rslog/package.json +1 -0
- package/compiled/rspack-chain/license +22 -0
- package/compiled/rspack-chain/package.json +1 -0
- package/compiled/rspack-chain/types/index.d.ts +515 -0
- package/compiled/rspack-manifest-plugin/index.d.ts +52 -0
- package/compiled/rspack-manifest-plugin/license +21 -0
- package/compiled/rspack-manifest-plugin/package.json +1 -0
- package/compiled/style-loader/index.d.ts +1 -0
- package/compiled/style-loader/index.js +370 -0
- package/compiled/style-loader/license +20 -0
- package/compiled/style-loader/package.json +1 -0
- package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
- package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
- package/compiled/style-loader/runtime/insertBySelector.js +34 -0
- package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
- package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
- package/compiled/style-loader/runtime/isOldIE.js +17 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
- package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
- package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
- package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
- package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
- package/compiled/ws/index.d.ts +445 -0
- package/compiled/ws/license +21 -0
- package/compiled/ws/package.json +1 -0
- package/dist/build.d.ts +4 -0
- package/dist/c.js +10 -0
- package/dist/chokidar.js +2 -0
- package/dist/chokidar.js.LICENSE.txt +1 -0
- package/dist/cli/commands.d.ts +31 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/init.d.ts +7 -0
- package/dist/client/f~0.js +22 -0
- package/dist/client/hmr.js +267 -0
- package/dist/client/overlay.js +214 -0
- package/dist/configChain.d.ts +84 -0
- package/dist/connect-next.js +2 -0
- package/dist/connect-next.js.LICENSE.txt +57 -0
- package/dist/constants.d.ts +67 -0
- package/dist/cors.js +188 -0
- package/dist/cors.js.LICENSE.txt +11 -0
- package/dist/createCompiler.d.ts +6 -0
- package/dist/createContext.d.ts +12 -0
- package/dist/createRsbuild.d.ts +4 -0
- package/dist/cssUrlLoader.mjs +34 -0
- package/dist/defaultConfig.d.ts +23 -0
- package/dist/freshImport.js +90 -0
- package/dist/helpers/cachedImport.d.ts +2 -0
- package/dist/helpers/compiler.d.ts +5 -0
- package/dist/helpers/css.d.ts +3 -0
- package/dist/helpers/exitHook.d.ts +3 -0
- package/dist/helpers/format.d.ts +4 -0
- package/dist/helpers/fs.d.ts +16 -0
- package/dist/helpers/html.d.ts +2 -0
- package/dist/helpers/index.d.ts +29 -0
- package/dist/helpers/overlayConfig.d.ts +4 -0
- package/dist/helpers/packageJson.d.ts +9 -0
- package/dist/helpers/path.d.ts +22 -0
- package/dist/helpers/restartManager.d.ts +15 -0
- package/dist/helpers/stats.d.ts +17 -0
- package/dist/helpers/url.d.ts +11 -0
- package/dist/helpers/vendors.d.ts +12 -0
- package/dist/helpers/version.d.ts +7 -0
- package/dist/hooks.d.ts +41 -0
- package/dist/http-proxy-middleware.js +14 -0
- package/dist/http-proxy-middleware.js.LICENSE.txt +34 -0
- package/dist/ignoreCssLoader.mjs +9 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +1 -0
- package/dist/initConfigs.d.ts +18 -0
- package/dist/initPlugins.d.ts +7 -0
- package/dist/inspectConfig.d.ts +7 -0
- package/dist/launch-editor-middleware.js +1 -0
- package/dist/loadConfig.d.ts +31 -0
- package/dist/loadEnv.d.ts +54 -0
- package/dist/loader/cssUrlLoader.d.ts +9 -0
- package/dist/loader/ignoreCssLoader.d.ts +10 -0
- package/dist/loader/transformLoader.d.ts +8 -0
- package/dist/loader/transformRawLoader.d.ts +4 -0
- package/dist/loader/workerLoader.d.ts +6 -0
- package/dist/logger.d.ts +24 -0
- package/dist/m.js +10348 -0
- package/dist/m.js.LICENSE.txt +26 -0
- package/dist/manifest-plugin.js +1 -0
- package/dist/memfs.js +1 -0
- package/dist/mergeConfig.d.ts +7 -0
- package/dist/open.js +2 -0
- package/dist/pluginHelper.d.ts +4 -0
- package/dist/pluginManager.d.ts +19 -0
- package/dist/plugins/appIcon.d.ts +2 -0
- package/dist/plugins/asset.d.ts +3 -0
- package/dist/plugins/basic.d.ts +4 -0
- package/dist/plugins/cache.d.ts +2 -0
- package/dist/plugins/cleanOutput.d.ts +2 -0
- package/dist/plugins/css.d.ts +8 -0
- package/dist/plugins/define.d.ts +2 -0
- package/dist/plugins/entry.d.ts +2 -0
- package/dist/plugins/externals.d.ts +9 -0
- package/dist/plugins/fileSize.d.ts +7 -0
- package/dist/plugins/html.d.ts +9 -0
- package/dist/plugins/inlineChunk.d.ts +6 -0
- package/dist/plugins/lazyCompilation.d.ts +2 -0
- package/dist/plugins/manifest.d.ts +2 -0
- package/dist/plugins/minimize.d.ts +10 -0
- package/dist/plugins/moduleFederation.d.ts +2 -0
- package/dist/plugins/nodeAddons.d.ts +2 -0
- package/dist/plugins/nonce.d.ts +2 -0
- package/dist/plugins/output.d.ts +2 -0
- package/dist/plugins/progress.d.ts +2 -0
- package/dist/plugins/resolve.d.ts +2 -0
- package/dist/plugins/resourceHints.d.ts +2 -0
- package/dist/plugins/rsdoctor.d.ts +2 -0
- package/dist/plugins/rspackProfile.d.ts +4 -0
- package/dist/plugins/server.d.ts +3 -0
- package/dist/plugins/sourceMap.d.ts +2 -0
- package/dist/plugins/splitChunks.d.ts +4 -0
- package/dist/plugins/sri.d.ts +2 -0
- package/dist/plugins/swc.d.ts +4 -0
- package/dist/plugins/target.d.ts +2 -0
- package/dist/plugins/wasm.d.ts +2 -0
- package/dist/plugins/worker.d.ts +2 -0
- package/dist/r.js +7 -0
- package/dist/range-parser.js +55 -0
- package/dist/range-parser.js.LICENSE.txt +6 -0
- package/dist/remapping.js +201 -0
- package/dist/restart.d.ts +15 -0
- package/dist/rslib-runtime.js +49 -0
- package/dist/rspack-plugins/RsbuildHtmlPlugin.d.ts +37 -0
- package/dist/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +36 -0
- package/dist/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +27 -0
- package/dist/rspack-plugins/resource-hints/extractChunks.d.ts +22 -0
- package/dist/rspack-plugins/resource-hints/getResourceType.d.ts +21 -0
- package/dist/rspackConfig.d.ts +8 -0
- package/dist/server/ansiHTML.d.ts +3 -0
- package/dist/server/assets-middleware/getFileFromUrl.d.ts +11 -0
- package/dist/server/assets-middleware/index.d.ts +35 -0
- package/dist/server/assets-middleware/memoryFileSystem.d.ts +2 -0
- package/dist/server/assets-middleware/middleware.d.ts +7 -0
- package/dist/server/assets-middleware/parseTokenList.d.ts +1 -0
- package/dist/server/assets-middleware/setupOutputFileSystem.d.ts +3 -0
- package/dist/server/assets-middleware/setupWriteToDisk.d.ts +15 -0
- package/dist/server/browserLogs.d.ts +8 -0
- package/dist/server/buildManager.d.ts +32 -0
- package/dist/server/cliShortcuts.d.ts +19 -0
- package/dist/server/compileState.d.ts +5 -0
- package/dist/server/devMiddlewares.d.ts +18 -0
- package/dist/server/devServer.d.ts +47 -0
- package/dist/server/environment.d.ts +8 -0
- package/dist/server/gracefulShutdown.d.ts +8 -0
- package/dist/server/gzipMiddleware.d.ts +2 -0
- package/dist/server/helper.d.ts +118 -0
- package/dist/server/historyApiFallback.d.ts +10 -0
- package/dist/server/hmrFallback.d.ts +1 -0
- package/dist/server/httpServer.d.ts +7 -0
- package/dist/server/middlewares.d.ts +31 -0
- package/dist/server/open.d.ts +12 -0
- package/dist/server/overlay.d.ts +3 -0
- package/dist/server/previewServer.d.ts +4 -0
- package/dist/server/proxy.d.ts +7 -0
- package/dist/server/publicPathnames.d.ts +2 -0
- package/dist/server/runner/asModule.d.ts +2 -0
- package/dist/server/runner/basic.d.ts +25 -0
- package/dist/server/runner/cjs.d.ts +10 -0
- package/dist/server/runner/esm.d.ts +6 -0
- package/dist/server/runner/index.d.ts +6 -0
- package/dist/server/runner/type.d.ts +42 -0
- package/dist/server/serverSetup.d.ts +2 -0
- package/dist/server/socketServer.d.ts +113 -0
- package/dist/server/watchFiles.d.ts +15 -0
- package/dist/sirv.js +122 -0
- package/dist/tinyglobby.js +1 -0
- package/dist/trace-mapping.js +548 -0
- package/dist/transformLoader.mjs +36 -0
- package/dist/transformRawLoader.mjs +4 -0
- package/dist/types/config.d.ts +1796 -0
- package/dist/types/context.d.ts +89 -0
- package/dist/types/hooks.d.ts +261 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/plugin.d.ts +479 -0
- package/dist/types/rsbuild.d.ts +241 -0
- package/dist/types/rspack.d.ts +10 -0
- package/dist/types/thirdParty.d.ts +161 -0
- package/dist/types/utils.d.ts +16 -0
- package/dist/workerLoader.mjs +94 -0
- package/dist/ws.js +2 -0
- package/package.json +107 -0
- package/static/openChrome.applescript +95 -0
- package/types.d.ts +422 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import type { Logger } from '../logger.js';
|
|
2
|
+
import type { ModifyRspackConfigUtils, NarrowedRspackConfig, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config.js';
|
|
3
|
+
import type { RsbuildContext } from './context.js';
|
|
4
|
+
import type { EnvironmentContext, ModifyBundlerChainFn, ModifyEnvironmentConfigFn, ModifyHTMLFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDevCompileFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartPreviewServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDevCompileFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartPreviewServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnExitFn, OnRestartFn } from './hooks.js';
|
|
5
|
+
import type { AddPluginsOptions, RsbuildInstance, RsbuildTarget } from './rsbuild.js';
|
|
6
|
+
import type { Rspack } from './rspack.js';
|
|
7
|
+
import type { Falsy, MaybePromise } from './utils.js';
|
|
8
|
+
type HookOrder = 'pre' | 'post' | 'default';
|
|
9
|
+
export type HookDescriptor<T extends (...args: any[]) => any> = {
|
|
10
|
+
handler: T;
|
|
11
|
+
order: HookOrder;
|
|
12
|
+
};
|
|
13
|
+
export type EnvironmentAsyncHook<Callback extends (...args: any[]) => T, T = any> = {
|
|
14
|
+
/**
|
|
15
|
+
* Registers a callback function to be executed when the hook is triggered.
|
|
16
|
+
* The callback can be a plain function or a HookDescriptor that includes execution order.
|
|
17
|
+
* The callback will be executed in all environments by default.
|
|
18
|
+
* If you need to specify the environment, use `tapEnvironment`
|
|
19
|
+
* @param cb The callback function or hook descriptor to register
|
|
20
|
+
*/ tap: (cb: Callback | HookDescriptor<Callback>) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Registers a callback function to be executed when the hook is triggered.
|
|
23
|
+
* The callback will only be executed under the specified environment.
|
|
24
|
+
*/ tapEnvironment: (params: {
|
|
25
|
+
/**
|
|
26
|
+
* Specify the environment that the callback will be executed under.
|
|
27
|
+
*/ environment?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The callback function or hook descriptor to register
|
|
30
|
+
*/ handler: Callback | HookDescriptor<Callback>;
|
|
31
|
+
}) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Executes callbacks in sequence independently and collects all their results into an array.
|
|
34
|
+
* Each callback receives the original parameters, and their results don't affect subsequent callbacks.
|
|
35
|
+
* @returns A promise that resolves with an array containing the results of all callbacks
|
|
36
|
+
*/ callChain: (params: {
|
|
37
|
+
/**
|
|
38
|
+
* Specify the environment for filtering callbacks.
|
|
39
|
+
*/ environment?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The parameters to pass to each callback
|
|
42
|
+
*/ args: Parameters<Callback>;
|
|
43
|
+
/**
|
|
44
|
+
* The callback function to be executed after each callback
|
|
45
|
+
*/ afterEach?: (args: Parameters<Callback>) => void;
|
|
46
|
+
}) => Promise<Parameters<Callback>>;
|
|
47
|
+
/**
|
|
48
|
+
* Executes callbacks in sequence independently and collects all their results into an array.
|
|
49
|
+
* Each callback receives the original parameters, and their results don't affect subsequent callbacks.
|
|
50
|
+
* @returns A promise that resolves with an array containing the results of all callbacks
|
|
51
|
+
*/ callBatch: (params: {
|
|
52
|
+
/**
|
|
53
|
+
* Specify the environment for filtering callbacks.
|
|
54
|
+
*/ environment?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The parameters to pass to each callback
|
|
57
|
+
*/ args: Parameters<Callback>;
|
|
58
|
+
}) => Promise<Awaited<ReturnType<Callback>>[]>;
|
|
59
|
+
};
|
|
60
|
+
export type AsyncHook<Callback extends (...args: any[]) => T, T = any> = {
|
|
61
|
+
/**
|
|
62
|
+
* Registers a callback function to be executed when the hook is triggered.
|
|
63
|
+
* The callback can be a plain function or a HookDescriptor that includes execution order.
|
|
64
|
+
* @param cb The callback function or hook descriptor to register
|
|
65
|
+
*/ tap: (cb: Callback | HookDescriptor<Callback>) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Executes callbacks in sequence, passing the result of each callback as the first argument
|
|
68
|
+
* to the next callback in the chain. If a callback returns undefined, the original arguments
|
|
69
|
+
* will be passed to the next callback.
|
|
70
|
+
* @param params The initial parameters to pass to the first callback
|
|
71
|
+
* @returns A promise that resolves with the final parameters after all callbacks have executed
|
|
72
|
+
*/ callChain: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
|
|
73
|
+
/**
|
|
74
|
+
* Executes callbacks in sequence independently and collects all their results into an array.
|
|
75
|
+
* Each callback receives the original parameters, and their results don't affect subsequent callbacks.
|
|
76
|
+
* @param params The parameters to pass to each callback
|
|
77
|
+
* @returns A promise that resolves with an array containing the results of all callbacks
|
|
78
|
+
*/ callBatch: (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>[]>;
|
|
79
|
+
};
|
|
80
|
+
export type ModifyRspackConfigFn = (config: NarrowedRspackConfig, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
|
|
81
|
+
export type PluginMeta = {
|
|
82
|
+
environment?: AddPluginsOptions['environment'];
|
|
83
|
+
instance: RsbuildPlugin;
|
|
84
|
+
};
|
|
85
|
+
export type PluginManager = Pick<RsbuildInstance, 'getPlugins' | 'addPlugins' | 'isPluginExists' | 'removePlugins'> & {
|
|
86
|
+
/** Get all plugins with environment info */ getAllPluginsWithMeta: () => PluginMeta[];
|
|
87
|
+
};
|
|
88
|
+
export type RsbuildPluginApplyFn = (// rslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
89
|
+
this: void, /**
|
|
90
|
+
* The original Rsbuild configuration object (before plugin processing)
|
|
91
|
+
*/ config: RsbuildConfig, context: Pick<RsbuildContext, 'action'>) => boolean;
|
|
92
|
+
export type RsbuildPluginApply = 'serve' | 'build' | RsbuildPluginApplyFn;
|
|
93
|
+
/**
|
|
94
|
+
* Defines the structure and behavior of an Rsbuild plugin.
|
|
95
|
+
* Rsbuild plugins provide a standardized way to extend build functionality through
|
|
96
|
+
* lifecycle hooks and configuration modifications.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const myPlugin = (): RsbuildPlugin => ({
|
|
101
|
+
* name: 'my-plugin',
|
|
102
|
+
* setup(api) {
|
|
103
|
+
* api.onBeforeBuild(() => {
|
|
104
|
+
* console.log('Build starting...');
|
|
105
|
+
* });
|
|
106
|
+
* }
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/ export type RsbuildPlugin = {
|
|
110
|
+
/**
|
|
111
|
+
* The name of the plugin, a unique identifier.
|
|
112
|
+
*/ name: string;
|
|
113
|
+
/**
|
|
114
|
+
* Conditional apply the plugin during serve or build.
|
|
115
|
+
* - `'serve'`: Apply the plugin when starting the dev server or preview server.
|
|
116
|
+
* - `'build'`: Apply the plugin during build.
|
|
117
|
+
* - Can be a function that returns `true` to apply the plugin or `false` to skip it.
|
|
118
|
+
* - If not specified, the plugin will be applied during both serve and build.
|
|
119
|
+
*/ apply?: RsbuildPluginApply;
|
|
120
|
+
/**
|
|
121
|
+
* The setup function of the plugin, which can be an async function.
|
|
122
|
+
* This function is called once when the plugin is initialized.
|
|
123
|
+
* @param api provides the context info, utility functions and lifecycle hooks.
|
|
124
|
+
*/ setup: (api: RsbuildPluginAPI) => MaybePromise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Specifies the execution order of the plugin.
|
|
127
|
+
* - `'pre'`: Execute the plugin before other plugins.
|
|
128
|
+
* - `'post'`: Execute the plugin after other plugins.
|
|
129
|
+
* - If not specified, the plugin will execute in the order they were registered.
|
|
130
|
+
*
|
|
131
|
+
* This affects the order in which hooks are registered, but if a hook specifies
|
|
132
|
+
* an `order` property, the `order` takes higher precedence.
|
|
133
|
+
*/ enforce?: 'pre' | 'post';
|
|
134
|
+
/**
|
|
135
|
+
* Declare the names of pre-plugins, which will be executed before the current plugin.
|
|
136
|
+
* This has higher precedence than the `enforce` property.
|
|
137
|
+
*/ pre?: string[];
|
|
138
|
+
/**
|
|
139
|
+
* Declare the names of post-plugins, which will be executed after the current plugin.
|
|
140
|
+
* This has higher precedence than the `enforce` property.
|
|
141
|
+
*/ post?: string[];
|
|
142
|
+
/**
|
|
143
|
+
* Declare the plugins that need to be removed, you can pass an array of plugin names.
|
|
144
|
+
*/ remove?: string[];
|
|
145
|
+
};
|
|
146
|
+
// Support for registering lower version Rsbuild plugins in the new version of
|
|
147
|
+
// Rsbuild core without throwing type mismatches. In most cases, Rsbuild core
|
|
148
|
+
// only adds new methods or properties to the API object, which means that lower
|
|
149
|
+
// version plugins will usually work fine.
|
|
150
|
+
type LooseRsbuildPlugin = Omit<RsbuildPlugin, 'setup' | 'apply'> & {
|
|
151
|
+
apply?: any;
|
|
152
|
+
setup: (api: any) => MaybePromise<void>;
|
|
153
|
+
};
|
|
154
|
+
export type RsbuildPlugins = (LooseRsbuildPlugin | Falsy | Promise<LooseRsbuildPlugin | Falsy | RsbuildPlugins> | RsbuildPlugins)[];
|
|
155
|
+
export type GetRsbuildConfig = {
|
|
156
|
+
() : Readonly<RsbuildConfig>;
|
|
157
|
+
(type: 'original' | 'current') : Readonly<RsbuildConfig>;
|
|
158
|
+
(type: 'normalized') : NormalizedConfig;
|
|
159
|
+
};
|
|
160
|
+
export type ExposeOptions = {
|
|
161
|
+
/**
|
|
162
|
+
* Register the exposed API for a specific Rsbuild environment name (the key of `config.environments`).
|
|
163
|
+
* If omitted, the API is registered as global.
|
|
164
|
+
*/ environment?: string;
|
|
165
|
+
};
|
|
166
|
+
type PluginHook<T extends (...args: any[]) => any> = (options: T | HookDescriptor<T>) => void;
|
|
167
|
+
type TransformResult = string | Buffer | {
|
|
168
|
+
code: string | Buffer;
|
|
169
|
+
map?: string | Rspack.RawSourceMap | null;
|
|
170
|
+
};
|
|
171
|
+
export type TransformContext<Raw extends boolean = false> = {
|
|
172
|
+
/**
|
|
173
|
+
* The code of the module.
|
|
174
|
+
* When `raw` is true, this will be a Buffer instead of a string.
|
|
175
|
+
*/ code: Raw extends true ? Buffer : string;
|
|
176
|
+
/**
|
|
177
|
+
* The directory path of the currently processed module,
|
|
178
|
+
* which changes with the location of each processed module.
|
|
179
|
+
*/ context: string | null;
|
|
180
|
+
/**
|
|
181
|
+
* The absolute path of the module, including the query.
|
|
182
|
+
* @example '/home/user/project/src/index.js?foo=123'
|
|
183
|
+
*/ resource: string;
|
|
184
|
+
/**
|
|
185
|
+
* The absolute path of the module, without the query.
|
|
186
|
+
* @example '/home/user/project/src/index.js'
|
|
187
|
+
*/ resourcePath: string;
|
|
188
|
+
/**
|
|
189
|
+
* The query of the module.
|
|
190
|
+
* @example '?foo=123'
|
|
191
|
+
*/ resourceQuery: string;
|
|
192
|
+
/**
|
|
193
|
+
* The environment context for current build.
|
|
194
|
+
*/ environment: EnvironmentContext;
|
|
195
|
+
/**
|
|
196
|
+
* Add an additional file as the dependency.
|
|
197
|
+
* The file will be watched and changes to the file will trigger rebuild.
|
|
198
|
+
* @param file The absolute path of the module
|
|
199
|
+
*/ addDependency: (file: string) => void;
|
|
200
|
+
/**
|
|
201
|
+
* Add a non-existing file as a dependency.
|
|
202
|
+
* Similar to addDependency, but handles the creation of files during compilation before watchers are attached correctly.
|
|
203
|
+
* The file will be watched and changes to the file will trigger rebuild.
|
|
204
|
+
* @param file The absolute path of the module
|
|
205
|
+
*/ addMissingDependency(file: string): void;
|
|
206
|
+
/**
|
|
207
|
+
* Add a directory as dependency.
|
|
208
|
+
* The directory will be watched and changes to the directory will trigger rebuild.
|
|
209
|
+
* @param context The absolute path of the directory
|
|
210
|
+
*/ addContextDependency(context: string): void;
|
|
211
|
+
/**
|
|
212
|
+
* Emits a file to the build output.
|
|
213
|
+
* @param name file name of the asset
|
|
214
|
+
* @param content the source of the asset
|
|
215
|
+
* @param sourceMap source map of the asset
|
|
216
|
+
* @param assetInfo additional asset information
|
|
217
|
+
*/ emitFile: Rspack.LoaderContext['emitFile'];
|
|
218
|
+
/**
|
|
219
|
+
* Compile and execute a module at the build time.
|
|
220
|
+
*/ importModule: Rspack.LoaderContext['importModule'];
|
|
221
|
+
/**
|
|
222
|
+
* Resolve a module specifier.
|
|
223
|
+
*/ resolve: Rspack.LoaderContext['resolve'];
|
|
224
|
+
};
|
|
225
|
+
export type TransformHandler<Raw extends boolean = false> = (context: TransformContext<Raw>) => MaybePromise<TransformResult>;
|
|
226
|
+
export type TransformDescriptor = {
|
|
227
|
+
/**
|
|
228
|
+
* Include modules that match the test assertion, the same as `rules[].test`
|
|
229
|
+
* @see https://rspack.rs/config/module-rules#rulestest
|
|
230
|
+
*/ test?: Rspack.RuleSetCondition;
|
|
231
|
+
/**
|
|
232
|
+
* A condition that matches the resource query.
|
|
233
|
+
* @see https://rspack.rs/config/module-rules#rulesresourcequery
|
|
234
|
+
*/ resourceQuery?: Rspack.RuleSetCondition;
|
|
235
|
+
/**
|
|
236
|
+
* Match based on the Rsbuild targets and only apply the transform to
|
|
237
|
+
* certain targets.
|
|
238
|
+
* @see https://rsbuild.rs/config/output/target
|
|
239
|
+
*/ targets?: RsbuildTarget[];
|
|
240
|
+
/**
|
|
241
|
+
* Match based on the Rsbuild environment names and only apply the transform
|
|
242
|
+
* to certain environments.
|
|
243
|
+
* @see https://rsbuild.rs/config/environments
|
|
244
|
+
*/ environments?: string[];
|
|
245
|
+
/**
|
|
246
|
+
* If raw is `true`, the transform handler will receive the Buffer type code
|
|
247
|
+
* instead of the string type.
|
|
248
|
+
* @see https://rspack.rs/api/loader-api/writing-loaders#raw-loader
|
|
249
|
+
*/ raw?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Marks the layer of the matching module, can be used to group a group of
|
|
252
|
+
* modules into one layer
|
|
253
|
+
* @see https://rspack.rs/config/module-rules#ruleslayer
|
|
254
|
+
*/ layer?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Matches all modules that match this resource, and will match against layer of
|
|
257
|
+
* the module that issued the current module.
|
|
258
|
+
* @see https://rspack.rs/config/module-rules#rulesissuerlayer
|
|
259
|
+
*/ issuerLayer?: string;
|
|
260
|
+
/**
|
|
261
|
+
* Matches all modules that match this resource, and will match against Resource
|
|
262
|
+
* (the absolute path without query and fragment) of the module that issued the
|
|
263
|
+
* current module.
|
|
264
|
+
* @see https://rspack.rs/config/module-rules#rulesissuer
|
|
265
|
+
*/ issuer?: Rspack.RuleSetCondition;
|
|
266
|
+
/**
|
|
267
|
+
* Matches [import attributes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with)
|
|
268
|
+
* @see https://rspack.rs/config/module-rules#ruleswith
|
|
269
|
+
*/ with?: Record<string, Rspack.RuleSetCondition>;
|
|
270
|
+
/**
|
|
271
|
+
* Matches modules based on MIME type instead of file extension. It's primarily
|
|
272
|
+
* useful for data URI module (like `data:text/javascript,...`).
|
|
273
|
+
* @see https://rspack.rs/config/module-rules#rulesmimetype
|
|
274
|
+
*/ mimetype?: Rspack.RuleSetCondition;
|
|
275
|
+
/**
|
|
276
|
+
* The original property for specifying execution order, now deprecated in favor of `order`.
|
|
277
|
+
* @deprecated Use `order` instead.
|
|
278
|
+
*/ enforce?: 'pre' | 'post';
|
|
279
|
+
/**
|
|
280
|
+
* Specifies the execution order of the transform function.
|
|
281
|
+
* - When specified as 'pre', the transform function will execute before other
|
|
282
|
+
* transform functions (or Rspack loaders).
|
|
283
|
+
* - When specified as 'post', the transform function will execute after other
|
|
284
|
+
* transform functions (or Rspack loaders).
|
|
285
|
+
* @see https://rspack.rs/config/module-rules#rulesenforce
|
|
286
|
+
*/ order?: HookOrder;
|
|
287
|
+
};
|
|
288
|
+
export type TransformHook = <T extends TransformDescriptor>(descriptor: T, handler: TransformHandler<T['raw'] extends true ? true : false>) => void;
|
|
289
|
+
export type ProcessAssetsStage = 'additional' | 'pre-process' | 'derived' | 'additions' | 'none' | 'optimize' | 'optimize-count' | 'optimize-compatibility' | 'optimize-size' | 'dev-tooling' | 'optimize-inline' | 'summarize' | 'optimize-hash' | 'optimize-transfer' | 'analyse' | 'report';
|
|
290
|
+
export type ProcessAssetsDescriptor = {
|
|
291
|
+
/**
|
|
292
|
+
* Specifies the order in which your asset processing logic should run relative to other plugins.
|
|
293
|
+
*/ stage: ProcessAssetsStage;
|
|
294
|
+
/**
|
|
295
|
+
* Match based on the Rsbuild targets and only process the assets of certain targets.
|
|
296
|
+
* @see https://rsbuild.rs/config/output/target
|
|
297
|
+
*/ targets?: RsbuildTarget[];
|
|
298
|
+
/**
|
|
299
|
+
* Match based on the Rsbuild environment names and only process the assets of certain environments.
|
|
300
|
+
* @see https://rsbuild.rs/config/environments
|
|
301
|
+
*/ environments?: string[];
|
|
302
|
+
};
|
|
303
|
+
export type RspackSources = Pick<typeof Rspack.sources, 'Source' | 'RawSource' | 'OriginalSource' | 'SourceMapSource' | 'CachedSource' | 'ConcatSource' | 'ReplaceSource' | 'PrefixSource' | 'SizeOnlySource' | 'CompatSource'>;
|
|
304
|
+
export type ProcessAssetsHandler = (context: {
|
|
305
|
+
assets: Record<string, Rspack.sources.Source>;
|
|
306
|
+
compiler: Rspack.Compiler;
|
|
307
|
+
compilation: Rspack.Compilation;
|
|
308
|
+
/**
|
|
309
|
+
* The environment context for current build.
|
|
310
|
+
*/ environment: EnvironmentContext;
|
|
311
|
+
/**
|
|
312
|
+
* Contains multiple classes which represent an Rspack `Source`.
|
|
313
|
+
*/ sources: RspackSources;
|
|
314
|
+
}) => Promise<void> | void;
|
|
315
|
+
export type ResolveHandler = (context: {
|
|
316
|
+
/** Module request information */ resolveData: Rspack.ResolveData;
|
|
317
|
+
/** The environment context for current build. */ environment: EnvironmentContext;
|
|
318
|
+
compiler: Rspack.Compiler;
|
|
319
|
+
compilation: Rspack.Compilation;
|
|
320
|
+
}) => Promise<void> | void;
|
|
321
|
+
export type ResolveHook = (handler: ResolveHandler) => void;
|
|
322
|
+
export type ProcessAssetsHook = (descriptor: ProcessAssetsDescriptor, handler: ProcessAssetsHandler) => void;
|
|
323
|
+
export type GetNormalizedConfig = {
|
|
324
|
+
() : NormalizedConfig;
|
|
325
|
+
(options: {
|
|
326
|
+
environment: string;
|
|
327
|
+
}) : NormalizedEnvironmentConfig;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* The API interface provided to Rsbuild plugins through the `setup` function.
|
|
331
|
+
* It allows plugins to interact with the build process, modify configurations,
|
|
332
|
+
* register hooks, and access context information.
|
|
333
|
+
*/ export type RsbuildPluginAPI = Readonly<{
|
|
334
|
+
/**
|
|
335
|
+
* A read-only object that provides some context information.
|
|
336
|
+
*/ context: Readonly<RsbuildContext>;
|
|
337
|
+
/**
|
|
338
|
+
* Explicitly expose some properties or methods of the current plugin,
|
|
339
|
+
* and other plugins can get these APIs through `api.useExposed`.
|
|
340
|
+
*/ expose: <T = any>(id: string | symbol, api: T, options?: ExposeOptions) => void;
|
|
341
|
+
/**
|
|
342
|
+
* Get the Rsbuild config, this method must be called after the
|
|
343
|
+
* `modifyRsbuildConfig` hook is executed.
|
|
344
|
+
*/ getRsbuildConfig: GetRsbuildConfig;
|
|
345
|
+
/**
|
|
346
|
+
* Get the all normalized Rsbuild config or the Rsbuild config of a specified
|
|
347
|
+
* environment, this method must be called after the
|
|
348
|
+
* `modifyRsbuildConfig` hook is executed.
|
|
349
|
+
*/ getNormalizedConfig: GetNormalizedConfig;
|
|
350
|
+
/**
|
|
351
|
+
* A logger instance used to output log information in a unified format.
|
|
352
|
+
* Use this instead of `console.log` to maintain consistent logging with Rsbuild.
|
|
353
|
+
* It is associated with the current Rsbuild instance and reflects
|
|
354
|
+
* `config.customLogger` when provided.
|
|
355
|
+
*/ logger: Logger;
|
|
356
|
+
/**
|
|
357
|
+
* Determines if a plugin has been registered in the current Rsbuild instance.
|
|
358
|
+
*/ isPluginExists: (pluginName: string, options?: {
|
|
359
|
+
/**
|
|
360
|
+
* Whether it exists in the specified environment.
|
|
361
|
+
* If environment is not specified, determine whether the plugin is a global plugin.
|
|
362
|
+
*/ environment: string;
|
|
363
|
+
}) => boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Allows you to modify the Rspack configuration using the `rspack-chain` API,
|
|
366
|
+
* providing the same functionality as `tools.bundlerChain`.
|
|
367
|
+
*/ modifyBundlerChain: PluginHook<ModifyBundlerChainFn>;
|
|
368
|
+
/**
|
|
369
|
+
* Modify the Rsbuild configuration of a specific environment.
|
|
370
|
+
*/ modifyEnvironmentConfig: PluginHook<ModifyEnvironmentConfigFn>;
|
|
371
|
+
/**
|
|
372
|
+
* Modify the final HTML content. The hook receives a HTML string
|
|
373
|
+
* and a context object, and you can return a new HTML string to
|
|
374
|
+
* replace the original one. This hook is triggered after the
|
|
375
|
+
* `modifyHTMLTags` hook.
|
|
376
|
+
*/ modifyHTML: PluginHook<ModifyHTMLFn>;
|
|
377
|
+
/**
|
|
378
|
+
* Modify the tags that are injected into the HTML.
|
|
379
|
+
* This hook is triggered before the `modifyHTML` hook.
|
|
380
|
+
*/ modifyHTMLTags: PluginHook<ModifyHTMLTagsFn>;
|
|
381
|
+
/**
|
|
382
|
+
* To modify the Rspack config, you can directly modify the config object,
|
|
383
|
+
* or return a new object to replace the previous object.
|
|
384
|
+
*/ modifyRspackConfig: PluginHook<ModifyRspackConfigFn>;
|
|
385
|
+
/**
|
|
386
|
+
* Modify the config passed to the Rsbuild, you can directly modify the config object,
|
|
387
|
+
* or return a new object to replace the previous object.
|
|
388
|
+
*/ modifyRsbuildConfig: PluginHook<ModifyRsbuildConfigFn>;
|
|
389
|
+
/**
|
|
390
|
+
* A callback function that is triggered after running the production build.
|
|
391
|
+
* You can access the build result information via the
|
|
392
|
+
* [stats](https://rspack.rs/api/javascript-api/stats) parameter.
|
|
393
|
+
*/ onAfterBuild: PluginHook<OnAfterBuildFn>;
|
|
394
|
+
/**
|
|
395
|
+
* A callback function that is triggered after the Rspack Compiler instance has been
|
|
396
|
+
* created, but before the build process. This hook is called when you run
|
|
397
|
+
* `rsbuild.startDevServer`, `rsbuild.build`, or `rsbuild.createCompiler`.
|
|
398
|
+
*/ onAfterCreateCompiler: PluginHook<OnAfterCreateCompilerFn>;
|
|
399
|
+
/**
|
|
400
|
+
* Called after each development mode build, you can use `isFirstCompile`
|
|
401
|
+
* to determine whether it is the first build.
|
|
402
|
+
*/ onAfterDevCompile: PluginHook<OnAfterDevCompileFn>;
|
|
403
|
+
/**
|
|
404
|
+
* A callback function that is triggered after the compilation of a single environment.
|
|
405
|
+
* You can access the build result information via the
|
|
406
|
+
* [stats](https://rspack.rs/api/javascript-api/stats) parameter.
|
|
407
|
+
*/ onAfterEnvironmentCompile: PluginHook<OnAfterEnvironmentCompileFn>;
|
|
408
|
+
/**
|
|
409
|
+
* Called after starting the dev server, you can get the port number with the
|
|
410
|
+
* `port` parameter, and the page routes info with the `routes` parameter.
|
|
411
|
+
*/ onAfterStartDevServer: PluginHook<OnAfterStartDevServerFn>;
|
|
412
|
+
/**
|
|
413
|
+
* Called after starting the preview server, you can get the port
|
|
414
|
+
* number with the `port` parameter, and the page routes info with the
|
|
415
|
+
* `routes` parameter.
|
|
416
|
+
*/ onAfterStartPreviewServer: PluginHook<OnAfterStartPreviewServerFn>;
|
|
417
|
+
/**
|
|
418
|
+
* A callback function that is triggered before the production build is executed.
|
|
419
|
+
*/ onBeforeBuild: PluginHook<OnBeforeBuildFn>;
|
|
420
|
+
/**
|
|
421
|
+
* A callback function that is triggered before the dev build is executed.
|
|
422
|
+
*/ onBeforeDevCompile: PluginHook<OnBeforeDevCompileFn>;
|
|
423
|
+
/**
|
|
424
|
+
* A callback function that is triggered before the Rspack Compiler instance is
|
|
425
|
+
* created. This hook is called when you
|
|
426
|
+
* run `rsbuild.startDevServer`, `rsbuild.build`, or `rsbuild.createCompiler`.
|
|
427
|
+
*/ onBeforeCreateCompiler: PluginHook<OnBeforeCreateCompilerFn>;
|
|
428
|
+
/**
|
|
429
|
+
* A callback function that is triggered before the compilation of a single environment.
|
|
430
|
+
*/ onBeforeEnvironmentCompile: PluginHook<OnBeforeEnvironmentCompileFn>;
|
|
431
|
+
/**
|
|
432
|
+
* Called before starting the dev server.
|
|
433
|
+
*/ onBeforeStartDevServer: PluginHook<OnBeforeStartDevServerFn>;
|
|
434
|
+
/**
|
|
435
|
+
* Called before starting the preview server.
|
|
436
|
+
*/ onBeforeStartPreviewServer: PluginHook<OnBeforeStartPreviewServerFn>;
|
|
437
|
+
/**
|
|
438
|
+
* Called when closing the build instance. Can be used to perform cleanup
|
|
439
|
+
* operations when the building is closed.
|
|
440
|
+
*/ onCloseBuild: PluginHook<OnCloseBuildFn>;
|
|
441
|
+
/**
|
|
442
|
+
* Called when closing the dev server. Can be used to perform cleanup
|
|
443
|
+
* operations when the dev server is closed.
|
|
444
|
+
*/ onCloseDevServer: PluginHook<OnCloseDevServerFn>;
|
|
445
|
+
/**
|
|
446
|
+
* Alias for the `onAfterDevCompile` hook.
|
|
447
|
+
* @deprecated Use `onAfterDevCompile` instead (added in v1.5.0).
|
|
448
|
+
* Both hooks have identical functionality.
|
|
449
|
+
*/ onDevCompileDone: PluginHook<OnAfterDevCompileFn>;
|
|
450
|
+
/**
|
|
451
|
+
* Called when the process is going to exit, this hook can only execute
|
|
452
|
+
* synchronous code.
|
|
453
|
+
*/ onExit: PluginHook<OnExitFn>;
|
|
454
|
+
/**
|
|
455
|
+
* Called when a restart is requested for the dev server or watch build.
|
|
456
|
+
*/ onRestart: PluginHook<OnRestartFn>;
|
|
457
|
+
/**
|
|
458
|
+
* Modify assets before emitting, the same as Rspack's
|
|
459
|
+
* [compilation.hooks.processAssets](https://rspack.rs/api/plugin-api/compilation-hooks#processassets) hook.
|
|
460
|
+
*/ processAssets: ProcessAssetsHook;
|
|
461
|
+
/**
|
|
462
|
+
* Intercept and modify module request information before module resolution begins.
|
|
463
|
+
* The same as Rspack's [normalModuleFactory.hooks.resolve](https://rspack.rs/api/plugin-api/normal-module-factory-hooks#resolve) hook.
|
|
464
|
+
*/ resolve: ResolveHook;
|
|
465
|
+
/**
|
|
466
|
+
* A simplified wrapper around Rspack loaders, `api.transform` lets you
|
|
467
|
+
* easily transform the code of specific modules during the build process.
|
|
468
|
+
* You can match files by module path, query, or other conditions, and
|
|
469
|
+
* apply custom transformations to their contents.
|
|
470
|
+
*/ transform: TransformHook;
|
|
471
|
+
/**
|
|
472
|
+
* Get the properties or methods exposed by other plugins.
|
|
473
|
+
*
|
|
474
|
+
* If the current plugin is registered in an environment, Rsbuild will
|
|
475
|
+
* first resolve the exposed API registered for the same environment,
|
|
476
|
+
* then fall back to the global exposed API.
|
|
477
|
+
*/ useExposed: <T = any>(id: string | symbol) => T | undefined;
|
|
478
|
+
}>;
|
|
479
|
+
export { };
|