interface DepOptimizationConfig {
    disabled?: boolean | "build" | "dev";
    esbuildOptions?: Omit<BuildOptions, "write" | "external" | "watch" | "bundle" | "entryPoints" | "outdir" | "outfile" | "outbase" | "outExtension" | "metafile">;
    exclude?: string[];
    extensions?: string[];
    holdUntilCrawlEnd?: boolean;
    include?: string[];
    needsInterop?: string[];
    noDiscovery?: boolean;
}

Properties

disabled?: boolean | "build" | "dev"

Deps optimization during build was removed in Vite 5.1. This option is now redundant and will be removed in a future version. Switch to using optimizeDeps.noDiscovery and an empty or undefined optimizeDeps.include. true or 'dev' disables the optimizer, false or 'build' leaves it enabled.

Default

'build'

Deprecated

esbuildOptions?: Omit<BuildOptions, "write" | "external" | "watch" | "bundle" | "entryPoints" | "outdir" | "outfile" | "outbase" | "outExtension" | "metafile">

Options to pass to esbuild during the dep scanning and optimization

Certain options are omitted since changing them would not be compatible with Vite's dep optimization.

  • external is also omitted, use Vite's optimizeDeps.exclude option
  • plugins are merged with Vite's dep plugin

https://esbuild.github.io/api

exclude?: string[]

Do not optimize these dependencies (must be resolvable import paths, cannot be globs).

extensions?: string[]

List of file extensions that can be optimized. A corresponding esbuild plugin must exist to handle the specific extension.

By default, Vite can optimize .mjs, .js, .ts, and .mts files. This option allows specifying additional extensions.

holdUntilCrawlEnd?: boolean

When enabled, it will hold the first optimized deps results until all static imports are crawled on cold start. This avoids the need for full-page reloads when new dependencies are discovered and they trigger the generation of new common chunks. If all dependencies are found by the scanner plus the explicitely defined ones in include, it is better to disable this option to let the browser process more requests in parallel.

Default

true
@experimental
include?: string[]

Force optimize listed dependencies (must be resolvable import paths, cannot be globs).

needsInterop?: string[]

Forces ESM interop when importing these dependencies. Some legacy packages advertise themselves as ESM but use require internally

noDiscovery?: boolean

Automatic dependency discovery. When noDiscovery is true, only dependencies listed in include will be optimized. The scanner isn't run for cold start in this case. CJS-only dependencies must be present in include during dev.

Default

false
@experimental