Vite
Overview
Vite is a next-generation frontend build tool providing instant dev server startup via native ES modules and optimized Rollup-based production builds. It supports React, Vue, Svelte, and vanilla TypeScript projects with advanced bundling strategies, plugin extensibility, and library mode.
Instructions
- When setting up a project, create
vite.config.ts with the appropriate framework plugin (@vitejs/plugin-react, @vitejs/plugin-vue), configure resolve.alias with @ mapping to src/, and set environment variables with VITE_ prefix.
- When configuring the dev server, set up API proxying with
server.proxy, enable HTTPS with @vitejs/plugin-basic-ssl, and use server.watch polling for containers or VMs.
- When optimizing builds, configure manual chunks with
build.rollupOptions.output.manualChunks for vendor splitting, enable CSS code splitting, and set build.target for browser compatibility.
- When creating plugins, use the Rollup-compatible plugin API with
resolveId, load, and transform hooks, and leverage virtual modules with the virtual: prefix.
- When building libraries, configure
build.lib with entry point and output formats (es, cjs, umd), externalize peer dependencies, and use vite-plugin-dts for TypeScript declaration generation.
- When migrating from Webpack, replace
webpack.config.js with vite.config.ts, swap loaders for Vite plugins, and update REACT_APP_* env vars to VITE_*.
- When integrating testing, use Vitest which shares Vite config and provides instant HMR for tests.
Examples
Example 1: Migrate a Create React App project to Vite
User request: "Convert my CRA project to use Vite instead"
Actions:
- Install Vite and
@vitejs/plugin-react, remove react-scripts
- Create
vite.config.ts with React plugin and path aliases
- Rename
REACT_APP_* environment variables to VITE_*
- Update
index.html to reference the entry module directly
Output: A Vite-powered React project with faster dev startup and HMR.
Example 2: Configure optimized production build
User request: "Set up Vite build with vendor chunk splitting and source maps for Sentry"
Actions:
- Configure
build.rollupOptions.output.manualChunks to separate vendor libraries
- Enable
build.sourcemap for error monitoring integration
- Set
build.target appropriate to browser support requirements
- Add
build.assetsInlineLimit tuning for small asset optimization
Output: An optimized production build configuration with proper chunk splitting and debugging support.
Guidelines
- Always use
import.meta.env.VITE_* for client-exposed env vars, never process.env.
- Configure
resolve.alias with @ prefix mapping to src/ for clean imports.
- Split vendor chunks manually when default chunking produces too many small files.
- Use
build.target: "esnext" for modern-only apps, @vitejs/plugin-legacy for legacy browser support.
- Enable
build.sourcemap in production for error monitoring tools.
- Keep
vite.config.ts clean by extracting complex plugin configs into separate files.
- Use
optimizeDeps.include to pre-bundle problematic dependencies that break during dev.
1---2name: vite3description: >-4 Assists with configuring and using Vite as a frontend build tool for modern web applications.5 Use when setting up dev servers, optimizing production builds, configuring plugins, migrating6 from Webpack or CRA, or building component libraries. Trigger words: vite, build tool, HMR,7 hot module replacement, vite config, rollup, bundling.8license: Apache-2.09compatibility: "Requires Node.js 16+"10metadata:11 source: https://skillmd.com/skills/eliferjunior/vite12 author: terminal-skills13 version: "1.0.0"14 category: development15 tags: ["vite", "build-tool", "bundler", "frontend", "hmr"]16---1718# Vite1920## Overview2122Vite is a next-generation frontend build tool providing instant dev server startup via native ES modules and optimized Rollup-based production builds. It supports React, Vue, Svelte, and vanilla TypeScript projects with advanced bundling strategies, plugin extensibility, and library mode.2324## Instructions2526- When setting up a project, create `vite.config.ts` with the appropriate framework plugin (`@vitejs/plugin-react`, `@vitejs/plugin-vue`), configure `resolve.alias` with `@` mapping to `src/`, and set environment variables with `VITE_` prefix.27- When configuring the dev server, set up API proxying with `server.proxy`, enable HTTPS with `@vitejs/plugin-basic-ssl`, and use `server.watch` polling for containers or VMs.28- When optimizing builds, configure manual chunks with `build.rollupOptions.output.manualChunks` for vendor splitting, enable CSS code splitting, and set `build.target` for browser compatibility.29- When creating plugins, use the Rollup-compatible plugin API with `resolveId`, `load`, and `transform` hooks, and leverage virtual modules with the `virtual:` prefix.30- When building libraries, configure `build.lib` with entry point and output formats (es, cjs, umd), externalize peer dependencies, and use `vite-plugin-dts` for TypeScript declaration generation.31- When migrating from Webpack, replace `webpack.config.js` with `vite.config.ts`, swap loaders for Vite plugins, and update `REACT_APP_*` env vars to `VITE_*`.32- When integrating testing, use Vitest which shares Vite config and provides instant HMR for tests.3334## Examples3536### Example 1: Migrate a Create React App project to Vite3738**User request:** "Convert my CRA project to use Vite instead"3940**Actions:**411. Install Vite and `@vitejs/plugin-react`, remove react-scripts422. Create `vite.config.ts` with React plugin and path aliases433. Rename `REACT_APP_*` environment variables to `VITE_*`444. Update `index.html` to reference the entry module directly4546**Output:** A Vite-powered React project with faster dev startup and HMR.4748### Example 2: Configure optimized production build4950**User request:** "Set up Vite build with vendor chunk splitting and source maps for Sentry"5152**Actions:**531. Configure `build.rollupOptions.output.manualChunks` to separate vendor libraries542. Enable `build.sourcemap` for error monitoring integration553. Set `build.target` appropriate to browser support requirements564. Add `build.assetsInlineLimit` tuning for small asset optimization5758**Output:** An optimized production build configuration with proper chunk splitting and debugging support.5960## Guidelines6162- Always use `import.meta.env.VITE_*` for client-exposed env vars, never `process.env`.63- Configure `resolve.alias` with `@` prefix mapping to `src/` for clean imports.64- Split vendor chunks manually when default chunking produces too many small files.65- Use `build.target: "esnext"` for modern-only apps, `@vitejs/plugin-legacy` for legacy browser support.66- Enable `build.sourcemap` in production for error monitoring tools.67- Keep `vite.config.ts` clean by extracting complex plugin configs into separate files.68- Use `optimizeDeps.include` to pre-bundle problematic dependencies that break during dev.