Add node polyfills (#1093)

* Add node polyfills

* remove unused polyfill

* enable fs in node polyfill

* remove polyfill aliases and crypto

* Fix build error

* Fix buffer injection
This commit is contained in:
Ajay Bura 2023-01-30 15:20:53 +11:00 committed by GitHub
parent 3ad143228d
commit 374d2d1962
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 162 additions and 0 deletions

View file

@ -2,6 +2,8 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { wasm } from '@rollup/plugin-wasm';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import inject from '@rollup/plugin-inject';
import { svgLoader } from './viteSvgLoader';
const copyFiles = {
@ -39,9 +41,28 @@ export default defineConfig({
wasm(),
react(),
],
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis'
},
plugins: [
// Enable esbuild polyfill plugins
NodeGlobalsPolyfillPlugin({
process: false,
buffer: true,
}),
]
}
},
build: {
outDir: 'dist',
sourcemap: true,
copyPublicDir: false,
rollupOptions: {
plugins: [
inject({ Buffer: ['buffer', 'Buffer'] })
]
}
},
});