Deployment
Learn how to deploy your Metronic React application to various hosting platforms.
This guide covers the basics of deploying your Metronic React application to production.
Building for Production
# Navigate to your project directory
cd metronic-tailwind-react/typescript/vite
# Install dependencies (if needed)
npm install
# Build for production
npm run buildThis creates a dist directory with optimized files ready for deployment.
Configuration
Base URL
Metronic React uses a base URL configuration in vite.config.ts for deployments to subdirectories or behind reverse proxies.
The starter kit comes with a default base configuration:
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [react(), tailwindcss()],
base: process.env.VITE_BASE_URL || '/',
// ... rest of config
});Understanding Base URL
The base option tells Vite where your application will be served from. For example:
- Root deployment:
https://example.com/→base: '/' - Subdirectory deployment:
https://example.com/metronic/tailwind/react/→base: '/metronic/tailwind/react'
Configuration Options
Option 1: Using Environment Variable (Recommended)
Set the VITE_BASE_URL environment variable in your .env.production file:
# For subdirectory deployment
VITE_BASE_URL=/metronic/tailwind/react
# For root deployment
VITE_BASE_URL=/Option 2: Hardcoded in Config
You can also hardcode the base directly in vite.config.ts:
export default defineConfig({
base: '/your-custom-path',
// ... rest of config
});Important Notes
-
Path Format: The
basemust be a path string (e.g.,/metronic/tailwind/react), not a full URL. Always start with a forward slash/. -
Trailing Slash: Vite handles trailing slashes automatically, but it's recommended to include the trailing slash for consistency:
/metronic/tailwind/react/ -
Asset Loading: When using a base path, Vite automatically prefixes all asset references (CSS, JS, images) with the base path.
-
Router Configuration: If you're using React Router, make sure your router's
basenameprop matches your Vite base configuration. -
Development vs Production: You can use different base URLs for development and production by setting different values in
.envand.env.productionfiles.
Example: Deploying Behind Nginx
If you're deploying behind an nginx reverse proxy:
location /metronic/tailwind/react {
alias /path/to/your/dist;
try_files $uri $uri/ /metronic/tailwind/react/index.html;
}Then set in your .env.production:
VITE_BASE_URL=/metronic/tailwind/reactTroubleshooting Base URL Issues
If you're experiencing issues with assets not loading or routes not working:
-
Check Environment Variable: Ensure
VITE_BASE_URLis set correctly in your production environment. -
Rebuild After Changes: After changing the base URL, you must rebuild your application:
npm run build -
Verify Asset Loading: Check your browser's Network tab to see if assets are being requested from the correct path.
-
Check Router Basename: If using React Router, ensure the
basenameprop matches your Vite base configuration.