🧹 chore: optimize vite config

This commit is contained in:
eshanized
2025-01-13 14:02:56 +05:30
parent 14f89ed2c2
commit 2a35172f8d

View File

@@ -3,15 +3,17 @@ 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';
export default defineConfig({ export default defineConfig(({ mode }) => {
const isProduction = mode === 'production';
return {
plugins: [ plugins: [
react(), react(),
ViteSitemap({ ViteSitemap({
hostname: 'https://www.snigdhaos.org', hostname: process.env.VITE_SITE_URL || 'https://www.snigdhaos.org',
outDir: './dist', outDir: './dist',
changefreq: 'daily', changefreq: 'daily',
priority: 0.7, priority: 0.7,
// lastmod: true,
}), }),
], ],
resolve: { resolve: {
@@ -19,10 +21,18 @@ export default defineConfig({
'@': resolve(__dirname, './src'), '@': resolve(__dirname, './src'),
}, },
}, },
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/global.scss";`, // Import global SCSS
},
},
},
build: { build: {
rollupOptions: { rollupOptions: {
output: { output: {
entryFileNames: 'script.js', entryFileNames: 'script.js',
chunkFileNames: 'chunk-[name]-[hash].js',
assetFileNames: ({ name }) => { assetFileNames: ({ name }) => {
if (name && name.endsWith('.css')) { if (name && name.endsWith('.css')) {
return 'style.css'; return 'style.css';
@@ -31,11 +41,21 @@ export default defineConfig({
}, },
}, },
}, },
terserOptions: {
compress: {
drop_console: isProduction, // Remove console logs in production
drop_debugger: isProduction, // Remove debugger in production
},
},
}, },
optimizeDeps: { optimizeDeps: {
exclude: ['lucide-react'], exclude: ['lucide-react'],
}, },
server: { server: {
open: true, // Automatically open the browser when running the development server open: true,
port: 5173, // Default port
strictPort: false, // Allow using a different port if 5173 is taken
}, },
envDir: './env', // Define directory for environment variables
};
}); });