Concept uses Vite as its build tool, providing lightning-fast development and optimized production builds. This guide covers everything you need to know about the build system.
Vite offers several advantages over traditional bundlers:
The vite.config.js file controls how Vite builds your project:
import { defineConfig } from 'vite';
import { resolve } from 'path';
import handlebars from 'vite-plugin-handlebars';
import { viteStaticCopy } from 'vite-plugin-static-copy';
export default defineConfig({
root: 'src',
base: '/',
build: {
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
input: {
main: resolve(__dirname, 'src/index.html'),
// Add all your pages here
login: resolve(__dirname, 'src/pages/auth/login.html'),
products: resolve(__dirname, 'src/pages/ecommerce/products.html'),
// ... more pages
}
}
},
plugins: [
handlebars({
partialDirectory: resolve(__dirname, 'src/partials'),
context: {
title: 'Concept Dashboard'
}
}),
viteStaticCopy({
targets: [
{ src: 'assets/images/*', dest: 'assets/images' }
]
})
],
server: {
port: 3000,
hot: true,
open: true
}
});
root: 'src'
Sets the project root to the src directory.
build: {
outDir: '../dist',
emptyOutDir: true
}
outDir: Where production files are generatedemptyOutDir: Cleans the output directory before buildingrollupOptions: {
input: {
main: '/index.html',
dashboard: '/pages/dashboard.html',
login: '/pages/auth/login.html'
}
}
Each entry creates a separate HTML file in the build.
server: {
port: 3000,
hot: true,
open: true,
host: 'localhost'
}
The package.json defines useful scripts:
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"clean": "rm -rf dist",
"build:analyze": "vite build --analyze",
"build:watch": "vite build --watch"
}
}
npm run dev - Start development servernpm run build - Create production buildnpm run preview - Preview production build locallynpm run clean - Remove dist directorynpm run build:analyze - Analyze bundle sizenpm run build:watch - Rebuild on file changesnpm run dev
This starts the Vite dev server with:
When you modify files:
To add a new page:
Create the HTML file:
<!-- src/pages/features/new-feature.html -->
{{> layouts/main title="New Feature"}}
{{#*inline "content"}}
<!-- Page content -->
{{/inline}}
{{> layouts/base}}
Add to vite.config.js:
input: {
'new-feature': resolve(__dirname, 'src/pages/features/new-feature.html')
}
The page is now accessible at /pages/features/new-feature.html
npm run build
This command:
Vite automatically applies these optimizations:
dist/
├── assets/
│ ├── index-[hash].css # Main styles
│ ├── index-[hash].js # Main JavaScript
│ └── vendor-[hash].js # Vendor libraries
├── pages/
│ └── [all HTML pages]
├── index.html
└── favicon.ico
Create a .env file:
VITE_APP_NAME=My Dashboard
VITE_API_URL=https://api.example.com
VITE_VERSION=1.0.0
Access in JavaScript:
console.log(import.meta.env.VITE_APP_NAME);
console.log(import.meta.env.VITE_API_URL);
Access in HTML/Handlebars:
<title>{{env.VITE_APP_NAME}}</title>
# Development
npm run dev
# Production
npm run build
# Staging (with .env.staging)
npm run build -- --mode staging
Add plugins to extend Vite functionality:
import imagemin from 'vite-plugin-imagemin';
export default {
plugins: [
imagemin({
gifsicle: { optimizationLevel: 3 },
optipng: { optimizationLevel: 7 },
mozjpeg: { quality: 75 },
svgo: { plugins: [{ name: 'removeViewBox' }] }
})
]
}
For API development:
server: {
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
Optimize build performance:
build: {
// Increase chunk size warning limit
chunkSizeWarningLimit: 1000,
// Optimize dependencies
commonjsOptions: {
include: [/node_modules/]
},
// Source maps only for errors
sourcemap: 'hidden'
}
# Use different port
npm run dev -- --port 3001
# Or kill process on port 3000
lsof -ti:3000 | xargs kill
# Clear cache
rm -rf node_modules/.vite
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
// Add to vite.config.js
server: {
watch: {
usePolling: true
}
}
# Analyze bundle
npm run build -- --analyze
# Check visualization at:
# http://localhost:8888
For static hosts (Netlify, Vercel):
base: '/',
build: {
outDir: 'dist'
}
For subdirectory deployment:
base: '/admin/',
build: {
outDir: 'dist',
assetsDir: 'assets'
}
Example nginx config:
server {
listen 80;
server_name example.com;
root /var/www/concept/dist;
location / {
try_files $uri $uri/ /index.html;
}
location /assets {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
vite.config.js clean and documentedMaster the build system with these guides:
Understanding Vite and the build system empowers you to customize and optimize your development workflow. Happy building! 🚀