browserify-resolutions
v1.1.0
Published
A Browserify plugin that allows more explicit control of module deduping. It purges duplicate modules from the output bundle and prevents modules from loading several times.
Downloads
400
Maintainers
Readme
#browserify-resolutions Bower resolutions for npm + Browserify... sort of.
A Browserify plugin that allows more explicit control of module deduping. It purges duplicate modules from the output bundle and prevents modules from loading several times.
Why?
A large dependency tree may include multiple versions of the same module, which may result in it being bundled multiple times, greatly increasing the bundle's size.
What about npm dedupe
?
It can be sufficient, but is sometimes hamstrung as third party modules may be asking for incompatible versions of the same library.
What about peerDependencies
?
Hopefully solves this problem in the future, but currently difficult to work with: https://github.com/npm/npm/issues/6565
What about Browserify's own dedupe?
It currently only dedupes identical source files. Even if deduped, a library may be instantiated several times.
E.g., even if Angular is deduped and only bundled once, you may still see:
WARNING: Tried to load angular more than once.
How to use
Pass either an array of package names to dedupe or "*" to dedupe everything possible.
var resolutions = require('browserify-resolutions');
// Dedupe Angular
browserify(options)
.plugin(resolutions, ['angular'])
.bundle();
// Dedupe everything possible
browserify(options)
.plugin(resolutions, '*')
.bundle();
via Browserify CLI
browserify path-to-your-entry-file.js -p [ browserify-resolutions '*' ] -o path-to-your-destination.js