# Tree Shaking

> A build step that drops code you imported but never used.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Dead Code Elimination, Tree-Shaking

## Think of it like

Think of it like shaking an apple tree so the dead leaves fall off. Only the living parts stay.

## Definition

Tree shaking is a build step that removes code you import but never use. A bundler follows which functions each file really calls. Anything that is never reached is left out of the final bundle. This matters because big libraries may hold hundreds of functions when you use three. It works best with modern import and export syntax.

## Example

Emma imports one date function from a large library. Tree shaking keeps that one function and drops the other 200.

## Why it matters

It keeps bundles small even when you use big libraries. Smaller bundles mean faster pages.

## Common mistake

Importing a whole library with one star import. Some tools then cannot tell what you use, and keep it all.

## Three principles

- **Unused code goes.** Only what is called stays.
- **Done by the bundler.** At build time.
- **Needs clean imports.** Import only what you use.

## Related terms

- [JavaScript Bundler](https://learn.benibix.com/term/development/bundler)
- [Minification](https://learn.benibix.com/term/development/minification)
- [Software Library](https://learn.benibix.com/term/development/library)
- [Vite](https://learn.benibix.com/term/development/vite)
- [Dead Code Detection](https://learn.benibix.com/term/development/dead-code-detection)

## Told apart from

- [Minification vs Tree Shaking](https://learn.benibix.com/compare/minification-vs-tree-shaking): Both make code files smaller. Minification squeezes code by cutting spaces and long names. Tree shaking drops whole parts of code that are never used.

---

Source: https://learn.benibix.com/term/development/tree-shaking
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
