# Migrate a Webpack 5 Project to Vite

Yes. An agent replaces the three webpack configs with one Vite config, keeps Sass and PostCSS working, and diffs the old and new build output in a PR.

[Run this on Rush](https://cloud.getrush.ai/run/migrate-webpack-to-vite/webpack/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the build before it replaces it. In a project like wbkd/webpack-starter there are three files under `webpack/`: `webpack.common.js` sets the entry `src/scripts/index.js`, the output folder `build`, an alias from `~` to `src`, an asset rule, and plugins that clean the folder, copy `public` and render `src/index.html`; the dev and prod configs merge into it with `webpack-merge`. `package.json` runs them as `webpack serve` and, for production, `cross-env NODE_ENV=production webpack`. Around them sit `.babelrc` with `useBuiltIns: usage`, a `.browserslistrc` with a production and a development section, `postcss.config.js` with `postcss-preset-env`, and `node-sass` for the one SCSS file.

Vite turns that inside out, and the agent makes each difference explicit. Vite's entry is the HTML file, and `src/index.html` has no script tag because `HtmlWebpackPlugin` injected one. Without a tag, `vite build` succeeds and emits an HTML file with no JavaScript or CSS at all, so the agent adds `<script type="module" src="./scripts/index.js">` first. It writes one config with `root: 'src'`, `publicDir: '../public'`, the same alias, and `build.outDir: '../build'` with `emptyOutDir: true`, because Vite will not empty an output folder outside its root unless told to. It names the file `vite.config.mjs`: this package has no `"type": "module"`, and Vite 8 warns about ESM syntax in a config loaded as CommonJS.

Styles need two decisions. Vite compiles SCSS only with `sass` or `sass-embedded` installed and does not use `node-sass`, so the agent swaps that dependency, which also removes a native module that node-sass 8 does not support on Node 20 or later. PostCSS keeps working: Vite finds `postcss.config.js` in the parent of its root, and `postcss-preset-env` still adds the prefixes the browserslist asks for. But Vite's CSS minifier then removes the prefixes its own default target does not need. For a rule such as `display: flex` or `user-select: none`, webpack's CSS keeps `display: -ms-flexbox` and `-moz-user-select` and Vite's minified CSS drops them. This project's own `index.scss` sets only a colour and a font, so the gap stays hidden until such a rule is added. The agent sets `build.cssTarget` from the browserslist, builds a probe rule both ways, and lists any prefix that still differs so the team can decide if those browsers matter.

It then compares the two output folders, because paths are what break deploys. Webpack writes `js/app.<hash>.js` and `css/app.<hash>.css`, references them with relative URLs, and copies `public` into `build/public`. Vite writes both files under `assets/`, references them from the site root unless `base` is set, and copies the contents of `public` to the top of `build`. The agent keeps Vite's `assets/` layout, sets `base: './'` to keep relative URLs, and states the `public` move plainly. Finally it removes the webpack packages and loaders, keeps `@babel/core` and `@babel/eslint-parser` because `.eslintrc` still parses with them, rewrites the `start` and `build` scripts, and serves the result with `vite preview` to load it in the sandbox's browser.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Migrate this project's build from webpack 5 to Vite and open a pull request. Read package.json, the three files under webpack/, .babelrc, .browserslistrc, postcss.config.js, .eslintrc, .stylelintrc.json, .travis.yml, src/index.html, src/scripts/index.js and src/styles/index.scss first. Before changing anything, get a production build from the existing webpack setup and keep a listing of build/ and a copy of its CSS; if npm ci fails on the sandbox's Node, say why and make the smallest change that lets the old build run. Then add Vite with one config file: keep src/index.html where it is, keep build/ as the output folder, keep the ~ alias, and keep public/ as the static folder. Add the module script tag index.html needs. Replace node-sass with sass. Keep postcss.config.js and check it is still applied. Build with Vite and compare with the webpack build: every file path, how index.html references its script and stylesheet, where files from public/ end up, and the CSS vendor prefixes. Explain each difference and fix the ones that can be fixed in config. Say what replaces the Babel polyfills from .babelrc and whether the browserslist needs them. Say what happens to the ESLint and Stylelint checks that ran inside the webpack dev server. Remove the webpack configs and every dependency nothing uses any more, keep the ones the lint scripts need, update the start and build scripts, and update .travis.yml and the README. Serve the build with vite preview, open it in the browser and attach a screenshot.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request deletes the `webpack/` folder, adds `vite.config.mjs`, edits `src/index.html`, `package.json` and its lockfile, and updates the README's commands. The description's first table is the dependency list: what was removed with the webpack configs, what was added, and what stayed for linting. Its second table puts the two builds side by side, one row per output file, with the old and new path and how `index.html` refers to each.

Under the tables are the differences a reader has to accept or reject. Files from `public` move from `build/public/` to the top of `build/`. CSS prefixes are listed as a diff between the two stylesheets, with the `cssTarget` the agent chose. Babel is no longer part of the build, so the polyfills that `useBuiltIns: usage` injected are gone; the description says that `@vitejs/plugin-legacy` is the way to get them back and leaves it out unless the browserslist needs it. The ESLint and Stylelint plugins that ran inside `webpack serve` are gone too, while `npm run lint` still works.

A reviewer starts with the server that hosts `build/`. Any rule that matches `js/` or `css/` paths, or a cache header keyed on them, has to follow the files to `assets/`. Then the browser list: the old production target included Firefox ESR and excluded only Internet Explorer below 11, and whether that still describes real visitors decides the `cssTarget` and the legacy plugin. The screenshot from `vite preview` shows the page rendering with its heading and the slate blue text from `index.scss`, which confirms the stylesheet is linked and compiled.

## Run it on every repository still on webpack

A migration is usually done once per repository, and a team with several front ends does them together. Send one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`. Each run reads its own configs, so a project with several entry points or a custom loader gets a config that fits it. A key runs up to its `max_concurrent` runs at once and the rest wait as `queued`, so the whole batch can be sent in one loop. Send a `request_id`, a fresh UUID per repository, so a retried request returns the run it already started.

The work does not have to end with the first pull request. The sandbox parks with its disk when the turn ends, and a follow-up with `POST …/sessions/{id}/messages` wakes it with both builds still on disk. That is the moment to say that the old `js/` and `css/` paths must be kept after all, or that the legacy plugin should go in, and have the agent rebuild and compare again without starting from an empty machine.

## Why run it on Rush?

A bundler migration is judged by its output, and the output only exists after both builds have run. In a Rush sandbox the agent produces the webpack build and the Vite build on the same machine from the same commit, lists both folders, diffs the stylesheets and loads the result in a real browser. Every command and both listings stay in the run's record, so the tables in the pull request are copies of what was on disk and not a description from memory.

The quiet failures are the reason to do it this way. A Vite build of this project with no script tag in the HTML exits zero and ships a page with no code, and a build with the script tag silently changes which browsers get prefixed CSS. Neither shows up as an error on a laptop. An agent that is told to compare the two outputs finds both, and the comparison costs nobody an afternoon.

## Frequently asked questions

### Does Vite read my .browserslistrc?

Not for its own output. PostCSS plugins such as `postcss-preset-env` still read it when Vite runs your `postcss.config.js`, but Vite's JavaScript target and its CSS minifier use `build.target` and `build.cssTarget`. The agent sets those from the browserslist and shows what changes in the built CSS.

### Will my build output paths change?

By default, yes. Vite puts hashed files in `assets/` and copies `public` to the root of the output folder, where this webpack config used `js/`, `css/` and `build/public/`. The pull request lists every path before and after, and the file names can be configured back if a deploy depends on them.

### Do I have to give up node-sass?

Yes. Vite's SCSS support requires the `sass` or `sass-embedded` package. A file like this project's `index.scss`, which uses one variable, compiles without changes. For larger stylesheets the agent reports every deprecation warning Dart Sass prints.

### What happens to Babel and my polyfills?

Vite does not run Babel, so `.babelrc` stops affecting the build and the `core-js` imports that `useBuiltIns: usage` added disappear. If the browsers you support need them, `@vitejs/plugin-legacy` adds a legacy bundle with polyfills. The agent keeps the Babel packages that ESLint's parser needs and removes the rest.

## More webpack jobs

- [Fix "BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default"](https://getrush.ai/run/fix-webpack-5-node-polyfill-errors/webpack/)
- [Migrate from node-sass to Dart Sass in a Webpack Project](https://getrush.ai/run/migrate-node-sass-to-dart-sass/webpack/)

## The same job on other stacks

- [Migrate a Chrome Extension from Webpack to Vite](https://getrush.ai/run/migrate-webpack-to-vite/chrome-extension/)

## More jobs like this: Hand off a long task

- [Migrate a Yarn 4 Project to pnpm, Lockfile and Patches Included](https://getrush.ai/run/migrate-yarn-to-pnpm/yarn/)
- [Move Yii2 Users From a Hardcoded Array to a Database Table](https://getrush.ai/run/move-users-to-database/yii/)
- [Persist Chat History in a Streamlit App](https://getrush.ai/run/persist-chat-history/streamlit/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
