网页 综合 更新时间 2026-11-13 15:38:37

Build Options | Vite

自动蜘蛛 vite.dev 正文约 6000 字
Build Options | Vite
Dep Optimization Options
Unless noted, the options in this section are only applied to build.
Browser compatibility target for the final bundle. The default value is a Vite special value, 'baseline-widely-available', which targets the minimum browser versions compatible with Baseline Widely Available as of a date fixed for each major release (2026-01-01 for this major). Specifically, it is ['chrome111', 'edge111', 'firefox114', 'safari16.4', 'ios16.4'].
Another special value is 'esnext' - which assumes native dynamic imports support and will only perform minimal transpiling.
The transform is performed with Oxc Transformer and the value should be a valid Oxc Transformer target option. Custom targets can either be an ES version (e.g. es2015), a browser with version (e.g. chrome58), or an array of multiple target strings.
Note the build will output a warning if the code contains features that cannot be safely transpiled by Oxc. See Oxc docs for more details.
By default, a module preload polyfill is automatically injected. 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.rolldownOptions.input, then it is necessary to manually import the polyfill in your custom entry:
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.
The polyfill can be disabled using { polyfill: false }.
The list of chunks to preload for each dynamic import is computed by Vite. By default, an absolute path including the base will be used when loading these dependencies. If the base is relative ('' or './'), import.meta.url is used at runtime to avoid absolute paths that depend on the final deployed base.
There is experimental support for fine grained control over the dependencies list and their paths using the resolveDependencies function. Give Feedback. It expects a function of type ResolveModulePreloadDependenciesFn:
The resolveDependencies function will be called for each dynamic import with a list of the chunks it depends on, and it will also be called for each chunk imported in entry HTML files. A new dependencies array can be returned with these filtered or more dependencies injected, and their paths modified. The deps paths are relative to the build.outDir. The return value should be a relative path to the build.outDir.
The resolved dependency paths can be further modified using experimental.renderBuiltUrl.
Whether to automatically inject a module preload polyfill.
Specify the output directory (relative to project root).
Specify the directory to nest generated assets under (relative to build.outDir). This is not used in Library Mode.
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.
If a callback is passed, a boolean can be returned to opt-in or opt-out. If nothing is returned the default logic applies.
Git LFS placeholders are automatically excluded from inlining because they do not contain the content of the file they represent.
If you specify build.lib, build.assetsInlineLimit will be ignored and assets will always be inlined, regardless of file size or being a Git LFS placeholder.
Enable/disable CSS code splitting. When enabled, CSS imported in async JS chunks will be preserved as chunks and fetched together when the chunk is fetched.
If disabled, all CSS in the entire project will be extracted into a single CSS file.
If you specify build.lib, build.cssCodeSplit will be false as default.
This option allows users to set a different browser target for CSS minification from the one used for JavaScript transpilation.
When build.cssMinify is 'lightningcss' (the default), this option takes precedence over css.lightningcss.targets for the minification step.
It should only be used when you are targeting a non-mainstream browser. One example is Android WeChat WebView, which supports most modern JavaScript features but not the #RGBA hexadecimal color notation in CSS. In this case, you need to set build.cssTarget to chrome61 to prevent Vite from transforming rgba() colors into #RGBA hexadecimal notations.
This option allows users to override CSS minification specifically instead of defaulting to build.minify, so you can configure minification for JS and CSS separately. Vite uses Lightning CSS by default to minify CSS. It can be configured using css.lightningcss. Set the option to 'esbuild' to use esbuild instead.
esbuild must be installed when it is set to 'esbuild'.
Generate production source maps. If true, a separate sourcemap file will be created. If 'inline', the sourcemap will be appended to the resulting output file as a data URI. 'hidden' works like true except that the corresponding sourcemap comments in the bundled files are suppressed.
Whether to use import maps feature to optimize chunk caching efficiency.
Note that this option requires import.meta.resolve support. If you need to support older browsers, check out @vitejs/plugin-legacy.
Directly customize the underlying Rolldown bundle. This is the same as options that can be exported from a Rolldown config file and will be merged with Vite's internal Rolldown options. See Rolldown options docs for more details.
Vite overrides Rolldown's default for preserveEntrySignatures. When this option is not set, Vite uses false for regular client builds, 'strict' for library builds, and 'allow-extension' for SSR builds.
Instead of build.rolldownOptions.input, it is recommended to set the top-level input option, because it will be used in dev as well. If build.rolldownOptions.input is set, it overrides the top-level input option for build only.
This option is an alias of build.rolldownOptions option. Use build.rolldownOptions option instead.
Whether to transform dynamic imports with variables.
Build as a library. entry defaults to the top-level input
访问原文 返回搜索 https://vite.dev/config/build-options
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。