-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
143 lines (135 loc) · 3.99 KB
/
Copy pathvite.config.ts
File metadata and controls
143 lines (135 loc) · 3.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { execSync } from 'child_process';
import { seoDevPlugin } from './seo/vite-seo-plugin.js';
// Get git version info at build time
function getGitVersion(): string {
try {
return execSync('git describe --tags --always', { encoding: 'utf-8' }).trim();
} catch {
return 'dev';
}
}
function getGitCommitHash(): string {
try {
return execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
} catch {
return 'unknown';
}
}
function getGitTag(): string | null {
try {
// Try to get the latest tag from git describe
const describe = execSync('git describe --tags --always', { encoding: 'utf-8' }).trim();
// Extract tag if it's in format "tag-commits-commithash" or just "tag"
const match = describe.match(/^([^-]+?)(?:-\d+-g[0-9a-f]+)?$/);
if (match && match[1] && !match[1].match(/^[0-9a-f]{7,40}$/)) {
// It's a tag, not just a commit hash
return match[1];
}
return null;
} catch {
return null;
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
const env = loadEnv(mode, process.cwd(), '');
const isProduction = mode === 'production';
// Get git version info
const gitVersion = getGitVersion();
const gitCommitHash = getGitCommitHash();
const gitTag = getGitTag();
// Production domains
const productionDomains = [
'devcommunity.io',
'www.devcommunity.io',
'api.devcommunity.io',
'www.devcommunity.com',
];
// Development domains
const developmentDomains = [
'localhost',
'127.0.0.1',
...productionDomains, // Include production domains for staging/testing
];
return {
resolve: {
alias: {
'lucide-react': path.resolve(__dirname, 'src/icons/lucide-react.tsx'),
__lucide_fallback__: path.resolve(__dirname, 'node_modules/lucide-react'),
},
},
css: {
devSourcemap: false,
},
plugins: [
react(),
nodePolyfills({
globals: {
Buffer: true,
global: true,
process: true,
},
protocolImports: true,
}),
// Dynamic SEO + AI discovery (robots/sitemap/llms) parity in dev on :3351
seoDevPlugin(env),
],
define: {
'import.meta.env.VITE_APP_VERSION': JSON.stringify(gitVersion),
'import.meta.env.VITE_APP_COMMIT_HASH': JSON.stringify(gitCommitHash),
'import.meta.env.VITE_APP_GIT_TAG': JSON.stringify(gitTag),
},
server: {
port: parseInt(env.VITE_PORT || '5173'),
host: env.VITE_HOST || '0.0.0.0',
strictPort: false,
open: false,
cors: true,
allowedHosts: isProduction ? productionDomains : developmentDomains,
sourcemapIgnoreList: (sourcePath) =>
sourcePath.includes('node_modules') || sourcePath.includes('.vite/deps'),
},
preview: {
port: parseInt(env.VITE_PORT || '4173'),
host: env.VITE_HOST || '0.0.0.0',
allowedHosts: isProduction ? productionDomains : developmentDomains,
cors: true,
},
build: {
// Production optimizations
minify: 'esbuild',
sourcemap: !isProduction, // Only generate sourcemaps in development
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
'ui-vendor': [
'@lineiconshq/react-lineicons',
'@lineiconshq/free-icons',
],
},
},
},
// Increase chunk size warning limit
chunkSizeWarningLimit: 1000,
// Optimize assets
assetsInlineLimit: 4096,
},
optimizeDeps: {
include: [
'react',
'react-dom',
'react-router-dom',
'@lineiconshq/react-lineicons',
'@lineiconshq/free-icons',
'buffer',
'process',
],
},
};
});