Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
79 lines (76 loc) · 2.26 KB
/
Copy pathvite.config.ts
File metadata and controls
79 lines (76 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { visualizer } from "rollup-plugin-visualizer";
import { seoPrerender } from "./scripts/seo/prerenderPlugin.ts";
export default defineConfig(({ mode }) => ({
server: {
host: "127.0.0.1",
port: 8080,
strictPort: true,
},
plugins: [
react(),
// Per-route HTML for crawlers and link previews; fails soft (see scripts/seo).
seoPrerender(),
// Bundle analyzer on request only (ANALYZE=1), written outside dist so it is never published.
process.env.ANALYZE === '1' && visualizer({
filename: 'stats.html',
open: false,
gzipSize: true,
brotliSize: true,
}),
].filter(Boolean),
resolve: {
alias: {
"@": path.resolve(import.meta.dirname, "./src"),
},
},
// Ensure all files in the public directory are served at the root
publicDir: "public",
build: {
// Improve build error reporting for contributors
reportCompressedSize: true,
// Optimize chunk size
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
// Add code splitting for CSS
assetFileNames: (assetInfo) => {
if (!assetInfo.name) return 'assets/[name]-[hash][extname]';
const info = assetInfo.name.split('.');
let extType = info[info.length - 1];
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
extType = 'img';
} else if (/woff|woff2|eot|ttf|otf/i.test(extType)) {
extType = 'fonts';
}
return `assets/${extType}/[name]-[hash][extname]`;
},
}
},
// Keep production implementation details out of public artifacts.
sourcemap: mode !== 'production',
// Modern build target for better performance
target: 'es2020',
// Minify output
minify: 'terser',
terserOptions: {
compress: {
// Remove console logs in production
drop_console: mode === 'production',
},
},
},
// Customize error overlay for better contributor experience
css: {
devSourcemap: true,
},
// Configure the preview option for better local testing
preview: {
host: "127.0.0.1",
port: 8081,
strictPort: true,
open: false,
},
}));