Deployment
About Deployment
ASP.NET Zero React UI is built using Vite as the build tool and bundler. Vite provides fast development server and optimized production builds out of the box.
Building for Production
To build the React application for production, run the following commands in the root directory of the React project:
- Run
pnpm installornpm installto install dependencies. - Run
pnpm buildornpm run buildto create a production build.
The build output will be placed in the dist/ folder, ready for deployment to any static file server.
Configuration
Before deploying, configure the production API endpoint by creating a .env.production file in the project root:
VITE_API_BASE_URL=https://your-production-api-url
This URL should point to your ASP.NET Zero Host API application.
Merged Solution (Optional)
ASP.NET Zero also provides a merged solution where the React client-side application is included in the server-side Host project. Both applications can be published together and hosted under the same website.
To publish the merged solution:
- Run
pnpm buildornpm run buildin the React project to build the client application. - Run
dotnet publish -c Releasein the root directory of the*.Hostproject. See the dotnet publish documentation for additional parameters. - When the publish is complete, ensure the React build output is copied to the
wwwrootfolder of the published Host application.
If you are using the merged solution, also configure settings in appsettings.Production.json file for the Host API.
Production Optimizations
Vite automatically applies the following optimizations for production builds:
- Code Splitting: Automatically splits code into smaller chunks for better caching
- Tree Shaking: Removes unused code from the final bundle
- Minification: Minifies JavaScript and CSS files
- Asset Optimization: Optimizes and hashes static assets for cache busting
You can preview the production build locally by running:
pnpm preview
# or
npm run preview