skills/catalog/frontend/vite/SKILL.md
Use for Vite config, plugins, SSR, or Vite 8/Rolldown migration. Not for Vitest testing.
npx skillsauth add erikstmartin/dotfiles viteInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Vite 6+ frontend build tool — native ESM dev server + optimized production builds.
vite.config.ts with defineConfig. Always use TypeScript + ESM.vite starts dev server with instant HMRvite build for production, vite preview to test output locallydist/, set base option for non-root paths (e.g. GitHub Pages)import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
resolve: { alias: { '@': '/src' } },
server: {
port: 3000,
proxy: { '/api': 'http://localhost:8080' },
},
build: {
target: 'esnext',
outDir: 'dist',
},
})
Use defineConfig with a function for environment-conditional config:
export default defineConfig(({ command, mode }) => ({
plugins: [react()],
define: {
__DEV__: command === 'serve',
},
}))
Glob imports — dynamically load matching modules:
const modules = import.meta.glob('./modules/*.ts')
// eager: true loads all immediately instead of lazy
const eager = import.meta.glob('./locale/*.json', { eager: true })
Asset queries — import assets with transform hints:
import url from './img.png?url' // resolves to public URL string
import raw from './shader.glsl?raw' // resolves to file contents as string
import worker from './worker.ts?worker' // wraps as Web Worker
Env variables — only VITE_-prefixed vars are exposed to client code:
// .env
VITE_API_URL=https://api.example.com
SECRET_KEY=do-not-expose // NOT accessible in client
// in source
const url = import.meta.env.VITE_API_URL
CSS Modules — auto-enabled for .module.css files:
import styles from './app.module.css'
// styles.container → scoped class name
Vite plugins extend Rollup's plugin interface with additional Vite-specific hooks:
import type { Plugin } from 'vite'
function myPlugin(): Plugin {
return {
name: 'my-plugin',
// Vite hook: runs before Rollup
configResolved(config) {
console.log('resolved base:', config.base)
},
// Rollup hook: transform source files
transform(code, id) {
if (!id.endsWith('.custom')) return
return { code: transformCustom(code), map: null }
},
}
}
Plugin ordering: enforce: 'pre' runs before framework plugins, enforce: 'post' runs after.
vite build --ssr src/entry-server.ts # build server bundle
vite build # build client bundle separately
In dev, use server.ssrLoadModule to load modules through Vite's pipeline:
const { render } = await viteDevServer.ssrLoadModule('/src/entry-server.ts')
@vitejs/plugin-vue — Vue 3 SFC support@vitejs/plugin-react — React with Babel/Oxc (Vite 8+)@vitejs/plugin-react-swc — React with SWC (faster transforms)@vitejs/plugin-legacy — transpile for older browsers with @babel/preset-envprocess.env does not work in client code — use import.meta.env insteadVITE_ prefix on env vars — they will be undefined in the browser with no warningoptimizeDeps.include so Vite pre-bundles them as ESMimport.meta.hot.accept() or have an ancestor that does; otherwise Vite does a full reload{ eager: false } (the default) add lazy dynamic imports; with eager: true they all land in the initial bundletesting
Use when creating new skills, editing existing skills, or verifying skills work before deployment
development
Use when you have a spec or requirements for a multi-step task, before touching code
data-ai
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
tools
Use when starting any conversation - establishes how to find and use skills, requiring Skill tool invocation before ANY response including clarifying questions