This is Vite 1.x – 6.x LEGACY documentation archive / 这是 Vite 1.x – 6.x 旧版文档归档
- These pages correspond to old plugin releases: vite-plugin-view ≤ 4.x, vite-plugin-external ≤ 7.x, vite-plugin-build-chunk ≤ 4.x, etc.
- Bundler covered: Rollup + esbuild (the default Vite 6 and below stack). This does NOT apply to Vite 8+ with the new Rolldown bundler; Vite 7/8+ users, go to the current docs immediately.
- Content under this folder is frozen and unmaintained. For any new option / field, check the current docs:
- Latest English docs: /guide/introduction
- 最新中文文档:/zh/guide/introduction
配置项 (legacy)
ts
export type TransformFile = (buf: Buffer, matchedPath: string) => string | Buffer | Promise<string | Buffer>;
export interface Target {
/**
* Path or glob of what to copy.
*
* 要复制的目录、文件或者 `globby` 匹配规则。
*/
src: string | string[];
/**
* One or more destinations where to copy.
*
* 复制到目标目录。
*/
dest: string;
/**
* Rename the file after copying.
*
* 复制后重命名文件。
*/
rename?: string | ((name: string) => string);
/**
* Remove the directory structure of copied files, if `src` is a directory.
*
* 是否删除复制的文件目录结构,`src` 为目录时有效。
*/
flatten?: boolean;
/**
* Options for tinyglobby. See more at https://github.com/sindresorhus/globby#options
*
* tinyglobby 的选项,设置 `src` 的匹配参数
*/
globOptions?: GlobOptions;
/**
* Options for fs-extra.copy See more at https://github.com/jprichardson/node-fs-extra/blob/HEAD/docs/copy.md
*
* fs-extra.copy 的选项,设置 `src` 的复制参数
*/
copyOptions?: CopyOptions;
/**
* Transform the file before copying.
*
* 复制前转换文件内容。
*/
transform?: TransformFile;
}
export interface Options {
/**
* Default `'closeBundle'`, vite hook the plugin should use.
*
* 默认 `'closeBundle'`,调用指定钩子函数时开始复制。
*
* @default 'closeBundle'
*/
hook?: string;
/**
* The value of enforce can be either `"pre"` or `"post"`, see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering.
*
* 强制执行顺序,`pre` 前,`post` 后,参考 https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering
*/
enforce?: 'pre' | 'post';
/**
* Options for tinyglobby. See more at https://github.com/SuperchupuDev/tinyglobby?tab=readme-ov-file#options
*
* tinyglobby 的选项,设置 `src` 的匹配参数。
*/
globOptions?: GlobOptions;
/**
* Options for fs-extra.copy See more at https://github.com/jprichardson/node-fs-extra/blob/HEAD/docs/copy.md
*
* fs-extra.copy 的选项,设置 `src` 的复制参数
*/
copyOptions?: CopyOptions;
/**
* Default `process.cwd()`, The current working directory in which to search.
*
* 默认 `process.cwd()`,用于拼接 `src` 的路径。
*
* @default `process.cwd()`
*/
cwd?: string;
/**
* Array of targets to copy.
*
* 复制文件的规则配置。
*/
targets: Target[];
/**
* Default `'warn'`, The log level to use.
*
* 默认 `'warn'`,日志等级。
*
* @default 'WARN'
*/
logLevel?: LogLevel;
/**
* Delay in milliseconds before copying.
*
* 复制前的延迟时间。
*/
delay?: number;
/**
* Whether to output the banner
*
* 是否输出 banner
*/
enableBanner?: boolean;
}