-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.mts
More file actions
141 lines (135 loc) · 3.82 KB
/
vite.config.mts
File metadata and controls
141 lines (135 loc) · 3.82 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
import react from '@vitejs/plugin-react'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import * as path from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import { checker } from 'vite-plugin-checker'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import tsconfigPaths from 'vite-tsconfig-paths'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// const isProduction = mode === 'production'
const isDevelopment = mode === 'development'
const isAnalyze = mode === 'analyze'
// const buildVersion = env.VITE_APP_BUILD_VERSION
return {
server: {
sourcemapIgnoreList: false,
},
plugins: [
react(),
// Custom plugin to load markdown files
{
name: 'markdown-loader',
transform(code, id) {
if (id.slice(-3) === '.md') {
// For .md files, get the raw content
return `export default ${JSON.stringify(code)};`
}
},
},
tsconfigPaths(),
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
symbolId: '[name]',
}),
...(isDevelopment
? [
checker({
overlay: {
initialIsOpen: false,
},
typescript: true,
eslint: {
useFlatConfig: true,
lintCommand: 'eslint "{src,config}/**/*.{js,ts,jsx,tsx}"',
},
}),
]
: []),
...(isAnalyze
? [
visualizer({
open: true,
}),
]
: []),
// Enable rollup polyfills plugin
// used during production bundling
nodePolyfills({
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true,
},
}),
],
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
dedupe: ['react', 'lodash'],
},
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
NodeModulesPolyfillPlugin(),
],
},
build: {
target: 'esnext',
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString()
}
// Handle specific web3 libraries as separate chunks
if (id.includes('@web3modal/siwe')) {
return 'web3modal-siwe'
}
if (id.includes('@walletconnect/modal')) {
return 'walletconnect-modal'
}
if (id.includes('@metamask/sdk')) {
return 'metamask-sdk'
}
if (id.includes('@coinbase/wallet-sdk')) {
return 'coinbase-wallet-sdk'
}
},
},
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
NodeModulesPolyfillPlugin(),
// Enable rollup polyfills plugin
// used during production bundling
nodePolyfills({
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true,
},
}),
],
},
},
}
})