简体中文
配置项
Type definitions copied verbatim from the plugin TypeScript source:
ts
export interface BuildOptions {
/**
* The chunk name.
*
* 构建的 chunk 名称。
*/
chunk: string;
/**
* Global variable name.
*
* 全局变量名。
*/
name: string;
/**
* The output format.
*
* 输出格式。
*/
format?: LibraryFormats;
/**
* Whether to generate sourcemaps.
*
* 是否生成 sourcemap。
*/
sourcemap?: boolean | 'inline' | 'hidden';
/**
* The exports type.
*
* 导出类型。
*/
exports?: 'default' | 'named' | 'none' | 'auto';
/**
* Whether to minify the output.
*
* 是否压缩输出。
*/
minify?: boolean | 'terser' | 'esbuild';
/**
* The output directory.
*
* 输出目录。
*/
outDir?: string;
/**
* The output file name.
*
* 输出文件名。
*/
fileName?: string | ((format: LibraryFormats, entryName: string) => string);
/**
* The plugins to use.
*
* 使用的插件。
*/
plugins?: PluginOption[];
/**
* The resolve options.
*
* 解析选项。
*/
resolve?: UserConfig['resolve'];
}
export interface Options {
/**
* The build options.
*
* 构建选项。
*/
build: BuildOptions | BuildOptions[];
}核心配置接口
Options(顶层配置对象)
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
build | BuildOptions[] | BuildOptions | 是 | - | 构建任务配置(数组或单个对象) |
BuildOptions(每个构建任务的配置)
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
chunk | string | 是 | - | 主构建输出目录(outDir)内的文件名 |
name | string | 是 | - | 全局变量名(仅在 UMD/IIFE 格式生效) |
format | 'es' | 'cjs' | 'umd' | 'iife' | 否 | 'umd' | 构建格式(默认 umd) |
sourcemap | boolean | 'inline' | 'hidden' | 否 | false | 是否生成 sourcemap(支持内联或隐藏模式) |
exports | 'default' | 'named' | 'none' | 'auto' | 否 | 'auto' | Rollup 输出的导出类型 |
minify | boolean | 'terser' | 'esbuild' | 否 | false | 是否启用代码压缩(支持 terser 或 esbuild) |
outDir | string | 否 | 主构建的 outDir | 自定义输出目录(相对项目根目录) |
fileName | string | ((format: LibraryFormats, entryName: string) => string) | 否 | 根据格式生成默认名称 | 自定义文件名(支持模板字符串或函数) |
plugins | PluginOption[] | 否 | [] | 额外的 Vite 插件列表 |
resolve | UserConfig['resolve'] | 否 | - | 透传给二次构建的 resolve 解析配置 |
TypeScript 定义
typescript
import type { LibraryFormats, PluginOption, UserConfig } from 'vite';
export interface BuildOptions {
/**
* The chunk name.
*
* 构建的 chunk 名称。
*/
chunk: string;
/**
* Global variable name.
*
* 全局变量名。
*/
name: string;
/**
* The output format.
*
* 输出格式。
*/
format?: LibraryFormats;
/**
* Whether to generate sourcemaps.
*
* 是否生成 sourcemap。
*/
sourcemap?: boolean | 'inline' | 'hidden';
/**
* The exports type.
*
* 导出类型。
*/
exports?: 'default' | 'named' | 'none' | 'auto';
/**
* Whether to minify the output.
*
* 是否压缩输出。
*/
minify?: boolean | 'terser' | 'esbuild';
/**
* The output directory.
*
* 输出目录。
*/
outDir?: string;
/**
* The output file name.
*
* 输出文件名。
*/
fileName?: string | ((format: LibraryFormats, entryName: string) => string);
/**
* The plugins to use.
*
* 使用的插件。
*/
plugins?: PluginOption[];
/**
* The resolve options.
*
* 解析选项。
*/
resolve?: UserConfig['resolve'];
}
export interface Options {
/**
* The build options.
*
* 构建选项。
*/
build: BuildOptions | BuildOptions[];
}