-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
105 lines (99 loc) · 3.03 KB
/
vite.config.ts
File metadata and controls
105 lines (99 loc) · 3.03 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
import { defineConfig, loadEnv, type Plugin } from 'vite';
import path, { resolve } from 'path';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import { existsSync } from 'fs';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// Plugin to handle JSON imports from node_modules
const jsonPlugin = (): Plugin => ({
name: 'json-resolver',
enforce: 'pre', // Run before Vite's default JSON plugin
resolveId(id: string, importer?: string) {
// Only handle JSON imports from dex-contracts-v2
if (id.endsWith('.json') && id.startsWith('dex-contracts-v2/')) {
try {
// Try to resolve using Node's module resolution
const resolvedPath = require.resolve(id, {
paths: [process.cwd(), importer ? path.dirname(importer) : process.cwd()],
});
// Return the resolved path - Vite's JSON plugin will handle loading it
return resolvedPath;
} catch {
// If require.resolve fails, try manual resolution
const parts = id.split(/[/\\]/);
const packageName = parts[0];
const filePath = parts.slice(1).join('/');
const fullPath = resolve(process.cwd(), 'node_modules', packageName, filePath);
if (existsSync(fullPath)) {
return fullPath;
}
}
}
return null; // Let Vite handle other JSON files
},
// Don't override load - let Vite's JSON plugin handle it
});
export default defineConfig(({ mode }) => {
// Load all envs from the app directory (where .env is located)
const envDir = __dirname;
const env = loadEnv(mode, envDir, '');
return {
plugins: [react(), svgr(), jsonPlugin()],
ssr: {
noExternal: ['react-helmet-async'],
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
dedupe: ['react', 'react-dom'],
},
optimizeDeps: {},
// Ensure env is loaded from the app directory
// Vite will automatically expose VITE_* vars to import.meta.env
envDir,
define: {
// Define process.env for compatibility - use object mapping to allow runtime access
'process.env': env,
},
build: {
sourcemap: false,
chunkSizeWarningLimit: 900,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
},
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: [
'@use "./src/styles/variables.scss" as *;',
'@use "./src/styles/mixins.scss" as *;',
].join(' '),
},
},
},
// Accept both prefixes in import.meta.env
envPrefix: ['VITE_', 'VUE_APP_'],
test: {
globals: true,
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{ts,tsx}'],
setupFiles: './vitest.setup.ts',
testTimeout: 30000,
pool: 'forks',
poolOptions: {
forks: {
singleFork: true,
},
},
clearMocks: true,
restoreMocks: true,
unstubGlobals: true,
unstubEnvs: true,
},
};
});