Nurbol Alpysbayev
Nurbol Alpysbayev

Reputation: 21931

Tree shaking: are unused functions included to a bundle?

Do modern bundlers like Webpack or Rollup shake out only unused modules or are they capable of removing unused functions (or variables, classes) inside a module as well?

// src.js
export function unused() {}
export function used() {} 

// bundle.js
// function unused() {}  // <-- will this be included?
function used() {} 

Searched on the subject but found nothing.

P.S. I've no experience with bundlers (other than zero-config Parcel) but I make the library that requires the answer to this question.

Upvotes: 4

Views: 1359

Answers (1)

Nurbol Alpysbayev
Nurbol Alpysbayev

Reputation: 21931

Turns out I've searched not well enough.

Here: https://medium.com/@netxm/what-is-tree-shaking-de7c6be5cadd the author says that unused functions won't be included.

Upvotes: 2

Related Questions