mirror of
https://github.com/Snigdha-OS/Snigdha-OS.github.io.git
synced 2025-09-06 04:35:18 +02:00
🔧 build: vite config has been optimized
This commit is contained in:
@@ -2,89 +2,40 @@ import { defineConfig } from 'vite';
|
|||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import ViteSitemap from 'vite-plugin-sitemap';
|
import ViteSitemap from 'vite-plugin-sitemap';
|
||||||
import ViteCompression from 'vite-plugin-compression'; // For file compression in production
|
|
||||||
import postcssPresetEnv from 'postcss-preset-env'; // For enabling modern PostCSS features
|
|
||||||
|
|
||||||
// Define the base path based on the deployment environment (GitHub Pages or main domain)
|
|
||||||
const isGitHubPages = process.env.VITE_DEPLOY_ENV === 'gh-pages';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
// Base path setting for GitHub Pages and main domain
|
|
||||||
// Use '/' for both GitHub Pages and the main domain (adjust as needed)
|
|
||||||
base: isGitHubPages ? '/' : '/',
|
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
react(), // Vite plugin for React support
|
react(),
|
||||||
|
|
||||||
// Sitemap plugin to generate a sitemap.xml for SEO purposes
|
|
||||||
ViteSitemap({
|
ViteSitemap({
|
||||||
hostname: isGitHubPages ? 'https://Snigdha-OS.github.io/' : 'https://www.snigdhaos.org', // Dynamic hostname based on deployment
|
hostname: 'https://www.snigdhaos.org',
|
||||||
outDir: './dist', // Directory to output the sitemap
|
outDir: './dist',
|
||||||
changefreq: 'daily', // Frequency of content updates
|
changefreq: 'daily',
|
||||||
priority: 0.7, // Priority of the pages in the sitemap
|
priority: 0.7,
|
||||||
// lastmod: true, // Optional: Use last modification date for each URL (uncomment if needed)
|
// lastmod: true,
|
||||||
}),
|
|
||||||
|
|
||||||
// Gzip compression for production build to reduce file sizes
|
|
||||||
ViteCompression({
|
|
||||||
algorithm: 'gzip', // Compression algorithm
|
|
||||||
threshold: 10240, // Only compress files larger than 10KB
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
// Alias for easier imports from the 'src' directory
|
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, './src'), // '@' is a shortcut for the 'src' folder
|
'@': resolve(__dirname, './src'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
build: {
|
build: {
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
// Entry file for the build (e.g., script.js instead of main.js)
|
|
||||||
entryFileNames: 'script.js',
|
entryFileNames: 'script.js',
|
||||||
|
|
||||||
// Customize asset file names (e.g., CSS and other assets)
|
|
||||||
assetFileNames: ({ name }) => {
|
assetFileNames: ({ name }) => {
|
||||||
if (name && name.endsWith('.css')) {
|
if (name && name.endsWith('.css')) {
|
||||||
return 'style.css'; // All CSS files will be named 'style.css'
|
return 'style.css';
|
||||||
}
|
}
|
||||||
return 'assets/[name]-[hash][extname]'; // For other assets, use hashed filenames
|
return 'assets/[name]-[hash][extname]';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
target: 'esnext', // Set the target to 'esnext' for modern JavaScript (ES modules)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Exclude specific dependencies from being bundled by Vite
|
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
exclude: ['lucide-react'], // Prevent bundling of 'lucide-react'
|
exclude: ['lucide-react'],
|
||||||
},
|
},
|
||||||
|
|
||||||
css: {
|
|
||||||
postcss: {
|
|
||||||
plugins: [
|
|
||||||
postcssPresetEnv({
|
|
||||||
stage: 2, // Enable PostCSS features up to stage 2
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Configuration for Vite development server
|
|
||||||
server: {
|
server: {
|
||||||
open: true, // Automatically open the browser when starting the dev server
|
open: true, // Automatically open the browser when running the development server
|
||||||
proxy: {
|
|
||||||
'/api': 'http://localhost:5000', // Example proxy setup for API requests during development
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Extend configuration with environment variables (useful for flexibility)
|
|
||||||
define: {
|
|
||||||
'process.env': {
|
|
||||||
// Provide a default API URL, which can be overridden by environment variables
|
|
||||||
API_URL: process.env.VITE_API_URL || 'https://api.snigdhaos.org',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user