From c909eef1e5b8562fa461ae3f32057c11012dc82b Mon Sep 17 00:00:00 2001 From: Ryan MacArthur Date: Wed, 13 Mar 2024 19:22:56 +0800 Subject: [PATCH] Update vite.config.ts --- packages/dapp/vite.config.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/dapp/vite.config.ts b/packages/dapp/vite.config.ts index a47d70e..e5c2258 100644 --- a/packages/dapp/vite.config.ts +++ b/packages/dapp/vite.config.ts @@ -1,8 +1,17 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; +import { nodePolyfills } from 'vite-plugin-node-polyfills'; export default defineConfig({ - plugins: [react()], + plugins: [react(), + nodePolyfills({ + include: ["buffer"], + globals: { + Buffer: true, + }, + }), + + ], server: { port: 3000, fs: { @@ -13,5 +22,15 @@ export default defineConfig({ target: "es2022", minify: true, sourcemap: true, + rollupOptions: { + plugins: [ + inject({ + // cbor-x checks for Buffer on the global object, and the polyfills plugin doesn't cover this case for the + // production build (but works in development because Buffer gets injected as a banner, so it's "naturally" + // available on the global object) + "globalThis.Buffer": ["buffer", "Buffer"], + }), + ], + }, }, });