Overview
Univerto is designed from the ground up for optimal tree-shaking. The library uses a modular export structure that allows modern bundlers to eliminate unused code, ensuring you only ship what you use.Modular Export Structure
Univerto provides separate export paths for each unit converter instead of a single monolithic import. This architecture enables bundlers to perform effective dead code elimination.Available Export Paths
Each converter has its own subpath export:Bundle Size Impact
❌ Avoid Barrel Imports
Don’t import from the main entry point if you only need specific converters:✅ Use Specific Imports
Import only what you need from subpaths:Bundle Size Comparison
| Import Strategy | Approximate Bundle Size |
|---|---|
Single converter (e.g., univerto/time) | ~2-3 KB (minified + gzipped) |
| Three converters (e.g., time, length, mass) | ~6-8 KB (minified + gzipped) |
| All converters via barrel import | ~15-20 KB (minified + gzipped) |
Exact bundle sizes depend on your bundler configuration and which converters you import. The library itself has zero dependencies, so there are no transitive dependency costs.
How It Works
Univerto’spackage.json defines explicit export maps for each converter:
- Resolve the exact file for each subpath
- Analyze which files are actually imported
- Eliminate code from unused files during the build
Best Practices
Import by subpath
Always use specific subpath imports like
univerto/time rather than the main univerto entryImport only what you need
If your app only converts time units, only import the time converter
Use named imports
Use
import { TimeUnitConverter } rather than import * to help bundlers identify used exportsCheck bundle analyzer
Use tools like webpack-bundle-analyzer to verify Univerto’s size in your production bundle
Bundler Configuration
Vite
Vite supports tree-shaking out of the box with ES modules. No configuration needed:Webpack 5
Webpack 5 has improved tree-shaking with thesideEffects flag. Univerto sets "sideEffects": false in its package.json, indicating all modules are safe to tree-shake:
Rollup
Rollup excels at tree-shaking ES modules:esbuild
esbuild performs tree-shaking automatically:Verifying Tree-Shaking
Using Webpack Bundle Analyzer
Using Rollup Plugin Visualizer
Zero Dependencies Advantage
Univerto has zero runtime dependencies. This means:- No dependency tree to manage
- No transitive dependency security vulnerabilities
- No version conflicts with your other packages
- Smaller total bundle size
- Faster npm install times
Related Topics
Installation
Learn how to install Univerto
TypeScript Support
Explore TypeScript integration and type safety