Build Options

build.base

  • Type: string

  • Default: /

    Base public path when served in production. Note the path should start and end with /. See Public Base Path for more details.

build.target

  • Type: string

  • Default: 'modules'

  • Related: Browser Compatibility

    Browser compatibility target for the final bundle. The default value is a Vite special value, 'modules', which targets browsers with native ES module support.

    Another special value is ‘esnext’ - which only performs minimal trasnpiling (for minification compat) and assumes native dynamic imports support.

    The transform is performed with esbuild and the value should be a valid esbuild target option. Custom targets can either be a ES version (e.g. es2015), a browser with version (e.g. chrome58), or an array of multiple target strings.

    Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See esbuid docs for more details.

build.polyfillDynamicImport

  • Type: boolean

  • Default: true unless build.target is 'esnext'

    Whether to automatically inject dynamic import polyfill.

    The polyfill is auto injected into the proxy module of each index.html entry. If the build is configured to use a non-html custom entry via build.rollupOptions.input, then it is necessary to manually import the polyfill in your custom entry:

    1. import 'vite/dynamic-import-polyfill'

    Note: the polyfill does not apply to Library Mode. If you need to support browsers without native dynamic import, you should probably avoid using it in your library.

build.outDir

  • Type: string

  • Default: dist

    Specify the output directory (relative to project root).

build.assetsDir

  • Type: string

  • Default: assets

    Specify the directory to nest generated assets under (relative to build.outDir).

build.assetsInlineLimit

  • Type: number

  • Default: 4096 (4kb)

    Imported or referenced assets that are smaller than this threshold will be inlined as base64 URLs to avoid extra http requests. Set to 0 to disable inlining altogether.

build.cssCodeSplit

  • Type: boolean

  • Default: true

    Enable/disable CSS code splitting. When enabled, CSS imported in async chunks will be inlined into the async chunk itself and inserted when the chunk is loaded.

    If disabled, all CSS in the entire project will be extracted into a single CSS file.

build.sourcemap

  • Type: boolean

  • Default: false

    Generate production source maps.

build.rollupOptions

  • Type: RollupOptions

    Directly customize the underlying Rollup bundle. This is the same as options that can be exported from a Rollup config file and will be merged with Vite’s internal Rollup options. See Rollup options docs for more details.

build.commonjsOptions

build.lib

  • Type: { entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[] }

  • Related: Library Mode

    Build as a library. entry is required since the library cannot use HTML as entry. name is the exposed global variable and is required when formats includes 'umd' or 'iife'. Default formats are ['es', 'umd'].

build.manifest

  • Type: boolean

  • Default: false

  • Related: Backend Integration

    When set to true, the build will also generate a manifest.json file that contains mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links.

build.minify

  • Type: boolean | 'terser' | 'esbuild'

  • Default: 'terser'

    Set to false to disable minification, or specify the minifier to use. The default is Terser which is slower but produces smaller bundles in most cases. Esbuild minification is significantly faster, but will result in slightly larger bundles.

build.terserOptions

build.cleanCssOptions

  • Type: CleanCSS.Options

    Constructor options to pass on to clean-css.

build.write

  • Type: boolean

  • Default: true

    Set to false to disable writing the bundle to disk. This is mostly used in programmatic build() calls where further post processing of the bundle is needed before writing to disk.

build.emptyOutDir

  • Type: boolean

  • Default: true if outDir is inside root

    By default, Vite will empty the outDir on build if it is inside project root. It will emit a warning if outDir is outside of root to avoid accidentially removing important files. You can explicitly set this option to suppress the warning. This is also available via command line as --emptyOutDir.