网页
综合
更新时间 2026-11-13 17:17:53
JavaScript API | Vite
自动蜘蛛
vite.dev
正文约 4298 字
Dependency Pre-Bundling
Static Asset Handling
Building for Production
Deploying a Static Site
Env Variables and Modes
Server-Side Rendering (SSR)
Environment Instances
Vite's JavaScript APIs are fully typed, and it's recommended to use TypeScript or enable JS type checking in VS Code to leverage the IntelliSense and validation.
When using createServer and build in the same Node.js process, both functions rely on process.env.NODE_ENV to work properly, which also depends on the mode config option. To prevent conflicting behavior, set process.env.NODE_ENV or the mode of the two APIs to development. Otherwise, you can spawn a child process to run the APIs separately.
When using middleware mode combined with proxy config for WebSocket, the parent http server should be provided in middlewareMode to bind the proxy correctly.
The InlineConfig interface extends UserConfig with additional properties:
The ResolvedConfig interface has all the same properties of a UserConfig, except most properties are resolved and non-undefined. It also contains utilities like:
waitForRequestsIdle is meant to be used as an escape hatch to improve DX for features that can't be implemented following the on-demand nature of the Vite dev server. It can be used during startup by tools like Tailwind to delay generating the app CSS classes until the app code has been seen, avoiding flashes of style changes. When this function is used in a load or transform hook, and the default HTTP1 server is used, one of the six http channels will be blocked until the server processes all static imports. Vite's dependency optimizer currently uses this function to avoid full-page reloads on missing dependencies by delaying loading of pre-bundled dependencies until all imported dependencies have been collected from static imported sources. Vite may switch to a different strategy in a future major release, setting optimizeDeps.holdUntilCrawlEnd: false by default to avoid the performance hit in large applications during cold start.
The command value is serve in dev and preview, and build in build.
Deeply merge two Vite configs. isRoot represents the level within the Vite config which is being merged. For example, set false if you're merging two build options.
Note that null and undefined values in overrides are skipped and not merged. If you need to explicitly clear a value from defaults, modify the result of mergeConfig directly.
mergeConfig accepts only config in object form. If you have a config in callback form, you should call it before passing into mergeConfig.
You can use the defineConfig helper to merge a config in callback form with another config:
Related: server.fs.allow
Search for the root of the potential workspace if it meets the following conditions, otherwise it would fallback to root:
Load .env files within the envDir and merge them with the matching variables already present in process.env. By default, only env variables prefixed with VITE_ are loaded, unless prefixes is changed.
Related: Path Normalization
Normalizes a path to interoperate between Vite plugins.
Transform JavaScript or TypeScript with Oxc Transformer. Useful for plugins that prefer matching Vite's internal Oxc Transformer transform.
Deprecated: Use transformWithOxc instead.
Transform JavaScript or TypeScript with esbuild. Useful for plugins that prefer matching Vite's internal esbuild transform.
Load a Vite config file manually with Rolldown.
Pre-processes .css, .scss, .sass, .less, .styl and .stylus files to plain CSS so it can be used in browsers or parsed by other tools. Similar to the built-in CSS pre-processing support, the corresponding pre-processor must be installed if used.
The pre-processor used is inferred from the filename extension. If the filename ends with .module.{ext}, it is inferred as a CSS module and the returned result will include a modules object mapping the original class names to the transformed ones.
Note that pre-processing will not resolve URLs in url() or image-set().
The current version of Vite as a string (e.g. "8.0.0").
The version of Rolldown used by Vite as a string (e.g. "1.0.0"). A re-export of VERSION from rolldown.
Only kept for backward compatibility.
Only kept for backward compatibility.
© 2019-present VoidZero Inc. and Vite contributors. (5def9360)
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。