A fast, modern, and production-ready frontend boilerplate using Vite, React, and TypeScript β fully containerized with Docker and supporting multiple environments (development, staging, production).
- Vite for lightning-fast bundling
- React + TypeScript for modern frontend development
- Docker for easy containerization and environment configuration
- Nginx to serve production builds
- Environment support for
development,staging, andproduction
Environment variables are configured using .env files:
.env.development.env.staging.env.production
Each must define:
VITE_API_URL=https://your.api.urlVite will pick the correct .env file based on the build mode:
--mode development--mode staging--mode production
# Install dependencies
npm install
# Start dev server (uses .env.development)
npm run dev
# Type check
npm run type-check# Replace "development" with "staging" or "production" as needed
docker build --build-arg BUILD_ENV=development -t vite-app-dev .docker run -p 3000:80 vite-app-dev"scripts": {
"dev": "vite",
"build": "vite build",
"build:dev": "vite build --mode development",
"build:staging": "vite build --mode staging",
"build:prod": "vite build --mode production",
"serve:dev": "vite preview --port 5001",
"serve:staging": "vite preview --port 5002",
"serve:prod": "vite preview --port 5003",
"type-check": "tsc --noEmit",
"docker:build:dev": "docker build -t vite-app-dev --build-arg BUILD_ENV=development .",
"docker:build:staging": "docker build -t vite-app-staging --build-arg BUILD_ENV=staging .",
"docker:build:prod": "docker build -t vite-app-prod --build-arg BUILD_ENV=production .",
"docker:run:dev": "docker run -p 3001:80 vite-app-dev",
"docker:run:staging": "docker run -p 3002:80 vite-app-staging",
"docker:run:prod": "docker run -p 3000:80 vite-app-prod"
}Access the environment variable in your code like this:
console.log(import.meta.env.VITE_API_URL);To verify the current build mode:
console.log(import.meta.env.MODE); // e.g., "development"- The final build is served via Nginx.
nginx.confis configured to support SPA routing with fallback toindex.html.- Docker
ARG BUILD_ENVcontrols which.env.*file is used at build time.
βββ src/ # React + TypeScript source code
βββ public/ # Static assets
βββ Dockerfile
βββ nginx.conf
βββ .env.development
βββ .env.staging
βββ .env.production
βββ vite.config.ts
βββ tsconfig.json
βββ package.json
βββ README.md
Pull requests are welcome! For major changes, please open an issue first to discuss what youβd like to change.