Tree Shaking in Kite
Tree shaking is an advanced optimization technique that removes unused code from your final bundle. Kite 3.1.0 introduces individually exported factory functions, allowing bundlers like webpack, Rollup, and esbuild to eliminate code you don’t use.
Why Kite’s Tree Shaking Matters
Kite is already 10X smaller than other Solana Kit frameworks at ~100KB compressed (310KB unpacked). With tree shaking support, advanced users can reduce their bundle size even further by importing only the functions they need.
While other frameworks like Gill also support tree shaking, Kite starts 10X smaller, meaning your optimized bundle is still significantly leaner than the competition.
How Tree Shaking Works in Kite 3.1.0
Starting in version 3.1.0, all Kite factory functions are exported individually from src/index.ts. The package.json includes "sideEffects": false, signaling to bundlers that all modules can be safely tree-shaken.
Using Tree Shaking
Traditional Import (Imports Everything)
import { connect } from "solana-kite";
const connection = connect("devnet");
// This imports the entire Kite libraryOptimized Import (Tree Shakeable)
import { createSolanaRpc } from "@solana/kit";
import {
getMintFactory,
transferTokensFactory,
getTokenAccountBalanceFactory
} from "solana-kite";
// Create RPC connection
const rpc = createSolanaRpc("https://api.devnet.solana.com");
// Create only the functions you need
const getMint = getMintFactory(rpc);
const transferTokens = transferTokensFactory(rpc);
const getTokenAccountBalance = getTokenAccountBalanceFactory(rpc);
// Use them
const mint = await getMint(mintAddress);Available Factory Functions
Kite 3.1.0 exports these factory functions for tree shaking:
SOL Functions
airdropIfRequiredFactorygetLamportBalanceFactorywatchLamportBalanceFactorytransferLamportsFactory
Token Functions
getMintFactorygetTokenAccountAddressFactorycreateTokenMintFactorymintTokensFactorytransferTokensFactorygetTokenAccountBalanceFactorycheckTokenAccountIsClosedFactorygetTokenMetadataFactoryburnTokensFactorycloseTokenAccountFactorywatchTokenBalanceFactorygetTokenAccountsFactory⭐ NEW in 3.1.0
Transaction & RPC Functions
getLogsFactorygetExplorerLinkFactorysendTransactionFromInstructionsFactorysendTransactionFromInstructionsWithWalletAppFactorygetLatestBlockhashFactorycheckHealthFactorygetCurrentSlotFactorygetMinimumBalanceFactorygetTransactionFactory
Wallet & Account Functions
createWalletFactorycreateWalletsFactorygetAccountsFactoryFactory
When to Use Tree Shaking
Use tree shaking when:
- You’re building for production and need the absolute smallest bundle size
- You’re using only a subset of Kite’s features
- You’re comfortable working with individual factory functions
- You have an advanced build pipeline with tree shaking configured
Stick with standard imports when:
- You’re prototyping or in early development
- You’re using many Kite functions
- You want the simplest developer experience
- Bundle size isn’t your primary concern (Kite is already small!)
Bundler Configuration
Most modern bundlers support tree shaking by default in production mode:
Webpack 5+
Tree shaking is automatic when mode: 'production'
Vite/Rollup
Tree shaking is enabled by default
esbuild
Use --tree-shaking=true (default in bundle mode)
Measuring Bundle Size Impact
To measure the impact of tree shaking:
# Webpack
npx webpack-bundle-analyzer dist/stats.json
# Vite
npm run build -- --report
# Or use bundlephobia
npx bundlephobia solana-kiteRelated Documentation
- Connecting to Solana RPC - Standard connection method
- Package Comparisons - Size comparisons with other frameworks