Vite Guide

How to set up Tamagui with Vite

Tamagui now has two plugins for Vite: one that sets up everything you need to get going, and a second that adds CSS compilation. Both are included in the @tamagui/vite-plugin package.

Install

For a full-featured example, you can create a new app using npm create tamagui@latest and select the ‘Simple Web’ option which includes a Vite setup.

Create a new Vite  project:

yarn create vite@latest

Add @tamagui/vite-plugin:

yarn add @tamagui/vite-plugin

Configuration

Update your vite.config.ts. If you have a tamagui.build.ts (recommended — see compiler install docs), no options are needed:

vite.config.ts

import react from '@vitejs/plugin-react-swc'
import { tamaguiPlugin } from '@tamagui/vite-plugin'
export default {
plugins: [
react(),
// reads from tamagui.build.ts automatically
tamaguiPlugin(),
].filter(Boolean),
}

Or pass options inline:

vite.config.ts

import react from '@vitejs/plugin-react-swc'
import { tamaguiPlugin } from '@tamagui/vite-plugin'
export default {
plugins: [
react(),
tamaguiPlugin({
config: 'src/tamagui.config.ts',
components: ['tamagui'],
disableExtraction: true,
}),
].filter(Boolean),
}

Or use a minimal manual setup for Vite that just adds compatibility for react-native-web and React Native extensions:

config.define = {
DEV: `${process.env.NODE_ENV === 'development' ? true : false}`,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}
config.resolve.alias['react-native'] = 'react-native-web'
// set up web extensions
config.optimizeDeps.esbuildOptions = {
...config.optimizeDeps.esbuildOptions,
resolveExtensions: [
'.web.js',
'.web.jsx',
'.web.ts',
'.web.tsx',
'.mjs',
'.js',
'.mts',
'.ts',
'.jsx',
'.tsx',
'.json',
],
loader: {
'.js': 'jsx',
},
}

Custom Aliases with tamaguiAliases

For advanced use cases where you need more control over alias ordering in your Vite config, you can use the tamaguiAliases helper function:

vite.config.ts

import { tamaguiAliases } from '@tamagui/vite-plugin'
export default {
resolve: {
alias: [
// your custom aliases first
{ find: '@app', replacement: '/src' },
// then tamagui aliases
...tamaguiAliases({
// use @tamagui/react-native-web-lite for smaller bundle
rnwLite: true,
// or 'without-animated' for even smaller bundle (no Animated API)
// rnwLite: 'without-animated',
// alias react-native-svg to @tamagui/react-native-svg
svg: true,
}),
],
},
}

This is useful when you need to ensure specific alias resolution order or when using a custom Vite setup without the full tamaguiPlugin.