Snowpack: Enable better tree-shaking in builds

Created on 1 Jun 2020  路  2Comments  路  Source: snowpackjs/snowpack

Original Discussion: https://www.pika.dev/npm/snowpack/discuss/274
/cc @Ciantic, @FredKSchott

Currently, Snowpack installs every package into a single JS file. As a result, any non-treeshakable code in one package file infects the rest of the package. This means that large packages like fluentui end up not being tree-shakable when you go and build for production.

I can think of two solutions:

  1. Add back our tree-shaking install support, which tree-shakes as a part of installing your web_modules/ dependencies. This was removed since we thought we didn't need it anymore, but it may make sense to add back. This would force us to re-install dependencies on every build, which is a safer move as well but will slow down production builds a bit more than they are now.

  2. Stop using web_modules/ when you build with a bundler. This would give bundlers the highest-fidelity package code to bundle from, but at the expense of complicating how much bundler plugins now need to support. Different bundlers would handle dependencies differently, leading to confusion and complexity.

I'm leaning towards #1 to start, but open to feedback/thoughts.

Most helpful comment

As a person who bangs his head against the wall everytime when I have to deal with Webpack I plead for keeping it simple on configuration side. Please :)

All 2 comments

As a person who bangs his head against the wall everytime when I have to deal with Webpack I plead for keeping it simple on configuration side. Please :)

If the internal installer uses Rollup, I would think that using Rollup's tree-shaker would be the right choice when doing a build? Then we don't need webpack or other bundlers to do it again.

Edit Also I want to note that tree-shaking should be standardized, it's bad that there are multiple algorithms for it. It's difficult to test if any given package have broken the tree-shaking rules if it's algorithm is not set in stone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

backspaces picture backspaces  路  5Comments

mfolkeseth picture mfolkeseth  路  5Comments

FredKSchott picture FredKSchott  路  5Comments

FredKSchott picture FredKSchott  路  6Comments

FredKSchott picture FredKSchott  路  6Comments