vite
Installation
SKILL.md
Vite
Overview
Vite is a next-generation frontend build tool providing instant dev server startup via native ES modules and production builds bundled by Rolldown (since Vite 8; earlier versions used Rollup and esbuild). It supports React, Vue, Svelte, and vanilla TypeScript projects with advanced bundling strategies, plugin extensibility, and library mode.
Instructions
- To start a project run
npm create vite@latest(ornpm create vite@latest storefront -- --template react-ts). Vite 8 needs Node.js 20.19+ or 22.12+. - When setting up a project, create
vite.config.tswith the appropriate framework plugin (@vitejs/plugin-react,@vitejs/plugin-vue), configureresolve.aliaswith@mapping tosrc/, and set environment variables withVITE_prefix in.env,.env.localor.env.[mode]files (restart the dev server after editing them). Addvite-env.d.tswith anImportMetaEnvinterface for typed variables. - When configuring the dev server, set up API proxying with
server.proxy, enable HTTPS with@vitejs/plugin-basic-ssl, and useserver.watchpolling for containers or VMs. - When optimizing builds, split vendor code with
build.rolldownOptions.output.codeSplitting(Vite 8; the object form ofmanualChunkswas removed and the function form is deprecated; on Vite 7 and older usebuild.rollupOptions.output.manualChunks). CSS code splitting is on by default.build.targetdefaults to'baseline-widely-available'(Chrome 111, Edge 111, Firefox 114, Safari 16.4). - When creating plugins, use the Rollup-compatible plugin API with
resolveId,load, andtransformhooks, and leverage virtual modules with thevirtual:prefix. - When building libraries, configure
build.libwith entry point and output formats (es, cjs, umd), externalize peer dependencies, and usevite-plugin-dtsfor TypeScript declaration generation. Default formats areesandumdfor one entry,esandcjsfor several; AMD and SystemJS output was removed in Vite 8. - When upgrading to Vite 8: rename
build.rollupOptionstobuild.rolldownOptions, expect Oxc instead of esbuild for transforms and minification (esbuildoptions are auto-converted tooxcbut deprecated), and Lightning CSS for CSS minification. If a default import from a CommonJS package changes behavior, setlegacy.inconsistentCjsInterop: truetemporarily. - When migrating from Webpack, replace
webpack.config.jswithvite.config.ts, swap loaders for Vite plugins, and updateREACT_APP_*env vars toVITE_*. Create React App is no longer maintained, so this is the usual path off it. - When integrating testing, use Vitest, which shares the Vite config (recent Vitest versions need Node 22.12+).
A typical dev setup with an alias and an API proxy: