import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import {NodeGlobalsPolyfillPlugin} from '@esbuild-plugins/node-globals-polyfill'
import rollupNodePolyFill from 'rollup-plugin-node-polyfills'
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [uni()],
  resolve:{
    alias:{
      stream: 'stream-browserify',
      crypto: 'crypto-browserify',
    }
  },
  optimizeDeps:{
    esbuildOptions:{
      define:{
        global:'globalThis'
      },
      plugins:[
        NodeGlobalsPolyfillPlugin({
          process:true,
          buffer:true
        })
      ]
    }
  },
  build:{
    rollupOptions:{
      plugins:[
        rollupNodePolyFill()
      ]
    }
  },
  server: {
    port: 8088,
    host: '0.0.0.0',
    open: true,
    cors: true,
    hmr: true,
    proxy: {
      '/api': {
        target:'https://wallet.nanodreamtech.com',
        changeOrigin: true,
        ws: true,
        secure: true,
      },
    }
  }
});
