View all files | ||||
browserify tree shaking plugin based on common-shake, the CommonJS tree shaker originally by @indutny.
Comments out unused exports from CommonJS modules.
With input files:
This plugin will rewrite the files to:
Use a minifier on the output to remove the exports entirely.
With the browserify cli:
With the browserify Node API:
Note that using a minifier transform like uglifyify doesn't eliminate the commented-out exports. Transforms run before common-shakeify, so you have to use a minifier on the final bundle to remove the unused exports.
When true, print messages to stderr when exports are deleted, or the tree-shaker bails out on a module. Default false. The verbose flag only works when no custom handlers are passed, so if you're using eg. a custom onExportDelete you have to print these messages manually.
Handler called for every exported identifier that is being removed. filename is the path to the file that exports the identifier. exportName is the name of the identifier. Return false to bail and keep the identifier.
Handler called when a module cannot be tree-shaked for some reason. module is the Module object from common-shake. reasons is an array of reasons that caused this module to be deoptimised.
Handler called when tree-shaking is skipped entirely, usually because there is a dynamic require call in the source. reasons is an array of reasons for skipping tree-shaking.
Parse with this ecmaVersion as interpreted by acorn. (default: 10)