interlockjs / interlock

JS bundler - inspired by Git, built on Babel.
MIT License
72 stars 7 forks source link

Tree Shaking plugin #60

Closed divmain closed 8 years ago

divmain commented 8 years ago

As modules are recursively resolved and generated, the plugin should track an esImported value for every module that is found.

The esImported value will be false in either of the following conditions:

However, the esImported value will be a truthy array if the module was only ever imported like import { subFeature } from "./bar" or import { otherFeature } from "./bar". In this case, the esImported value will be an array with string elements "subFeature" and "otherFeature".

After all modules have been resolved and generated, the plugin will take another pass over each module, looking for export nodes at the root level of the AST. For each module with a truthy esImported value, any export nodes that do not match an element in the esImported array will be removed.

Lastly, sub-dependencies that are no longer needed must be detected and removed from all dependency lists. This is because the function that consumed a particular dependency may have been purged. Some investigation may be necessary to ensure that we don't just implement a minifier. If it proves to be too difficult, we should have a two-stage process - one step before a minifier is applied and one step after, at which point any removed requires would have to be detected.

Notes:

divmain commented 8 years ago

Moved to interlockjs/plugins#11.