As I’ve mentioned earlier I’m on a Browserify kick and thus exploring the available transform modules for it. One of them is browserify-shim, which let’s you make CommonJS incompatible files “browserifyable”.
Let’s say we have a library that’s exposes itself as
easiest way to use it with Browserify and browserify-shim is to add this to our
This will make browserify-shim replace
var module = require('module') with
var module = (typeof window !== "undefined" ? window.Module : typeof global !==
"undefined" ? global.Module : null) in all the places that you’ve required
Integrating Browserify and browserify-shim with gulp is
pretty straightforward. Given that we’ve added the above configuration to our
package.json file, all we need to add in our
gulpfile.js file is this:
Now let’s say that we want to minify our code. The easiest way to do this would be to add another transform module, uglifyify:
We could also integrate it directly in our
gulpfile.js file, but that requires
more modules and a bit more code.
The above setup is probably the fastest way of getting up and running, which I find preferable when just I want to experiment with a couple of libraries.