Browserify is a pretty slick tool that lets
developers use node.js-style
This gives significant advantages such as importing libraries from the
thousands available on npm or being able to run unit
tests headlessly in node.
Using a module system like Browserify and
require is one of the many
accidentally leak variables into the global scope. But sometimes the whole
purpose of a library is to do exactly that: export a namespaced set of
objects that other scripts can use. If all of the developer’s code is hidden
inside a closure and accessed internally through
require, how can other third
party scripts use the library?
But there’s no reason a developer couldn’t just export the required modules manually. All
she has to do is include an
exports.js script that sticks
window object. Putting them all in an
exports.js file sends a
clear signal that the referenced modules are meant for public consumption.
Something like the following is usually sufficient.
Now third-party or other external scripts will be able to access the exported
modules right off the