Vite Guide
How to set up Gui with Vite
Gui 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 @hanzogui/vite-plugin package.
Install
@hanzogui/vite-plugin is ESM-only. Your project must have "type": "module" in its
package.json (or use .mjs/.mts config files). CJS (require()) is not supported.npm create hanzogui@latest
and select the ‘Simple Web’ option which includes a Vite setup.Create a new Vite project:
yarn
npm
bun
pnpm
yarn create vite@latest
Add @hanzogui/vite-plugin:
yarn
npm
bun
pnpm
yarn add @hanzogui/vite-plugin
Configuration
Update your vite.config.ts. If you have a hanzogui.build.ts (recommended —
see compiler install docs),
no options are needed:
vite.config.ts
import { hanzoguiPlugin } from '@hanzogui/vite-plugin'export default {plugins: [// reads from hanzogui.build.ts automaticallyhanzoguiPlugin(),].filter(Boolean),}
Or pass options inline:
vite.config.ts
import { hanzoguiPlugin } from '@hanzogui/vite-plugin'export default {plugins: [hanzoguiPlugin({config: 'src/hanzogui.config.ts',components: ['@hanzo/gui'],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 extensionsconfig.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 hanzoguiAliases
For advanced use cases where you need more control over alias ordering in your Vite config, you can use the hanzoguiAliases helper function:
vite.config.ts
import { hanzoguiAliases } from '@hanzogui/vite-plugin'export default {resolve: {alias: [// your custom aliases first{ find: '@app', replacement: '/src' },// then hanzogui aliases...hanzoguiAliases({// use @hanzogui/react-native-web-lite for smaller bundlernwLite: true,// or 'without-animated' for even smaller bundle (no Animated API)// rnwLite: 'without-animated',// alias react-native-svg to @hanzogui/react-native-svgsvg: true,}),],},}
This is useful when you need to ensure specific alias resolution order or when using a custom Vite setup without the full hanzoguiPlugin.