Vite Plugin
Resolid provides a custom Vite plugin that integrates with React Router and configures the development and build environments.Setup
The Resolid Vite plugin is configured throughdefineDevConfig:
Vite Plugin Options
ThevitePluginOptions returned from defineDevConfig configures the Resolid Vite plugin:
Platform
Theplatform option determines the deployment target:
"node"- Standard Node.js server"vercel"- Vercel serverless platform"netlify"- Netlify serverless platform
Node Version
Specify the Node.js runtime version for server-side builds:build.target in Vite’s SSR configuration to match your deployment environment.
Entry File
Customize the server entry file (defaults toserver.ts):
Development Exclusions
Exclude specific URLs from being handled by the React Router middleware during development:Environment Variables
The Vite plugin automatically defines environment variables accessible viaimport.meta.env:
Development Server
During development, the Resolid Vite plugin configures a middleware that:- Serves static files from the
publicdirectory - Excludes specified patterns from React Router handling
- Loads your server entry file using Vite’s SSR module loader
- Forwards requests to your Hono application
- Provides full-reload HMR for SSR modules
Hot Module Replacement
The plugin handles HMR for both client and server code:- Client modules: Standard Vite HMR with fast refresh
- Server modules: Full page reload when SSR modules change
Production Builds
For production builds, the plugin configures:- Target: Node.js version-specific builds (
node22ornode24) - Entry: Your server file as the SSR bundle entry point
- Format: ESM module format for modern Node.js
- Optimization: Removes unused React imports warnings
Configuration Example
A complete configuration example from the Resolid website:resolid.config.ts
Using in vite.config.ts
Import and use the plugin in your Vite configuration:vite.config.ts
resolidVite function returns an array of plugins including the Resolid dev plugin and React Router’s Vite plugin.