import { defineConfig } from 'vite'

import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";


const writerServerProxyTarget = {
  target: "http://localhost:5001",
  changeOrigin: true
}

export default defineConfig({
  define: {
    'process.env.DEBUG': '""',
    'process.env.NODE_ENV': '"production"',
    'process.env.TERM': '""',
    'process.platform': '""'
  },
  server: {
    proxy: {
      "/rpc": writerServerProxyTarget
    },
  },
  plugins: [
    wasm(),
    topLevelAwait()
  ],
  
  // This is only necessary if you are using `SharedWorker` or `WebWorker`, as 
  // documented in https://vitejs.dev/guide/features.html#import-with-constructors
  worker: {
    format: "es",
    plugins: [topLevelAwait(), wasm()]
  },

  optimizeDeps: {
    // This is necessary because otherwise `vite dev` includes two separate
    // versions of the JS wrapper. This causes problems because the JS
    // wrapper has a module level variable to track JS side heap
    // allocations, initializing this twice causes horrible breakage
    exclude: ["@automerge/automerge-wasm"]
  }
});
