Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SvelteKit+Vite - Fix config issue with sveltekit and vite config - Add docs #1569

Merged
merged 6 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@web3-onboard/trezor": "^2.3.3",
"@web3-onboard/trust": "^2.0.0",
"@web3-onboard/uauth": "^2.0.1",
"@web3-onboard/walletconnect": "^2.2.1",
"@web3-onboard/walletconnect": "^2.3.1",
"@web3-onboard/web3auth": "^2.1.4",
"@web3-onboard/xdefi": "^2.0.0",
"animejs": "^3.2.1",
Expand Down
7 changes: 6 additions & 1 deletion docs/src/lib/services/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ const intiOnboard = async (theme) => {
const infinityWallet = infinityWalletModule()
const coinbase = coinbaseModule()
const dcent = dcentModule()
const walletConnect = walletConnectModule()
const walletConnect = walletConnectModule({ connectFirstChainId: true,
version: 2,
projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5',
qrcodeModalOptions: {
mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar']
}})
Adamj1232 marked this conversation as resolved.
Show resolved Hide resolved
const ledger = ledgerModule()
const keystone = keystoneModule()
const keepkey = keepkeyModule()
Expand Down
131 changes: 126 additions & 5 deletions docs/src/routes/docs/[...3]modules/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ type ConnectModalOptions = {
* ENS resolution takes precedent over UNS
* Defaults to false
*/
disableUDResolution?: boolean
disableUDResolution?: boolean
}
```

Expand Down Expand Up @@ -1383,8 +1383,103 @@ const config = {
export default config
```

### SvelteKit + Vite

Checkout a boilerplate example (here)[https://github.com/blocknative/web3-onboard/tree/develop/examples/with-sveltekit]

Add the following dev dependencies:

`yarn add rollup-plugin-polyfill-node -D`

Then add the following to your `svelte.config.js` file:

```javascript
import adapter from '@sveltejs/adapter-auto'
import preprocess from 'svelte-preprocess'

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

kit: {
adapter: adapter()
}
}

export default config
```

Then add the following to your `vite.config.js` file:

```javascript
import { sveltekit } from '@sveltejs/kit/vite'
import inject from '@rollup/plugin-inject'

import type { UserConfig } from 'vite'
import nodePolyfills from 'rollup-plugin-polyfill-node'

const MODE = process.env.NODE_ENV
const development = MODE === 'development'

/** @type {import('@sveltejs/kit').Config} */

const config: UserConfig = {
plugins: [
sveltekit(),
development &&
nodePolyfills({
include: ['node_modules/**/*.js', new RegExp('node_modules/.vite/.*js'), 'http', 'crypto']
})
],
resolve: {
alias: {
crypto: 'crypto-browserify',
stream: 'stream-browserify',
assert: 'assert'
}
},
build: {
rollupOptions: {
external: ['@web3-onboard/*'],
plugins: [
nodePolyfills({ include: ['crypto', 'http'] }),
inject({ Buffer: ['Buffer', 'Buffer'] })
]
},
commonjsOptions: {
transformMixedEsModules: true
}
},
optimizeDeps: {
exclude: ['@ethersproject/hash', 'wrtc', 'http'],
include: [
'@web3-onboard/core',
'@web3-onboard/gas',
'@web3-onboard/sequence',
'js-sha3',
'@ethersproject/bignumber'
],
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
}
}
},
define: {
global: 'window'
}
}

export default config
```

### Vite

Checkout a boilerplate example for Vite-React (here)[https://github.com/blocknative/web3-onboard/tree/develop/examples/with-vite-react]

Add the following dev dependencies:

`npm i --save-dev rollup-plugin-polyfill-node`
Expand All @@ -1402,9 +1497,7 @@ export default {
plugins: [
development &&
nodePolyfills({
include: ['node_modules/**/*.js', new RegExp('node_modules/.vite/.*js')],
http: true,
crypto: true
include: ['node_modules/**/*.js', new RegExp('node_modules/.vite/.*js'), 'http', 'crypto']
})
],
resolve: {
Expand All @@ -1416,11 +1509,34 @@ export default {
},
build: {
rollupOptions: {
plugins: [nodePolyfills({ crypto: true, http: true })]
external: ['@web3-onboard/*'],
plugins: [
nodePolyfills({ include: ['crypto', 'http'] }),
inject({ Buffer: ['Buffer', 'Buffer'] })
]
},
commonjsOptions: {
transformMixedEsModules: true
}
},
optimizeDeps: {
exclude: ['@ethersproject/hash', 'wrtc', 'http'],
include: [
'@web3-onboard/core',
'@web3-onboard/gas',
'@web3-onboard/sequence',
'js-sha3',
'@ethersproject/bignumber'
],
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
}
}
},
define: {
global: 'window'
}
}
```
Expand All @@ -1437,6 +1553,11 @@ build: {

### Next.js

Checkout a boilerplate example for NextJS v13 (here)[https://github.com/blocknative/web3-onboard/tree/develop/examples/with-nextjs-13]

Checkout a boilerplate example for NextJS (here)[https://github.com/blocknative/web3-onboard/tree/develop/examples/with-nextjs]


:::admonition type=note

If you are seeing an error during builds when dynamically importing Web3Onboard in a NextJS v13 project, try upgrading to to the Canary beta release of NextJS where this issue is fixed.
Expand Down
Loading