forked from selfxyz/self
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
202 lines (185 loc) · 6.58 KB
/
vite.config.ts
File metadata and controls
202 lines (185 loc) · 6.58 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
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
import { dirname, resolve } from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
import { fileURLToPath } from 'url';
import { defineConfig } from 'vite';
import svgr from 'vite-plugin-svgr';
import { tamaguiPlugin } from '@tamagui/vite-plugin';
import react from '@vitejs/plugin-react-swc';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default defineConfig({
root: 'web',
publicDir: 'web',
envDir: '..', // This is the directory where Vite will look for .env files relative to the root
resolve: {
extensions: [
'.web.tsx',
'.web.js',
'.web.jsx',
'.web.ts',
'.tsx',
'.ts',
'.jsx',
'.js',
],
alias: {
'@env': resolve(__dirname, 'env.ts'),
'/src': resolve(__dirname, 'src'),
'@': resolve(__dirname, 'src'),
'react-native-svg': 'react-native-svg-web',
'lottie-react-native': 'lottie-react',
'@react-native-community/blur': resolve(
__dirname,
'src/mocks/react-native-community-blur.ts',
),
'react-native-safe-area-context': resolve(
__dirname,
'src/mocks/react-native-safe-area-context.js',
),
'react-native-gesture-handler': resolve(
__dirname,
'src/mocks/react-native-gesture-handler.ts',
),
'react-native-passport-reader': resolve(
__dirname,
'src/mocks/react-native-passport-reader.ts',
),
'@/utils/nfcScanner': resolve(__dirname, 'src/mocks/nfcScanner.ts'),
crypto: resolve(__dirname, '../common/src/polyfills/crypto.ts'),
buffer: 'buffer',
// Fix @noble/hashes subpath exports for web builds
'@noble/hashes/crypto.js': '@noble/hashes/crypto',
},
},
plugins: [
{
name: 'fix-buffer-externalization',
transform(code, id) {
// Fix the mobile-sdk-alpha chunk that references Buffer
if (id.includes('mobile-sdk-alpha') && code.includes('from "buffer"')) {
// Keep the import so the polyfill is bundled, and set global assignment
const fixedCode = code.replace(
/import\s+\{\s*Buffer\s*\}\s+from\s+['"]buffer['"]/g,
"import { Buffer } from 'buffer';\nif (typeof globalThis.Buffer === 'undefined') { globalThis.Buffer = Buffer; }",
);
return { code: fixedCode, map: null };
}
return null;
},
},
react(),
svgr({
include: '**/*.svg',
}),
tamaguiPlugin({
config: resolve(__dirname, 'tamagui.config.ts'),
components: ['tamagui'],
enableDynamicEvaluation: true,
excludeReactNativeWebExports: [
'Switch',
'ProgressBar',
'Picker',
'CheckBox',
'Touchable',
],
platform: 'web',
optimize: true,
}),
// Bundle analyzer for tree shaking analysis
visualizer({
filename: 'web/dist/bundle-analysis.html',
open: false, // Don't auto-open in CI
gzipSize: true,
brotliSize: true,
template: 'treemap', // Shows tree shaking effectiveness visually
}),
].filter(Boolean),
define: {
global: 'globalThis',
},
optimizeDeps: {
include: ['buffer'],
exclude: ['fs', 'path', 'child_process', '@zk-email/helpers'],
esbuildOptions: {
// Optimize minification
minifyIdentifiers: true,
minifySyntax: true,
minifyWhitespace: true,
},
},
build: {
emptyOutDir: true,
outDir: resolve(__dirname, 'web/dist'),
// Optimize minification settings
minify: 'esbuild',
target: 'es2020',
cssMinify: true,
cssCodeSplit: true,
rollupOptions: {
external: ['fs', 'child_process', '@zk-email/helpers'],
output: {
// Optimize chunk size and minification
compact: true,
manualChunks: {
// Core React and Navigation
'vendor-react-core': ['react', 'react-dom'],
'vendor-navigation': [
'@react-navigation/native',
'@react-navigation/native-stack',
],
// UI Framework - split Tamagui into smaller chunks
'vendor-ui-core': ['tamagui'],
'vendor-ui-icons': ['@tamagui/lucide-icons'],
'vendor-ui-toast': ['@tamagui/toast'],
// Crypto libraries - split heavy crypto into smaller chunks
'vendor-crypto-core': ['elliptic', 'node-forge'],
'vendor-crypto-ethers': ['ethers'],
'vendor-crypto-x509': ['@peculiar/x509', 'pkijs', 'asn1js'],
'vendor-crypto-cbor': ['@stablelib/cbor'],
// Heavy crypto dependencies - split further
'vendor-crypto-poseidon': ['poseidon-lite'],
'vendor-crypto-lean-imt': ['@openpassport/zk-kit-lean-imt'],
// Device-specific libraries
'vendor-device-nfc': ['react-native-nfc-manager'],
'vendor-device-gesture': ['react-native-gesture-handler'],
'vendor-device-haptic': ['react-native-haptic-feedback'],
// Analytics - split by provider
'vendor-analytics-segment': ['@segment/analytics-react-native'],
'vendor-analytics-sentry': ['@sentry/react', '@sentry/react-native'],
// Animations
'vendor-animations-lottie': ['lottie-react-native', 'lottie-react'],
// WebSocket and Socket.IO
'vendor-websocket': ['socket.io-client'],
// UUID generation
'vendor-uuid': ['uuid'],
// State management
'vendor-state-xstate': ['xstate'],
'vendor-state-zustand': ['zustand'],
// Screen-specific chunks - more granular
'screens-document-core': ['./src/navigation/document.ts'],
'screens-passport-nfc': ['./src/utils/nfcScanner.ts'],
// Proving - split into even smaller chunks
'screens-prove-core': ['./src/navigation/prove.ts'],
'screens-prove-validation-core': [
'./src/utils/proving/validateDocument.ts',
],
'screens-prove-utils': [
'./src/utils/proving/index.ts',
'./src/utils/proving/loadingScreenStateText.ts',
],
// Large animations - split out heavy Lottie files
'animations-passport-onboarding': [
'./src/assets/animations/passport_onboarding.json',
],
// Other screens
'screens-settings': ['./src/navigation/settings.ts'],
'screens-recovery': ['./src/navigation/recovery.ts'],
'screens-dev': ['./src/navigation/devTools.ts'],
},
},
},
},
});