The problem:
Browserify makes your frontend javascript more modularized and it helps to organize the frontend codes
much better. But only use browserify is not enough if you are using some legacy libs. Which means such
libs are not qualified for npm publication. for example some libs just simply use a global variable: window.Module
Introduce to browserify-shim:
For those libs which expose themselves as window.Module
, add the following to your package.json
:
1 | "browserify": { "transform": [ "browserify-shim" ] }, "browserify-shim": { "module": "global:Module", } |
What browserify-shim does here is it replaces:
1
var module = require('module')
with:
1
var module = (typeof window !== "undefined" ? window.Module : typeof global !== "undefined" ? global.Module : null)