Skip to content

Commit 1c77c33

Browse files
committed
chore: setup node polyfills
1 parent 7ac6671 commit 1c77c33

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
},
104104
"devDependencies": {
105105
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
106+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
106107
"@testing-library/dom": "^10.1.0",
107108
"@testing-library/react": "^12.1.5",
108109
"@types/enzyme": "^3.10.10",

vite.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig, loadEnv } from 'vite';
22
import react from '@vitejs/plugin-react-swc';
33
import { resolve } from 'path';
44
import svgr from 'vite-plugin-svgr';
5+
import NodeGlobalsPolyfillPlugin from '@esbuild-plugins/node-globals-polyfill';
56

67
// https://vitejs.dev/config/
78
export default defineConfig(({ mode }) => {
@@ -48,5 +49,19 @@ export default defineConfig(({ mode }) => {
4849
environment: 'jsdom',
4950
setupFiles: ['./setupVitest.ts'],
5051
},
52+
optimizeDeps: {
53+
esbuildOptions: {
54+
// Node.js global to browser globalThis
55+
define: {
56+
global: 'globalThis',
57+
},
58+
// Enable esbuild polyfill plugins
59+
plugins: [
60+
NodeGlobalsPolyfillPlugin({
61+
buffer: true,
62+
}),
63+
],
64+
},
65+
},
5166
};
5267
});

0 commit comments

Comments
 (0)