11import { sveltekit } from '@sveltejs/kit/vite'
22import inject from '@rollup/plugin-inject'
3+ import commonjs from '@rollup/plugin-commonjs' ;
34
45import type { UserConfig } from 'vite'
56import nodePolyfills from 'rollup-plugin-polyfill-node'
67
7- // For further build env configs and troubleshooting
8+ // yarn add --dev @esbuild-plugins/node-globals-polyfill
9+ import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
10+ // yarn add --dev @esbuild-plugins/node-modules-polyfill
11+ import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
12+
13+ // For further build env configs and troubleshooting
814// checkout our official docs [here](https://onboard.blocknative.com/docs/modules/core#sveltekit-vite)
915
1016const MODE = process . env . NODE_ENV
@@ -15,44 +21,55 @@ const development = MODE === 'development'
1521const config : UserConfig = {
1622 plugins : [
1723 sveltekit ( ) ,
24+ commonjs ( {
25+ include : / n o d e _ m o d u l e s / // Only transpile CommonJS modules from node_modules
26+ } ) ,
1827 development &&
1928 nodePolyfills ( {
20- include : [ 'node_modules/**/*.js' , new RegExp ( 'node_modules/.vite/.*js' ) , 'http' , 'crypto' ]
29+ include : [ 'node_modules/**/*.js' , new RegExp ( 'node_modules/.vite/.*js' ) , 'http' , 'crypto' , 'buffer' ]
2130 } )
2231 ] ,
2332 resolve : {
2433 alias : {
2534 crypto : 'crypto-browserify' ,
2635 stream : 'stream-browserify' ,
27- assert : 'assert'
36+ assert : 'assert' ,
37+ zlib : 'browserify-zlib' ,
2838 }
2939 } ,
3040 build : {
3141 rollupOptions : {
3242 external : [ '@web3-onboard/*' ] ,
33- plugins : [ nodePolyfills ( { include : [ 'crypto' , 'http' ] } ) , inject ( { Buffer : [ 'Buffer' , 'Buffer' ] } ) ]
43+ plugins : [
44+ nodePolyfills ( { include : [ 'crypto' , 'http' ] } ) ,
45+ inject ( { Buffer : [ 'Buffer' , 'Buffer' ] } )
46+ ]
3447 } ,
3548 commonjsOptions : {
3649 transformMixedEsModules : true
3750 }
3851 } ,
3952 optimizeDeps : {
4053 exclude : [ '@ethersproject/hash' , 'wrtc' , 'http' ] ,
41- include : [
42- '@web3-onboard/core' ,
43- 'js-sha3' ,
44- '@ethersproject/bignumber'
45- ] ,
54+ include : [ '@web3-onboard/core' , 'js-sha3' , '@ethersproject/bignumber' ] ,
4655 esbuildOptions : {
4756 // Node.js global to browser globalThis
4857 define : {
4958 global : 'globalThis'
5059 } ,
60+ // Enable esbuild polyfill plugins
61+ plugins : [
62+ NodeGlobalsPolyfillPlugin ( {
63+ process : true ,
64+ buffer : true
65+ } ) ,
66+ NodeModulesPolyfillPlugin ( )
67+ ]
5168 }
5269 } ,
5370 define : {
5471 global : 'window'
5572 }
5673}
5774
58- export default config
75+ export default config
0 commit comments