import type { CopyRspackPluginOptions, Externals, SwcJsMinimizerRspackPluginOptions } from '@rspack/core'; import type { CSSLoaderModulesOptions, HTMLPluginOptions } from '../../types'; import type { RsbuildTarget } from '../rsbuild'; import type { Rspack, RspackConfig } from '../rspack'; export type DistPathConfig = { /** * The root directory of all files. * @default 'dist' **/ root?: string; /** * The output directory of JavaScript files. * @default 'static/js' */ js?: string; /** * The output directory of async JavaScript files. * @default 'static/js/async' */ jsAsync?: string; /** * The output directory of CSS files. * @default 'static/css' */ css?: string; /** * The output directory of async CSS files. * @default 'static/css/async' */ cssAsync?: string; /** * The output directory of SVG images. * @default 'static/svg' */ svg?: string; /** * The output directory of font files. * @default 'static/font' */ font?: string; /** * The output directory of HTML files. * @default '/' */ html?: string; /** * The output directory of Wasm files. * @default 'static/wasm' */ wasm?: string; /** * The output directory of non-SVG images. * @default 'static/image' */ image?: string; /** * The output directory of media resources, such as videos. * @default 'static/media' */ media?: string; /** * The output directory of server bundles when target is `node`. * @default 'server' */ server?: string; /** * The output directory of service worker bundles when target is `service-worker`. * @default 'worker' */ worker?: string; }; export type FilenameConfig = { /** * The name of the JavaScript files. * @default * - dev: '[name].js' * - prod: '[name].[contenthash:8].js' */ js?: NonNullable['filename']; /** * The name of the CSS files. * @default * - dev: '[name].css' * - prod: '[name].[contenthash:8].css' */ css?: string; /** * The name of the SVG images. * @default '[name].[contenthash:8].svg' */ svg?: string; /** * The name of the font files. * @default '[name].[contenthash:8][ext]' */ font?: string; /** * The name of non-SVG images. * @default '[name].[contenthash:8][ext]' */ image?: string; /** * The name of media assets, such as video. * @default '[name].[contenthash:8][ext]' */ media?: string; }; export type DataUriLimit = { /** The data URI limit of the SVG image. */ svg?: number; /** The data URI limit of the font file. */ font?: number; /** The data URI limit of non-SVG images. */ image?: number; /** The data URI limit of media resources such as videos. */ media?: number; }; export type Charset = 'ascii' | 'utf8'; export type LegalComments = 'none' | 'inline' | 'linked'; export type NormalizedDataUriLimit = Required; export type Polyfill = 'usage' | 'entry' | 'off'; export type SourceMap = { js?: RspackConfig['devtool']; css?: boolean; }; export type CSSModulesLocalsConvention = 'asIs' | 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'; export type CSSModules = { /** * Allows CSS Modules to be automatically enabled based on their filenames. */ auto?: CSSLoaderModulesOptions['auto']; /** * Allows exporting names from global class names, so you can use them via import. */ exportGlobals?: boolean; /** * Style of exported class names. */ exportLocalsConvention?: CSSModulesLocalsConvention; /** * Set the local ident name of CSS Modules. */ localIdentName?: string; /** * Controls the level of compilation applied to the input styles. */ mode?: CSSLoaderModulesOptions['mode']; /** * Whether to enable ES modules named export for locals. */ namedExport?: boolean; }; export type Minify = boolean | { /** * Whether to enable JavaScript minification. */ js?: boolean; /** * Minimizer options of JavaScript, which will be passed to swc. */ jsOptions?: SwcJsMinimizerRspackPluginOptions; /** * Whether to enable CSS minimization. */ css?: boolean; /** * Whether to enable HTML minimization. */ html?: boolean; /** * Minimizer options of HTML, which will be passed to html-rspack-plugin. */ htmlOptions?: HTMLPluginOptions['minify']; }; export type CopyPluginOptions = CopyRspackPluginOptions; export type InlineChunkTestFunction = (params: { size: number; name: string; }) => boolean; export type InlineChunkTest = RegExp | InlineChunkTestFunction; export type EmitAssets = (params: { target: RsbuildTarget; }) => boolean; export interface OutputConfig { /** * Specify build targets to run in different target environments. */ targets?: RsbuildTarget[]; /** * At build time, prevent some `import` dependencies from being packed into bundles in your code, and instead fetch them externally at runtime. * For more information, please see: [Rspack Externals](https://rspack.dev/config/externals) */ externals?: Externals; /** * Set the directory of the dist files. * Rsbuild will output files to the corresponding subdirectory according to the file type. */ distPath?: DistPathConfig; /** * Sets the filename of dist files. */ filename?: FilenameConfig; /** * By default, Rsbuild's output is ASCII-only and will escape all non-ASCII characters. * If you want to output the original characters without using escape sequences, * you can set `output.charset` to `utf8`. */ charset?: Charset; /** * Configure how the polyfill is injected. */ polyfill?: Polyfill; /** * When using CDN in the production, * you can use this option to set the URL prefix of static assets, * similar to the output.publicPath config of webpack. */ assetPrefix?: string; /** * Set the size threshold to inline static assets such as images and fonts. * By default, static assets will be Base64 encoded and inline into the page if the size is less than 4KiB. */ dataUriLimit?: number | DataUriLimit; /** * Configure how to handle the legal comment. * A "legal comment" is considered to be any statement-level comment in JS or rule-level * comment in CSS that contains @license or @preserve or that starts with //! or /\*!. * These comments are preserved in output files by default since that follows the intent * of the original authors of the code. */ legalComments?: LegalComments; /** * Whether to clean all files in the dist path before starting compilation. */ cleanDistPath?: boolean; /** * Allow to custom CSS Modules options. */ cssModules?: CSSModules; /** * Whether to disable code minification in production build. */ minify?: Minify; /** * Whether to generate manifest file. */ manifest?: string | boolean; /** * Whether to generate source map files, and which format of source map to generate */ sourceMap?: SourceMap; /** * Whether to add filename hash after production build. */ filenameHash?: boolean | string; /** * Whether to inline output scripts files (.js files) into HTML with `