-
Notifications
You must be signed in to change notification settings - Fork 0
Description
tldr; Update steal-tools build process to support tree shaking.
The RFC for this proposal was discussed on a recent live stream (1:16). It was also discussed on a previous live stream (38:52) and contributors meeting (1:05:29).
The Problem
When using 3rd party libraries you often are only using a portion of the functionality they provide. For example, if you are using a utility library that looks like:
hidash
export function intersection() {
...
}
export function flatten() {
...
}But you are only using one of these utility functions like so:
import { flatten } from "hidash";Even though you are only using one of the utility functions, your bundle will contain all of the code from this library's module.
The Solution
Tree shaking is a technique popularized by rollup that detects this unused code and "shakes" it away (and any code it depends on that is also not used elsewhere).
The other popular bundlers now support tree-shaking. We can piggyback on the libraries already created by others to support it as well.
- rollup is used internally by WebPack and the SystemJS Builder to treeshake ES modules
- common-shake is a utility that works with ASTs to tree-shake CommonJS code. As far as I know, no bundler currently uses this under the hood.
Tasks
- - Research how these libraries are used by bundlers to do treeshaking. I would think that they need access to the entire dependency graph, so we might need to plug this in as a transform that happens after transpile runs in steal-tools.
- - Create a couple of tests to show this working with ES and CommonJS modules.
- - Measure: I think presenting to the user how much wasted code was removed by using this technique will be a big benefit.