Skip to content

Commit

Permalink
Use different plugin for polyfilling
Browse files Browse the repository at this point in the history
  • Loading branch information
ebma committed Jan 22, 2024
1 parent 6becffa commit 02e79d7
Show file tree
Hide file tree
Showing 3 changed files with 766 additions and 124 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@graphql-codegen/cli": "~5.0.0",
"@graphql-codegen/client-preset": "~4.1.0",
"@pendulum-chain/types": "^0.2.3",
Expand Down Expand Up @@ -98,6 +96,7 @@
"@typescript-eslint/parser": "^5.53.0",
"autoprefixer": "^10.4.13",
"daisyui": "^2.52.0",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.34.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-react": "^7.32.2",
Expand Down
68 changes: 61 additions & 7 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import preact from '@preact/preset-vite';
import { defineConfig } from 'vite';

import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import rollupNodePolyFill from 'rollup-plugin-node-polyfills';
import { polyfillNode } from 'esbuild-plugin-polyfill-node';

// https://vitejs.dev/config/
export default defineConfig({
Expand Down Expand Up @@ -51,13 +50,68 @@ export default defineConfig({
define: {
global: 'globalThis',
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
// Enable esbuild polyfill plugins
polyfillNode({
globals: {
global: false,
__dirname: false,
__filename: false,
buffer: false,
process: false,
navigator: false,
},
polyfills: {
_stream_duplex: true,
_stream_passthrough: true,
_stream_readable: true,
_stream_transform: true,
_stream_writable: true,
assert: true,
'assert/strict': false,
async_hooks: false,
buffer: false,
child_process: 'empty',
cluster: 'empty',
console: false,
constants: true,
crypto: 'empty',
dgram: 'empty',
diagnostics_channel: false,
dns: 'empty',
domain: true,
events: true,
fs: 'empty',
'fs/promises': false,
http: true,
http2: false,
https: true,
module: 'empty',
net: 'empty',
os: true,
path: true,
perf_hooks: false,
process: true,
punycode: true,
querystring: true,
readline: 'empty',
repl: 'empty',
stream: true,
string_decoder: true,
sys: true,
timers: true,
'timers/promises': false,
tls: 'empty',
tty: true,
url: true,
util: true,
v8: false,
vm: true,
wasi: false,
worker_threads: false,
zlib: true,
},
}),
NodeModulesPolyfillPlugin(),
],
},
},
Expand Down
Loading

0 comments on commit 02e79d7

Please sign in to comment.