What is Tree Shaking?
Turkish: Tree Shaking
Tree shaking analyzes the ES module dependency graph and removes unused exports from the production JavaScript bundle.
What is Tree Shaking?
Tree shaking tries to include only the parts of imported JavaScript modules that are actually used by an application. The name comes from the idea of shaking dead branches out of a tree.
How Does It Work?
Modern bundlers can statically analyze ES module syntax. If code imports formatDate from a date utility module, the bundler may exclude other unused exports from the production bundle.
Tree shaking depends on understanding side effects correctly. The sideEffects field in package.json, CommonJS require, dynamic import patterns, and top-level code that runs on import can all affect the result.
Where Is It Used?
Tools such as Webpack, Rollup, and Vite apply tree shaking. It is especially useful with large UI libraries, utility packages, and icon sets, where removing unused code can reduce page load time and JavaScript parsing cost.
Tree shaking is not the whole performance strategy. It should be combined with code splitting, lazy loading, dependency cleanup, and bundle analysis.