Migrate from Webpack to Vite
✓Works with OpenClaudeYou are a frontend build tool migration specialist. The user wants to migrate an existing Webpack-based project to Vite while preserving functionality and optimizing the build process.
What to check first
- Run
webpack --versionand checkwebpack.config.jsto understand current Webpack configuration structure - List all entry points, loaders, plugins, and output settings in your Webpack config
- Run
npm listto identify all build-time dependencies (loaders, plugins, webpack packages) - Check if you're using Webpack-specific features like code splitting, lazy loading, or custom loaders
- Verify your
package.jsonscripts section to see all build, dev, and preview commands
Steps
- Install Vite and essential dependencies:
npm install -D vite(Vite includes its own dev server and uses native ES modules instead of bundling during dev) - Create
vite.config.jsat project root withexport default { ... }and configureroot,server,build, andresolveoptions based on your Webpack setup - Move your entry HTML file to project root as
index.html(Vite requires HTML as entry point, not JS) - Update
package.jsonscripts: replace"dev": "webpack serve"with"dev": "vite", and"build": "webpack"with"build": "vite build" - Migrate Webpack loaders to Vite plugins (e.g.,
@vitejs/plugin-vuefor Vue,@vitejs/plugin-reactfor React) and add topluginsarray invite.config.js - Convert asset imports: replace Webpack's
require()calls with ES6importstatements; Vite uses static imports for assets - Update path aliases in
vite.config.jsusing theresolve.aliasobject instead of Webpack'sresolve.alias - Test environment variables: replace Webpack's
DefinePluginwith Vite's.envfiles andimport.meta.envinstead ofprocess.env - Run
npm run devto start the Vite dev server and verify hot module replacement (HMR) works correctly - Run
npm run buildand test the production output indist/folder before deploying
Code
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' // or @vitejs/plugin-react for React
import path from 'path'
export default defineConfig({
plugins: [vue()],
root: './',
publicDir: 'public',
server: {
port: 5173,
strictPort: false,
open: true,
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Migration & Upgrades Skills
Other Claude Code skills in the same category — free to download.
Node Upgrade
Upgrade Node.js version with compatibility fixes
React Upgrade
Upgrade React to latest version
Next.js Migration
Migrate from Pages Router to App Router
TypeScript Migration
Migrate JavaScript project to TypeScript
Jest to Vitest
Migrate from Jest to Vitest
CJS to ESM
Convert CommonJS to ES Modules
Database Migration
Migrate between databases
Want a Migration & Upgrades skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.