DCE unused modules
divmain opened this issue · 0 comments
divmain commented
360d7b3 added basic tree-shaking functionality. However, as implemented, modules that come away completely unused (and their dependencies) are still included in the module bundles.
-
detect which modules exclusively use ES6 exports - of those, detect which modules have ZERO used exports, and mark these for removal
-
for all other modules (which aren't removed, or which use non-ES6 exports), track its dependencies and mark these to keep - after all modules have been examined, check for any deep dependencies that aren't marked as keep, and remove them also
- determine what to do for bundles whose entry points have been DCE'd
Edit: Took a simpler approach to this:
- Detect all ES^
import
s/export
s for all modules. - Go through all modules and mark any imports as used.
- For any unused exports, transform
exports.foo = foo...
intofoo...
so that it can be removed by a minifier.
This succeeds in removing unused exports from modules. However, this doesn't help determine which sub-dependencies are no longer needed. Need to take another pass at this to come up with a clever way to detect and remove the unused modules from the build.