-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
216 lines (200 loc) · 6.86 KB
/
Copy pathvite.config.js
File metadata and controls
216 lines (200 loc) · 6.86 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import envCompatible from 'vite-plugin-env-compatible';
import path from 'path';
import { execSync } from 'child_process';
import pkg from './package.json' with { type: 'json' };
// Get git commit hash for version tracking
function getGitCommitHash() {
try {
return execSync('git rev-parse --short HEAD').toString().trim();
} catch {
return 'unknown';
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on mode (development, production, etc.)
const env = loadEnv(mode, process.cwd(), '');
// Get version info
const appVersion = pkg.version;
const commitHash = getGitCommitHash();
const buildTime = new Date().toISOString();
return {
plugins: [
react({
// Enable JSX in .js files
include: '**/*.{jsx,js}',
}),
// Enable importing SVG files as React components
svgr({
svgrOptions: {
// SVGR options
icon: true,
dimensions: false,
},
}),
// Support REACT_APP_ environment variables for backward compatibility
envCompatible({
prefix: 'REACT_APP_'
})
],
// Define environment variables without VITE_ prefix
define: {
// Secure Storage Lite
// Injected as a compile-time constant to avoid importing `import.meta.env` in runtime code
// that is also executed by Jest (which runs in CJS and can't parse import.meta).
__BIEN_SECURE_STORAGE_LITE_SCRAMBLE_KEY__: JSON.stringify(env.VITE_BIEN_SECURE_STORAGE_LITE_SCRAMBLE_KEY || ''),
// App Version Info (injected at build time)
'import.meta.env.APP_VERSION': JSON.stringify(appVersion),
'import.meta.env.COMMIT_HASH': JSON.stringify(commitHash),
'import.meta.env.BUILD_TIME': JSON.stringify(buildTime),
// AI Configuration
'import.meta.env.AI_DEFAULT_PROVIDER': JSON.stringify(env.AI_DEFAULT_PROVIDER || 'openai'),
'import.meta.env.OPENAI_API_KEY': JSON.stringify(env.OPENAI_API_KEY || ''),
'import.meta.env.ANTHROPIC_API_KEY': JSON.stringify(env.ANTHROPIC_API_KEY || ''),
'import.meta.env.MISTRAL_API_KEY': JSON.stringify(env.MISTRAL_API_KEY || ''),
'import.meta.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY || ''),
'import.meta.env.AI_AUTOCOMPLETE_PROVIDER': JSON.stringify(env.AI_AUTOCOMPLETE_PROVIDER || ''),
'import.meta.env.AI_EDIT_PROVIDER': JSON.stringify(env.AI_EDIT_PROVIDER || ''),
'import.meta.env.AI_IMPROVE_PROVIDER': JSON.stringify(env.AI_IMPROVE_PROVIDER || ''),
'import.meta.env.AI_SUMMARIZE_PROVIDER': JSON.stringify(env.AI_SUMMARIZE_PROVIDER || ''),
'import.meta.env.AI_TIPS_PROVIDER': JSON.stringify(env.AI_TIPS_PROVIDER || ''),
'import.meta.env.AI_TRANSLATE_PROVIDER': JSON.stringify(env.AI_TRANSLATE_PROVIDER || ''),
},
// Enable esbuild to handle JSX in .js files
esbuild: {
loader: 'jsx',
include: /src\/.*\.jsx?$/,
exclude: [],
// Enable tree shaking
treeShaking: true,
// Minify identifiers
minifyIdentifiers: true,
// Minify syntax
minifySyntax: true,
},
// Set the root directory for the app
root: '.',
// Public directory for static assets
publicDir: 'public',
// Build output directory
build: {
outDir: 'build',
sourcemap: true,
chunkSizeWarningLimit: 1000,
// Enable CSS code splitting for better caching and loading
cssCodeSplit: true,
// Consistent CSS minification
cssMinify: process.env.NODE_ENV === 'production' ? 'esbuild' : false,
// Minification options
minify: 'esbuild',
rollupOptions: {
output: {
manualChunks: {
// Split vendor chunks for better caching
// Keys are internal identifiers only - filenames use hash
'v0': ['react', 'react-dom', 'react-router-dom'],
'v2': ['react-icons'],
'v3': ['js-cookie', 'dompurify', 'store2'],
'v4': ['@aws-sdk/client-s3'],
},
// Obfuscated chunk file names - hash only for security
chunkFileNames: 'assets/[hash].js',
entryFileNames: 'assets/[hash].js',
assetFileNames: (assetInfo) => {
// Separate CSS files from other assets for better caching
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
return 'assets/[hash].css';
}
return 'assets/[hash].[ext]';
}
}
}
,
// Improve CommonJS handling for packages that export mixed ESM/CJS
commonjsOptions: {
// Process all node_modules through the CommonJS plugin to
// support packages that only provide CJS entrypoints.
include: [/node_modules/],
transformMixedEsModules: true,
// Prefer exposing default when requiring CommonJS modules
requireReturnsDefault: 'preferred'
}
},
// Dev server configuration
server: {
port: 3001,
open: true,
// Proxy API requests to backend
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
secure: false,
},
'/auth': {
target: 'http://localhost:3000',
changeOrigin: true,
secure: false,
}
},
// Watch configuration - exclude files that are updated by backend
watch: {
ignored: ['**/fallback-exchange-rates.json']
}
},
// Preview server (for production build preview)
preview: {
port: 3001,
open: true,
},
// Resolve aliases
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
'@views': path.resolve(__dirname, './src/views'),
'@utilities': path.resolve(__dirname, './src/utilities'),
'@hooks': path.resolve(__dirname, './src/hooks'),
'@contexts': path.resolve(__dirname, './src/contexts'),
'@styles': path.resolve(__dirname, './src/styles'),
}
},
// CSS configuration with PostCSS and consistent processing
css: {
devSourcemap: true,
// Enable CSS code splitting for better caching in production
devCodeSplit: false,
// PostCSS configuration
postcss: './postcss.config.js',
},
// Optimize dependencies
optimizeDeps: {
include: [
'react',
'react-dom',
'react-router-dom',
'react-icons',
'js-cookie',
'dompurify',
'store2',
'@aws-sdk/client-s3',
// Pre-bundle stream chat packages to avoid Rollup static import issues
'stream-chat',
'stream-chat-react',
// Prebundle react-helmet and its shallowEqual dependency
'react-helmet-async',
'shallowequal',
'invariant',
'react-fast-compare',
'prop-types',
'react-transition-group',
'classnames'
],
// Exclude large dependencies from pre-bundling if they're not used immediately
exclude: ['@aws-sdk/client-s3']
},
};
});