Closed reslear closed 7 months ago
mmm, we do tree shaking.
We also don't use the MM SDK internally, so that shouldn't be bundled unless you're using the Wagmi's MetaMask connector.
Adding the package as external will break the app as you're not bundling it.
It is interesting that this happens only during development, as for the build it does not happen, maybe it is a vite problem.
I found similar issues:
Current workaround: https://github.com/vitejs/vite/issues/6582
uses https://github.com/MilanKovacic/vite-plugin-externalize-dependencies
exclude specific dependencies from the Vite bundle during development.
// vite.config.ts
import externalize from 'vite-plugin-externalize-dependencies'
// ...
externalize({
externals: ['@wagmi/connectors'],
}),
// ...
Also, on the Web3Modal side, we need to:
I don't recommend that, you can however try
externals: ['@web3modal/siwe', '@walletconnect/modal', '@metamask/sdk']
tree shaking is not the same as dynamic import. We use package imports to tree shake unused hooks for other frameworks, but the rest we use pretty much everything.
Also, we use dynamic imports for the SIWE package, but this is still bundled, you will see it generates a chunk, but this won't be shipped to the browser because it's splitted.
You can also check for the JS size sent to the browser from the Network tab.
And better:
import { defineConfig } from 'vite'
import externalize from 'vite-plugin-externalize-dependencies'
// https://vitejs.dev/config/
export default defineConfig({
// https://github.com/WalletConnect/web3modal/issues/2159
// https://github.com/reslear/metakeep-wagmi-connector/blob/main/playground/vite.config.mts#L20
externalize({
externals: [
'@web3modal/siwe',
'@walletconnect/modal',
'@metamask/sdk',
'@coinbase/wallet-sdk',
],
}),
],
})
or add from wagmi/connectors:
@glitch-txs This solves my problem, I can close it. Also maybe needs add it to the FAQ.
Coinbase one is used by Web3Modal, if you remove it the coinbase wallet won't work on mobile. Of course it's up to you if you'd like to support it on mobile.
@glitch-txs
Yes, but it's solution just ONLY for local development - vite esbuild pre-bundling.
for build vite use rollup, and it's needs modify:
build: {
rollupOptions: {
output: {
manualChunks: {
Link to minimal reproducible example
https://stackblitz.com/edit/vitejs-vite-zxnq49?file=src%2FApp.vue
Summary
A simple template, for playback
we get chunk
chunk-22BZIRQV.js?v=998e5bee:39559
- 2,5mb :(and more, so this is
@wagmi/connectors
:So i found solution use ESM:
fork https://stackblitz.com/edit/vitejs-vite-bngsgj?file=vite.config.ts
but we got error:
same https://github.com/WalletConnect/walletconnect-utils/issues/134
so we need to prepare or customize vite so that it doesn't bandwidth huge files.
List of related npm package versions