0

Given entry is the entry module:

enter image description here

It just uses function1 from external1 module.

I expected that external1.function2 and the whole external2 module would be eliminated.

However, my output includes external2.function1. Just.. why?

Here's a repo of the whole thing.

Daniel Birowsky Popeski
  • 8,752
  • 12
  • 60
  • 125

1 Answers1

0

tree shaking is not working perfectly since javascript in nature is dynamic language, so sometimes it does pessimistic guess given code maybe used in other places. in external1, you've imported everything from external2 via * as xxx from 'external2' - and that makes assumption to bundler given exported module might have reference in somewhere else and does not delete it.

OJ Kwon
  • 4,385
  • 1
  • 20
  • 24
  • if that was true, we would also see `external2.function2` in the output. but it's not the case. anyhow, i updated the repo to import only the specific function through `import {function1 as f1} from './external2';`. the output is the same. – Daniel Birowsky Popeski Jan 08 '18 at 17:19