Core plugins are Vite's built-in plugins that handle essential transformations and processing during both development and build. These plugins implement fundamental features such as module resolution, CSS processing, HTML transformation, asset handling, and import analysis. They are automatically included in every Vite project and execute in a specific order as part of the plugin pipeline.
For information about the plugin API and hook system that core plugins use, see Plugin API and Hooks. For guidance on writing custom plugins, see Creating Custom Plugins.
Core plugins are organized into execution tiers. User plugins can position themselves relative to core plugins using the enforce option. In Vite 8, many core transformation tasks are offloaded to native implementations in Rolldown/Oxc for performance.
Sources: packages/vite/src/node/plugins/importAnalysis.ts:80-81(), packages/vite/src/node/plugins/worker.ts:187-210()
These plugins handle module resolution and aliasing, translating import specifiers to file paths.
| Plugin | Purpose | Key Files |
|---|---|---|
preAliasPlugin | Early alias resolution for optimized dependencies | packages/vite/src/node/plugins/preAlias.ts1-142 |
resolvePlugin | Main module resolver for bare imports, relative paths, and URLs | packages/vite/src/node/plugins/resolve.ts168-953 |
Sources: packages/vite/src/node/plugins/importAnalysis.ts:77-80()
Transform plugins process source code, converting between formats and applying optimizations. Vite 8 defaults to oxc for JS/TS/JSX transformations when bundled.
| Plugin | Purpose | Implementation |
|---|---|---|
oxcPlugin | Fast TS/JSX transformation via Oxc | packages/vite/src/node/plugins/oxc.ts210-245 |
jsonPlugin | Loads JSON files as ES modules | packages/vite/src/node/plugins/json.ts1-68 |
wasmPlugin | Handles .wasm file imports | packages/vite/src/node/plugins/wasm.ts1-124 |
cssPlugin | Processes CSS, preprocessors, and PostCSS | packages/vite/src/node/plugins/css.ts295-452 |
definePlugin | Replaces global constants (e.g. process.env.NODE_ENV) | packages/vite/src/node/plugins/define.ts12-165 |
importGlobPlugin | Handles import.meta.glob patterns | packages/vite/src/node/plugins/importMetaGlob.ts37-127 |
Sources: packages/vite/src/node/plugins/oxc.ts:210-245(), packages/vite/src/node/plugins/css.ts:1-294(), packages/vite/src/node/plugins/define.ts:12-165(), packages/vite/src/node/plugins/importMetaGlob.ts:44-55()
These plugins manage static assets and web workers.
| Plugin | Purpose | Features |
|---|---|---|
assetPlugin | Handles static asset imports with hashing and inlining | packages/vite/src/node/plugins/asset.ts152-163 |
webWorkerPlugin | Bundles web workers separately | packages/vite/src/node/plugins/worker.ts162-230 |
htmlInlineProxyPlugin | Proxies inline scripts and styles in HTML | packages/vite/src/node/plugins/html.ts103-137 |
Sources: packages/vite/src/node/plugins/asset.ts:152-225(), packages/vite/src/node/plugins/worker.ts:154-160(), packages/vite/src/node/plugins/html.ts:103-137()
The resolve plugin implements Vite's module resolution algorithm. It is responsible for mapping browser-friendly specifiers to actual file system paths.
Resolution Logic:
/@fs/ prefixes for absolute paths.exports and imports fields) for bare module specifiers.Sources: packages/vite/src/node/plugins/importAnalysis.ts:108-145()
Vite provides first-class support for CSS, including preprocessors and CSS Modules.
cssPlugin Implementation Details:
WorkerWithFallback to avoid blocking the main thread packages/vite/src/node/plugins/css.ts25-36postcss (default) or lightningcss (experimental) packages/vite/src/node/plugins/css.ts123-124url() and @import references in CSS, converting them to asset URLs or inlined data URLs.Sources: packages/vite/src/node/plugins/css.ts:114-165(), packages/vite/src/node/plugins/css.ts:214-225()
The assetPlugin manages static assets like images, fonts, and raw text files.
Key Functions:
assetsInlineLimit are converted to Base64 data URLs packages/vite/src/node/plugins/asset.ts34-37import code from './file.txt?raw' packages/vite/src/node/plugins/asset.ts204-214Sources: packages/vite/src/node/plugins/asset.ts:148-225()
Vite treats index.html as a first-class entry point.
HTML Proxying:
Inline <script> tags in HTML are extracted into virtual modules. For example, a script in index.html becomes a request to index.html?html-proxy&index=0.js packages/vite/src/node/plugins/html.ts59-61 This allows the standard transform pipeline (TS, JSX, etc.) to apply to inline code.
HTML Traversal:
The traverseHtml function uses parse5 to walk the HTML AST and identify src, href, and srcset attributes that need resolution packages/vite/src/node/plugins/html.ts202-223
Sources: packages/vite/src/node/plugins/html.ts:103-137(), packages/vite/src/node/plugins/html.ts:202-223(), packages/vite/src/node/server/middlewares/indexHtml.ts:68-107()
These plugins analyze and rewrite import statements.
Development Import Analysis:
import.meta.hot API packages/vite/src/node/plugins/importAnalysis.ts225-230ModuleGraph.Build Import Analysis:
__vitePreload for preloading async chunks packages/vite/src/node/plugins/importAnalysisBuild.ts30-31preload helper function manages the browser-side logic for preloading dependencies via <link rel="modulepreload"> packages/vite/src/node/plugins/importAnalysisBuild.ts62-163Sources: packages/vite/src/node/plugins/importAnalysis.ts:196-223(), packages/vite/src/node/plugins/importAnalysisBuild.ts:5-163()
Handles the new Worker(new URL('./worker.js', import.meta.url)) pattern.
Worker Bundling:
The bundleWorkerEntry function creates a separate Rolldown build for the worker entry point packages/vite/src/node/plugins/worker.ts162-211 This ensures workers have their own dependency graph and can be emitted as separate chunks or inlined.
Sources: packages/vite/src/node/plugins/worker.ts:162-211()
The following diagram bridges the natural language description of a module request to the specific code entities involved.
Sources: packages/vite/src/node/plugins/oxc.ts:120-199(), packages/vite/src/node/plugins/importAnalysis.ts:225-360()
Many core plugins share state or use specific caches to optimize performance.
| Cache Entity | Role | Source |
|---|---|---|
htmlProxyMap | Stores code for inline HTML scripts | packages/vite/src/node/plugins/html.ts87-96 |
assetCache | Caches resolved asset URLs | packages/vite/src/node/plugins/asset.ts54 |
WorkerOutputCache | Prevents redundant worker bundling | packages/vite/src/node/plugins/worker.ts46-150 |
patternsCache | Caches regex patterns for define replacements | packages/vite/src/node/plugins/define.ts103-106 |
Sources: packages/vite/src/node/plugins/html.ts:87-152(), packages/vite/src/node/plugins/worker.ts:46-150(), packages/vite/src/node/plugins/css.ts:214-225()
Refresh this wiki