import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from 'path' import { nodePolyfills } from 'vite-plugin-node-polyfills' // https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), nodePolyfills({ // Enable polyfills for specific modules globals: { Buffer: true, global: true, process: true, }, // Include specific polyfills include: ['buffer', 'events', 'stream', 'util', 'crypto'], // Exclude Node.js built-ins that shouldn't be polyfilled exclude: ['https', 'http', 'url', 'path', 'fs', 'os', 'net', 'tls', 'zlib'], }), ], resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, server: { port: 3002, }, optimizeDeps: { // Exclude problematic packages from optimization exclude: ['@safe-global/safe-core-sdk', 'https', 'http', 'url', 'stream', 'util', 'crypto', 'path', 'fs', 'os', 'net', 'tls', 'zlib'], // Include Safe SDK dependencies include: ['@safe-global/safe-ethers-lib', '@safe-global/safe-service-client'], }, define: { global: 'globalThis', 'process.env': {}, }, build: { rollupOptions: { output: { // Add Content Security Policy meta tag via HTML plugin if needed }, external: (id) => { // Mark Node.js built-ins as external for browser const nodeBuiltIns = ['https', 'http', 'url', 'stream', 'util', 'crypto', 'path', 'fs', 'os', 'net', 'tls', 'zlib'] return nodeBuiltIns.includes(id) }, }, commonjsOptions: { transformMixedEsModules: true, }, chunkSizeWarningLimit: 1000, }, })