Skip to content

DCE unused modules #12

@divmain

Description

@divmain

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:

  1. Detect all ES^ imports/exports for all modules.
  2. Go through all modules and mark any imports as used.
  3. For any unused exports, transform exports.foo = foo... into foo... 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions