title: Barrel file and Tree Shaking
body: <p><em>Here is an example repository that shows an example of the issue reported in this thread: <a href="https://github.com/Eux86/tree-shaking-barrel-test/blob/master/README.md" rel="noreferrer">https://github.com/Eux86/tree-shaking-barrel-test/blob/master/README.md</a></em></p>
  
  <p>I'm trying to understand what's the effect of using a Barrel file to export functions and classes from a library project when importing it into another project that use webpack and should be able to treeshake the bundle.</p>
  
  <p>Imagine I have a project:</p>
  
  <p>library</p>
  
  <ul>
  <li><p>index.ts</p></li>
  <li><p>libA.ts</p></li>
  <li><p>libB.ts</p></li>
  </ul>
  
  <p>index.ts has this code:</p>
  
  <pre><code>export { LibAMain } from 'LibA';
  export { LibBMain } from 'LibB';
  </code></pre>
  
  <p>So I'm using index as a barrel file to export all the functions I'm going to develop in my library.</p>
  
  <p>The second project will be:</p>
  
  <p>library-user</p>
  
  <ul>
  <li>index.ts</li>
  </ul>
  
  <p>Index.ts has this code: </p>
  
  <pre><code>import { LibAMain } from 'library'
  
  LibAMain();
  </code></pre>
  
  <p>Now: library-user is builded using webpack, which I expect to be able to treeshake the unused libraries in MyLib, but when I look into the generated bundle I see that it contains boot LibA.js and LibB.js, which shouldn't be there:</p>
  
  <p><a href="https://i.stack.imgur.com/znq1y.png" rel="noreferrer"><img src="https://i.stack.imgur.com/znq1y.png" alt="enter image description here"></a></p>
  
  <p>If I change index.ts to:</p>
  
  <pre><code>import { LibAMain } from 'library/lib/LibA'
  
  LibAMain();
  </code></pre>
  
  <p>then webpack does its job well and I only see LibA in the final bundle:</p>
  
  <p><a href="https://i.stack.imgur.com/asNGU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/asNGU.png" alt="enter image description here"></a></p>
  
  <p>TL;DR: How can I keep using the barrel index file and just import everything from 'library' but still have the treeshaking working?</p>
  
  <p>Thank you for any help :)</p>