> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Vite

This guide explains how to migrate a Vite project to Rsbuild.

## Installing dependencies

First, replace Vite's npm dependencies with Rsbuild's equivalents.

- Remove Vite dependencies:


```sh [npm]
npm remove vite
```

```sh [yarn]
yarn remove vite
```

```sh [pnpm]
pnpm remove vite
```

```sh [bun]
bun remove vite
```

```sh [deno]
deno remove npm:vite
```

- Install Rsbuild dependencies:


```sh [npm]
npm add @rsbuild/core -D
```

```sh [yarn]
yarn add @rsbuild/core -D
```

```sh [pnpm]
pnpm add @rsbuild/core -D
```

```sh [bun]
bun add @rsbuild/core -D
```

```sh [deno]
deno add npm:@rsbuild/core -D
```

## Test tooling

Vitest uses Vite to transform and run tests, so retain Vite and any Vite plugins referenced by `vitest.config.*` while you use Vitest. To remove Vite from the test toolchain, you can migrate to [Rstest](https://rstest.rs/), which reuses your Rsbuild configuration through `@rstest/adapter-rsbuild`. See the [Testing](/guide/advanced/testing.md) guide and the [Rstest migration guide](https://rstest.rs/guide/migration/vitest) for the required configuration and test API changes.

Remove Vite only after confirming that no other development tool or dependency still requires it.

## TanStack Start

TanStack Start manages client and server entries, deployment output, and framework-specific plugins. Follow the dedicated [TanStack Start migration guide](/guide/migration/tanstack-start.md) instead of the generic build entry steps below.

## Updating npm scripts

Next, update the npm scripts in your package.json to run Rsbuild CLI commands.

```json title="package.json"
{
  "scripts": {
    "dev": "vite", // [!code --]
    "build": "vite build", // [!code --]
    "preview": "vite preview", // [!code --]
    "dev": "rsbuild", // [!code ++]
    "build": "rsbuild build", // [!code ++]
    "preview": "rsbuild preview" // [!code ++]
  }
}
```

## Create configuration file

Create an Rsbuild configuration file named `rsbuild.config.ts` alongside package.json, and add the following content:

```ts title="rsbuild.config.ts"
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
  plugins: [],
});
```

## Build entry

The default build entry points for Rsbuild and Vite are different. Vite uses `index.html` as the default entry, while Rsbuild auto-detects a `src/index.*` module such as `src/index.ts` or `src/index.js`.

When migrating from Vite to Rsbuild, use Rsbuild's [source.entry](/config/source/entry.md) to set the build entry and [html.template](/config/html/template.md) to set the template.

Using a newly created Vite project as an example, first delete the `<script>` tags from `index.html`:

```html title="index.html"
<!-- [!code --] -->
<script type="module" src="/src/main.ts"></script>
```

Then add the following configuration:

```ts title="rsbuild.config.ts"
export default {
  html: {
    template: './index.html',
  },
  source: {
    entry: {
      index: './src/main.ts',
    },
  },
};
```

Rsbuild automatically injects the `<script>` tags into the generated HTML files during the build.

## Migrating plugins

Most common Vite plugins can be easily migrated to Rsbuild plugins, such as:

| Vite                                                                                       | Rsbuild                                                                                           |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
| [@vitejs/plugin-react](https://npmjs.com/package/@vitejs/plugin-react)                     | [@rsbuild/plugin-react](/plugins/list/plugin-react.md)                                            |
| [@vitejs/plugin-react-swc](https://npmjs.com/package/@vitejs/plugin-react-swc)             | [@rsbuild/plugin-react](/plugins/list/plugin-react.md)                                            |
| [@tailwindcss/vite](https://npmjs.com/package/@tailwindcss/vite)                           | [@rsbuild/plugin-tailwindcss](/plugins/list/plugin-tailwindcss.md)                                |
| [@vitejs/plugin-vue](https://npmjs.com/package/@vitejs/plugin-vue)                         | [@rsbuild/plugin-vue](/plugins/list/plugin-vue.md)                                                |
| [@vitejs/plugin-vue2](https://npmjs.com/package/@vitejs/plugin-vue2)                       | [@rsbuild/plugin-vue2](https://github.com/rstackjs/rsbuild-plugin-vue2)                           |
| [@vitejs/plugin-vue-jsx](https://npmjs.com/package/@vitejs/plugin-vue-jsx)                 | [@rsbuild/plugin-vue-jsx](https://github.com/rstackjs/rsbuild-plugin-vue-jsx)                     |
| [@vitejs/plugin-vue2-jsx](https://npmjs.com/package/@vitejs/plugin-vue2-jsx)               | [@rsbuild/plugin-vue2-jsx](https://github.com/rstackjs/rsbuild-plugin-vue2-jsx)                   |
| [@vitejs/plugin-basic-ssl](https://npmjs.com/package/@vitejs/plugin-basic-ssl)             | [@rsbuild/plugin-basic-ssl](https://github.com/rstackjs/rsbuild-plugin-basic-ssl)                 |
| [@vitejs/plugin-legacy](https://npmjs.com/package/@vitejs/plugin-legacy)                   | No need to use, see [Browser compatibility](/guide/advanced/browser-compatibility.md) for details |
| [@sveltejs/vite-plugin-svelte](https://npmjs.com/package/@sveltejs/vite-plugin-svelte)     | [@rsbuild/plugin-svelte](/plugins/list/plugin-svelte.md)                                          |
| [vite-plugin-svgr](https://npmjs.com/package/vite-plugin-svgr)                             | [@rsbuild/plugin-svgr](/plugins/list/plugin-svgr.md)                                              |
| [vite-plugin-checker](https://npmjs.com/package/vite-plugin-checker)                       | [@rsbuild/plugin-type-check](https://github.com/rstackjs/rsbuild-plugin-type-check)               |
| [vite-plugin-eslint](https://npmjs.com/package/vite-plugin-eslint)                         | [@rsbuild/plugin-eslint](https://github.com/rstackjs/rsbuild-plugin-eslint)                       |
| [vite-plugin-static-copy](https://npmjs.com/package/vite-plugin-static-copy)               | [output.copy](/config/output/copy.md)                                                             |
| [vite-plugin-node-polyfills](https://npmjs.com/package/vite-plugin-node-polyfills)         | [@rsbuild/plugin-node-polyfill](https://github.com/rstackjs/rsbuild-plugin-node-polyfill)         |
| [vite-plugin-solid](https://npmjs.com/package/vite-plugin-solid)                           | [@rsbuild/plugin-solid](/plugins/list/plugin-solid.md)                                            |
| [@preact/preset-vite](https://npmjs.com/package/@preact/preset-vite)                       | [@rsbuild/plugin-preact](/plugins/list/plugin-preact.md)                                          |
| [@tanstack/router-plugin/vite](https://npmjs.com/package/@tanstack/router-plugin)          | [@tanstack/router-plugin/rsbuild](https://npmjs.com/package/@tanstack/router-plugin)              |
| [@sentry/vite-plugin](https://npmjs.com/package/@sentry/vite-plugin)                       | [@sentry/webpack-plugin](https://npmjs.com/package/@sentry/webpack-plugin)                        |
| [vite-plugin-full-reload](https://npmjs.com/package/vite-plugin-full-reload)               | [dev.watchFiles](/config/dev/watch-files.md)                                                      |
| [vite-plugin-html](https://npmjs.com/package/vite-plugin-html)                             | [html.template](/config/html/template.md)                                                         |
| [vite-plugin-css-injected-by-js](https://npmjs.com/package/vite-plugin-css-injected-by-js) | [output.injectStyles](/config/output/inject-styles.md)                                            |

> Refer to [Plugin list](/plugins/list/index.md) to learn more about available plugins.

## Config migration

Here is the corresponding Rsbuild configuration for each Vite option:

| Vite                                   | Rsbuild                                                                                                 |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| root                                   | [root](/config/root.md)                                                                                 |
| mode                                   | [mode](/config/mode.md)                                                                                 |
| base                                   | [server.base](/config/server/base.md)                                                                   |
| define                                 | [source.define](/config/source/define.md)                                                               |
| plugins                                | [plugins](/config/plugins.md)                                                                           |
| appType                                | [server.historyApiFallback](/config/server/history-api-fallback.md)                                     |
| envDir                                 | [Env directory](/guide/advanced/env-vars.md#env-directory)                                              |
| logLevel                               | [logLevel](/config/log-level.md)                                                                        |
| cacheDir                               | [buildCache](/config/performance/build-cache.md)                                                        |
| publicDir                              | [server.publicDir](/config/server/public-dir.md)                                                        |
| customLogger                           | [customLogger](/config/custom-logger.md)                                                                |
| assetsInclude                          | [source.assetsInclude](/config/source/assets-include.md)                                                |
| resolve.alias                          | [resolve.alias](/config/resolve/alias.md)                                                               |
| resolve.dedupe                         | [resolve.dedupe](/config/resolve/dedupe.md)                                                             |
| resolve.extensions                     | [resolve.extensions](/config/resolve/extensions.md)                                                     |
| resolve.conditions                     | [resolve.conditionNames](/config/resolve/condition-names.md)                                            |
| resolve.mainFields                     | [resolve.mainFields](/config/resolve/main-fields.md)                                                    |
| resolve.preserveSymlinks               | [tools.rspack.resolve.symlinks](/config/tools/rspack.md)                                                |
| html.cspNonce                          | [security.nonce](/config/security/nonce.md)                                                             |
| css.modules                            | [output.cssModules](/config/output/css-modules.md)                                                      |
| css.postcss                            | [tools.postcss](/config/tools/postcss.md)                                                               |
| css.preprocessorOptions.sass           | [pluginSass](/plugins/list/plugin-sass.md)                                                              |
| css.preprocessorOptions.less           | [pluginLess](/plugins/list/plugin-less.md)                                                              |
| css.preprocessorOptions.stylus         | [pluginStylus](https://github.com/rstackjs/rsbuild-plugin-stylus)                                       |
| css.devSourcemap                       | [output.sourceMap](/config/output/source-map.md)                                                        |
| css.lightningcss                       | [tools.lightningcssLoader](/config/tools/lightningcss-loader.md)                                        |
| server.host, preview\.host             | [server.host](/config/server/host.md)                                                                   |
| server.port, preview\.port             | [server.port](/config/server/port.md)                                                                   |
| server.cors, preview\.cors             | [server.cors](/config/server/cors.md)                                                                   |
| server.strictPort, preview\.strictPort | [server.strictPort](/config/server/strict-port.md)                                                      |
| server.https, preview\.https           | [server.https](/config/server/https.md)                                                                 |
| server.open, preview\.open             | [server.open](/config/server/open.md)                                                                   |
| server.proxy, preview\.proxy           | [server.proxy](/config/server/proxy.md)                                                                 |
| server.headers, preview\.headers       | [server.headers](/config/server/headers.md)                                                             |
| server.hmr                             | [dev.hmr](/config/dev/hmr.md), [dev.client](/config/dev/client.md)                                      |
| server.middlewareMode                  | [server.middlewareMode](/config/server/middleware-mode.md)                                              |
| build.target, build.cssTarget          | [Browserslist](/guide/advanced/browserslist.md)                                                         |
| build.outDir, build.assetsDir          | [output.distPath](/config/output/dist-path.md)                                                          |
| build.assetsInlineLimit                | [output.dataUriLimit](/config/output/data-uri-limit.md)                                                 |
| build.cssMinify                        | [output.minify](/config/output/minify.md)                                                               |
| build.sourcemap                        | [output.sourceMap](/config/output/source-map.md)                                                        |
| build.lib                              | Use [Rslib](https://github.com/web-infra-dev/rslib)                                                     |
| build.manifest                         | [output.manifest](/config/output/manifest.md)                                                           |
| build.ssrEmitAssets                    | [output.emitAssets](/config/output/emit-assets.md)                                                      |
| build.minify, build.terserOptions      | [output.minify](/config/output/minify.md)                                                               |
| build.emptyOutDir                      | [output.cleanDistPath](/config/output/clean-dist-path.md)                                               |
| build.copyPublicDir                    | [server.publicDir](/config/server/public-dir.md)                                                        |
| build.reportCompressedSize             | [performance.printFileSize](/config/performance/print-file-size.md)                                     |
| ssr.external                           | [output.autoExternal](/config/output/auto-external.md), [output.externals](/config/output/externals.md) |
| ssr.noExternal                         | [output.autoExternal.exclude](/config/output/auto-external.md#exclude)                                  |
| ssr, worker                            | [environments](/config/environments.md)                                                                 |

Notes:

- The table above doesn't cover every Vite option; feel free to add more.

## Server port

Vite's dev server uses port `5173` by default, while Rsbuild uses port `3000` by default. If your project depends on `5173`, you can keep Vite's original port with the following configuration:

```ts title="rsbuild.config.ts"
export default {
  server: {
    port: 5173,
  },
};
```

## Environment variables

Vite injects environment variables starting with `VITE_` into the client code by default, while Rsbuild injects environment variables starting with `PUBLIC_` by default (see [public variables](/guide/advanced/env-vars.md#public-variables)). Rename client variables in `.env` files, deployment configuration, and application code:

```diff
- VITE_API_URL
+ PUBLIC_API_URL
```

Rsbuild injects the following [environment variables](/guide/advanced/env-vars.md) by default:

- `import.meta.env.MODE`
- `import.meta.env.BASE_URL`
- `import.meta.env.PROD`
- `import.meta.env.DEV`
- `import.meta.env.SSR`

## Preset types

Vite provides some preset type definitions through `vite/client`. When migrating to Rsbuild, replace it with the [preset types](/guide/basic/typescript.md#preset-types) provided by `@rsbuild/core`:

```json title="tsconfig.json"
{
  "compilerOptions": {
    "types": ["vite/client"], // [!code --]
    "types": ["@rsbuild/core/types"] // [!code ++]
  }
}
```

## Web Workers

When migrating worker query imports from Vite, Rsbuild supports `?worker` and `?worker&inline`:

```ts
import Worker from './worker.ts?worker';
import InlineWorker from './worker.ts?worker&inline';
```

Rsbuild does not support Vite's `?worker&url` query suffix. If you use it to create a dedicated worker, migrate to the standard `new Worker()` constructor syntax instead:

```ts
const worker = new Worker(new URL('./worker.ts', import.meta.url), {
  type: 'module',
});
```

Rsbuild also does not support Vite's `?sharedworker`, `?sharedworker&inline`, or `?sharedworker&url` query suffixes. To preserve shared worker behavior, use the standard `new SharedWorker()` constructor syntax instead:

```ts
const sharedWorker = new SharedWorker(new URL('./worker.ts', import.meta.url), {
  type: 'module',
});
```

The constructor syntax also lets you pass standard `WorkerOptions` or `SharedWorkerOptions`, such as `name`, `type`, and `credentials`. See [Web Workers](/guide/basic/web-workers.md) for more details.

## Glob import

Rsbuild >= 2.0.8 is compatible with [import.meta.glob()](https://rspack.rs/api/runtime-api/module-variables#importmetaglob), so you can keep the Vite code unchanged when migrating to Rsbuild.

## vite-tsconfig-paths

Rsbuild supports TypeScript's `paths` option as alias out of the box, so you can remove the `vite-tsconfig-paths` dependency directly.

See [Path aliases](/guide/advanced/alias.md) for more details.

## Migrating Vite plugins

See [Vite plugin](/guide/migration/vite-plugin.md) to learn how to migrate Vite plugins.

## Validating results

After completing the steps above, the basic migration from Vite to Rsbuild is complete. You can now run the `npm run dev` command to try starting the dev server.

If you encounter issues during the build process, debug using the error log, or check the Vite configuration for any settings that haven't been migrated to Rsbuild.

## Contents supplement

This document covers only part of the migration process. If you have content to add, feel free to contribute via a pull request 🤝.

> The documentation for rsbuild can be found in the [rsbuild/website](https://github.com/web-infra-dev/rsbuild/tree/main/website) directory.
