Zayne Labs Toolkit is designed from the ground up to be fully tree-shakeable, ensuring you only bundle the code you actually use. This guide explains how tree-shaking works and how to get the most out of it.
All functions and utilities are exported as named exports from barrel files (index.ts), making them individually tree-shakeable:
packages/toolkit-core/src/index.ts
export * from "./checkIsDeviceMobile";export * from "./common-utils";export * from "./compare";export * from "./constants";export * from "./copyToClipboard";export * from "./createBatchManager";export * from "./createExternalStorageStore";// ... and more
Always use named imports instead of namespace imports:
// Good - Tree-shakeableimport { debounce, throttle } from "@zayne-labs/toolkit-core";// Bad - Imports everythingimport * as toolkit from "@zayne-labs/toolkit-core";
2
Import from specific subpaths
For the React package, import from the most specific path:
// Good - Only utils are bundledimport { composeRefs } from "@zayne-labs/toolkit-react/utils";// Less optimal - Might include hooks codeimport { composeRefs } from "@zayne-labs/toolkit-react";
3
Use type imports
Always use the type keyword for type-only imports:
// Good - Zero runtime overheadimport type { Prettify } from "@zayne-labs/toolkit-type-helpers";// Unnecessary - Same result but less explicitimport { Prettify } from "@zayne-labs/toolkit-type-helpers";
4
Install only what you need
Only install the packages you actually use:
# If you only need core utilitiespnpm add @zayne-labs/toolkit-core# If you need React hookspnpm add @zayne-labs/toolkit-core @zayne-labs/toolkit-react