code/tamagui.dev/data/docs/guides/vite.mdx
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.
Create a new Vite project:
npm create vite@latest
Add @tamagui/vite-plugin:
yarn add @tamagui/vite-plugin
Update your vite.config.ts. If you have a tamagui.build.ts (recommended —
see compiler install docs),
no options are needed:
import { tamaguiPlugin } from '@tamagui/vite-plugin'
export default {
plugins: [
// reads from tamagui.build.ts automatically
tamaguiPlugin(),
].filter(Boolean),
}
Or pass options inline:
import { tamaguiPlugin } from '@tamagui/vite-plugin'
export default {
plugins: [
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',
},
}
For advanced use cases where you need more control over alias ordering in your Vite config, you can use the tamaguiAliases helper function:
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.