Skip to content

Configuration Options ​

Type definitions copied verbatim from the plugin TypeScript source:

ts
import type { LibraryFormats, PluginOption } from 'vite';
import { LibraryOptions, UserConfig } from 'vite';

type ViteBuildOptions = NonNullable<UserConfig['build']>;
type BaseBuildOptions = Exclude<ViteBuildOptions, 'rollupOptions' | 'rolldownOptions' | 'lib'>;
type OutputOptions = NonNullable<NonNullable<ViteBuildOptions['rolldownOptions']>['output']>;
type SingleOutputOptions = Exclude<OutputOptions, OutputOptions[]>;

export interface BuildOptions extends BaseBuildOptions, LibraryOptions {
  logLevel?: UserConfig['logLevel'];
  output?: OutputOptions;
  /**
   * Deprecated legacy entry option.
   *
   * A relative value is resolved against the **main build's `outDir`** (legacy
   * behaviour), so it is not equivalent to `entry`, whose relative value resolves
   * against the project root.
   *
   * @deprecated Use `entry` instead and convert the path to be project-root relative.
   */
  chunk?: string;
  /**
   * The chunk name.
   *
   * 构建的 chunk 名称。
   */
  entry: NonNullable<LibraryOptions['entry']>;
  /**
   * The output format.
   *
   * 输出格式。
   */
  format?: LibraryFormats;
  /**
   * The exports type.
   *
   * 导出类型。
   */
  exports?: SingleOutputOptions['exports'];
  /**
   * @deprecated
   */
  plugins?: PluginOption[];

  /**
   * @deprecated
   */
  resolve?: UserConfig['resolve'];
}

export interface Options {
  /**
   * The plugins to use.
   *
   * 使用的插件。
   */
  plugins?: PluginOption[];

  /**
   * The resolve options.
   *
   * 解析选项。
   */
  resolve?: UserConfig['resolve'];
  /**
   * The build options.
   *
   * 构建选项。
   */
  build: BuildOptions | BuildOptions[];
}

Core Configuration Interfaces ​

Options (Top-level Configuration Object) ​

ParameterTypeRequiredDefault ValueDescription
buildBuildOptions[] | BuildOptionsYes-Configuration for build tasks (array or single object).
pluginsPluginOption[]No[]Additional Vite plugins applied to every secondary build.
resolveUserConfig['resolve']No-resolve config passed through to every secondary build.

BuildOptions (Configuration for Each Build Task) ​

BuildOptions extends Vite's build options (minus rollupOptions / rolldownOptions / lib) and Vite's build.lib options, so fields such as sourcemap, minify, formats, cssFileName and emptyOutDir are also accepted. The most commonly used ones are listed below.

ParameterTypeRequiredDefault ValueDescription
entryNonNullable<LibraryOptions['entry']>Yes-The file to re-bundle (usually an artifact inside the main build's outDir). A relative value is resolved against the project root; an absolute path is used as-is.
chunkstringNo-Deprecated; keeps the legacy behaviour only: a relative value is resolved against the main build's outDir. It is not equivalent to entry — a relative entry resolves against the project root, so convert the path when migrating.
namestringNo-Global variable name; required when the output format is UMD or IIFE.
format'es' | 'cjs' | 'umd' | 'iife'No'umd'Build format (defaults to umd). Ignored when formats is provided.
sourcemapboolean | 'inline' | 'hidden'NofalseWhether to generate sourcemaps (supports inline or hidden modes).
exports'default' | 'named' | 'none' | 'auto'No'auto'Export type for the Rolldown output.
minifyboolean | 'terser' | 'esbuild'NofalseWhether to enable output minification (supports terser or esbuild).
outDirstringNoMain build's outDirSecondary build's output directory (relative to project root). Note: a relative entry resolves against the project root, not this value; only the deprecated chunk is resolved against the main build's outDir.
fileNamestring | ((format: LibraryFormats, entryName: string) => string)NoVite default namingOutput file name. When unset, Vite derives it from the package.json name (not the entry file name), so rebundling my-lib.js does NOT yield my-lib.*; set fileName explicitly to control the name. A function form returns the exact filename without extra extensions.
pluginsPluginOption[]No-Deprecated at this level; use the top-level Options.plugins.
resolveUserConfig['resolve']No-Deprecated at this level; use the top-level Options.resolve.

TypeScript Definitions ​

typescript
import type { LibraryFormats, PluginOption } from 'vite';
import { LibraryOptions, UserConfig } from 'vite';

type ViteBuildOptions = NonNullable<UserConfig['build']>;
type BaseBuildOptions = Exclude<ViteBuildOptions, 'rollupOptions' | 'rolldownOptions' | 'lib'>;
type OutputOptions = NonNullable<NonNullable<ViteBuildOptions['rolldownOptions']>['output']>;
type SingleOutputOptions = Exclude<OutputOptions, OutputOptions[]>;

export interface BuildOptions extends BaseBuildOptions, LibraryOptions {
  logLevel?: UserConfig['logLevel'];
  output?: OutputOptions;
  /**
   * Deprecated legacy entry option.
   *
   * A relative value is resolved against the **main build's `outDir`** (legacy
   * behaviour), so it is not equivalent to `entry`, whose relative value resolves
   * against the project root.
   *
   * @deprecated Use `entry` instead and convert the path to be project-root relative.
   */
  chunk?: string;
  /**
   * The chunk name.
   */
  entry: NonNullable<LibraryOptions['entry']>;
  /**
   * The output format.
   */
  format?: LibraryFormats;
  /**
   * The exports type.
   */
  exports?: SingleOutputOptions['exports'];
  /**
   * @deprecated
   */
  plugins?: PluginOption[];

  /**
   * @deprecated
   */
  resolve?: UserConfig['resolve'];
}

export interface Options {
  /**
   * The plugins to use.
   */
  plugins?: PluginOption[];

  /**
   * The resolve options.
   */
  resolve?: UserConfig['resolve'];
  /**
   * The build options.
   */
  build: BuildOptions | BuildOptions[];
}