Skip to content

Commit

Permalink
feat(webpack): add fallback for optional wallet dependencies (#307)
Browse files Browse the repository at this point in the history
- Add `webpackFallback` object
- Export `webpackFallback` from index.ts
- Update Next.js example app
  • Loading branch information
drichar authored Oct 25, 2024
1 parent 6598e1c commit 32baa7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
13 changes: 3 additions & 10 deletions examples/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { webpackFallback } from '@txnlab/use-wallet-react'

/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config, { isServer }) => {
Expand All @@ -14,16 +16,7 @@ const nextConfig = {
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
'@agoralabs-sh/avm-web-provider': false,
'@algorandfoundation/liquid-auth-use-wallet-client': false,
'@blockshake/defly-connect': false,
'@magic-ext/algorand': false,
'@perawallet/connect': false,
'@perawallet/connect-beta': false,
'@walletconnect/modal': false,
'@walletconnect/sign-client': false,
'lute-connect': false,
'magic-sdk': false
...webpackFallback
}
}
return config
Expand Down
1 change: 1 addition & 0 deletions packages/use-wallet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export { WalletManager, WalletManagerConfig, WalletManagerOptions } from './mana
export { NetworkId } from './network'
export { State, WalletState, defaultState } from './store'
export { StorageAdapter } from './storage'
export { webpackFallback } from './webpack'
export * from './wallets'
19 changes: 19 additions & 0 deletions packages/use-wallet/src/webpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Fallback configuration for Webpack to handle optional wallet dependencies.
* This allows applications to build without these packages installed,
* enabling users to include only the wallet packages they need.
* Each package is set to 'false', which means Webpack will provide an empty module
* if the package is not found, preventing build errors for unused wallets.
*/
export const webpackFallback = {
'@agoralabs-sh/avm-web-provider': false,
'@algorandfoundation/liquid-auth-use-wallet-client': false,
'@blockshake/defly-connect': false,
'@magic-ext/algorand': false,
'@perawallet/connect': false,
'@perawallet/connect-beta': false,
'@walletconnect/modal': false,
'@walletconnect/sign-client': false,
'lute-connect': false,
'magic-sdk': false
}

0 comments on commit 32baa7f

Please sign in to comment.