Skip to content

Commit c696edd

Browse files
authored
Fix the demo (#2086)
1 parent 3234d99 commit c696edd

File tree

4 files changed

+725
-34
lines changed

4 files changed

+725
-34
lines changed

examples/with-sveltekit/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@
3131
},
3232
"type": "module",
3333
"dependencies": {
34+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
35+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
3436
"@fontsource/fira-mono": "^4.5.10",
35-
"@web3-onboard/core": "^2.21.0",
37+
"@rollup/plugin-commonjs": "^25.0.7",
38+
"@web3-onboard/core": "^2.21.3-alpha.1",
3639
"@web3-onboard/injected-wallets": "^2.8.5",
3740
"@web3-onboard/walletconnect": "^2.3.6",
38-
"buffer": "^6.0.3"
41+
"assert": "^2.1.0",
42+
"browserify-zlib": "^0.2.0",
43+
"buffer": "^6.0.3",
44+
"crypto-browserify": "^3.12.0",
45+
"stream-browserify": "^3.0.0"
3946
}
4047
}
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import adapter from '@sveltejs/adapter-auto';
2-
import preprocess from 'svelte-preprocess';
1+
import adapter from '@sveltejs/adapter-auto'
2+
import preprocess from 'svelte-preprocess'
33

4-
// For further build env configs and troubleshooting
4+
// For further build env configs and troubleshooting
55
// checkout our official docs [here](https://onboard.blocknative.com/docs/modules/core#sveltekit-vite)
66

77
/** @type {import('@sveltejs/kit').Config} */
88
const config = {
9-
// Consult https://github.com/sveltejs/svelte-preprocess
10-
// for more information about preprocessors
11-
preprocess: preprocess(),
9+
// Consult https://github.com/sveltejs/svelte-preprocess
10+
// for more information about preprocessors
11+
preprocess: preprocess(),
1212

13-
kit: {
14-
adapter: adapter(),
15-
}
16-
};
13+
kit: {
14+
adapter: adapter()
15+
},
1716

18-
export default config;
17+
build: {
18+
rollupOptions: {
19+
external: ['buffer']
20+
}
21+
}
22+
}
23+
24+
export default config
Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { sveltekit } from '@sveltejs/kit/vite'
22
import inject from '@rollup/plugin-inject'
3+
import commonjs from '@rollup/plugin-commonjs';
34

45
import type { UserConfig } from 'vite'
56
import 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

1016
const MODE = process.env.NODE_ENV
@@ -15,44 +21,55 @@ const development = MODE === 'development'
1521
const config: UserConfig = {
1622
plugins: [
1723
sveltekit(),
24+
commonjs({
25+
include: /node_modules/ // 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

Comments
 (0)