Skip to content

这是 Vite 1.x – 6.x 旧版文档归档 / This is Vite 1.x – 6.x legacy archive

  • 本文档对应插件版本:vite-plugin-view ≤ 4.x、vite-plugin-external ≤ 7.x、vite-plugin-build-chunk ≤ 4.x 等旧发行版
  • 适用打包器:Rollup / esbuild(Vite 6 及之前的默认组合)。不支持 Vite 8+ 的 Rolldown 打包器,Vite 7/8+ 用户请立即返回新文档。
  • 本目录内容已冻结,不再维护。遇到新功能/新字段请查看最新文档:

配置项(旧版)

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: ModuleFormat, entryName: string) => string);
  /**
   * The plugins to use.
   *
   * 使用的插件。
   */
  plugins?: PluginOption[];
}

export interface Options {
  /**
   * The build options.
   *
   * 构建选项。
   */
  build: BuildOptions | BuildOptions[];

  /**
   * The log level to use.
   *
   * 日志等级。
   */
  logLevel?: LogLevel;

  /**
   * Whether to output the banner
   *
   * 是否输出 banner
   */
  enableBanner?: boolean;
}

核心配置接口

Options(顶层配置对象)

参数类型必填默认值说明
buildBuildOptions[] | BuildOptions-构建任务配置(数组或单个对象)
logLevelLogLevel (来自 vp-runtime-helper)'info'日志等级(如 'error', 'warn', 'info'
enableBannerbooleanfalse是否输出构建 banner(如版本信息)

BuildOptions(每个构建任务的配置)

参数类型必填默认值说明
chunkstring-入口文件路径(相对项目根目录)
namestring'default'全局变量名(仅在 UMD/IIFE 格式生效)
format'es' | 'cjs' | 'umd' | 'iife''umd'构建格式(默认 umd
sourcemapboolean | 'inline' | 'hidden'false是否生成 sourcemap(支持内联或隐藏模式)
exports'default' | 'named' | 'none' | 'auto''auto'Rollup 输出的导出类型
minifyboolean | 'terser' | 'esbuild'false是否启用代码压缩(支持 terseresbuild
outDirstring主构建的 outDir自定义输出目录(相对项目根目录)
fileNamestring | ((format: string, entryName: string) => string)根据格式生成默认名称自定义文件名(支持模板字符串或函数)
pluginsPluginOption[][]额外的 Vite 插件列表

TypeScript 定义

typescript
import { ModuleFormat } from 'rollup';
import type { LibraryFormats, PluginOption } from 'vite';
import { LogLevel } from 'vp-runtime-helper';

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: ModuleFormat, entryName: string) => string);
  /**
   * The plugins to use.
   *
   * 使用的插件。
   */
  plugins?: PluginOption[];
}

export interface Options {
  /**
   * The build options.
   *
   * 构建选项。
   */
  build: BuildOptions | BuildOptions[];

  /**
   * The log level to use.
   *
   * 日志等级。
   */
  logLevel?: LogLevel;

  /**
   * Whether to output the banner
   *
   * 是否输出 banner
   */
  enableBanner?: boolean;
}