Vite config generator — vite.config for React, Vue, Svelte or Preact

Choose your framework and dev-server settings, and the tool writes a vite.config.ts (or .js) with the right plugin, an @ alias for src, an API proxy and build options, together with the install command for the plugins it imports.

Live demo · real result from this tool

vite.config.ts

import { fileURLToPath, URL } from 'node:url';import { defineConfig } from 'vite';import react from '@vitejs/plugin-react'; // https://vite.dev/config/export default defineConfig({  plugins: [react()],  resolve: {    alias: {      '@': fileURLToPath(new URL('./src', import.meta.url)),    },  },  server: {    port: 5173,    strictPort: true,    proxy: {      '/api': { target: 'http://localhost:3000', changeOrigin: true },    },  },});

Install

npm install --save-dev vite @vitejs/plugin-react

Processed on your device — nothing is uploaded.

How to use the Vite config generator

  1. Choose the Framework: React, Vue, Svelte, Preact or Vanilla. Keep TypeScript config file ticked for vite.config.ts.
  2. Set the Dev server port (default 5173), and tick Open the browser on start or Expose on the local network if you want them.
  3. Keep @ alias for ./src to import with @/components/....
  4. Enter an API proxy as path -> target, or clear the field.
  5. Adjust Public base path, Build output folder, Production source maps and Tailwind CSS v4 plugin, then save the file in the project root and run the install command.

What it does and when to use it

npm create vite gives you a minimal config. Most projects soon need more: a fixed port, a proxy to the backend, an import alias, a sub-folder deployment or source maps for debugging production. This tool writes those settings with the correct imports, which is handy when adding Vite to an existing project or cleaning up a config copied from an older version.

Related setup files work alongside it. Use the tsconfig generator with its bundler preset for the TypeScript side, the Tailwind config generator for the CSS file the Tailwind plugin reads, and the ESLint config generator for linting.

How it works

The file imports defineConfig from Vite and the plugin for your framework: @vitejs/plugin-react, @vitejs/plugin-vue, @sveltejs/vite-plugin-svelte or @preact/preset-vite. Vanilla adds no plugin. Tailwind adds @tailwindcss/vite.

Settings that equal Vite’s defaults are left out: base when it is /, and the build block unless the output folder is not dist or source maps are on. The alias uses fileURLToPath(new URL('./src', import.meta.url)), which works in ES module configs. The proxy accepts ->, => or a space between path and target; a lone URL is proxied from /api. Option names follow the Vite config reference; the tool targets Vite 8.

Worked examples

The default React setup:

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 5173,
    strictPort: true,
    proxy: {
      '/api': { target: 'http://localhost:3000', changeOrigin: true },
    },
  },
});

Vue with Tailwind, JavaScript file. No alias or proxy: vite.config.js contains plugins: [vue(), tailwindcss()], and the install line adds tailwindcss @tailwindcss/vite.

Svelte in a sub-folder. Port 3000, network access on, base /app/, output build, source maps on. The file imports import { svelte } from '@sveltejs/vite-plugin-svelte';, sets base: '/app/', host: true, and a build block with outDir: 'build' and sourcemap: true.

Limits and tips

  • One proxy rule only. Add more entries inside proxy by hand.
  • Exposing the server on the network lets anyone on the same Wi-Fi open it; avoid it on public networks.
  • Production source maps reveal your original source to visitors unless you upload them to an error tracker and keep them off the public server.

Frequently asked questions

Why does the dev server stop instead of trying another port?
The config sets strictPort to true. If the port is busy, Vite exits with an error rather than moving to the next free port, so proxies, OAuth callbacks and bookmarks keep pointing at the right address.
What does the API proxy do?
During development, requests from your app to a path such as /api are forwarded to your backend, for example http://localhost:3000. The browser sees one origin, so you avoid CORS errors. changeOrigin rewrites the Host header to the target. The proxy does not exist in the production build.
The @ alias works in Vite but my editor shows errors. Why?
Vite resolves the alias, but TypeScript and your editor read tsconfig.json. Add a matching paths entry there, mapping @/* to ./src/*.
When do I change the public base path?
When the built site is served from a sub-folder rather than the domain root, for example GitHub Pages at /my-repo/. Enter the folder with slashes on both ends.
Why is react itself missing from the install command?
The command installs only build tooling as dev dependencies. Install the framework, such as react and react-dom, vue, svelte or preact, as normal dependencies if your project does not have them yet.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close