Package Exports
- browserify-shim
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (browserify-shim) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
browserify-shim 
Shims modules that aren't installed as npm
modules so they can be browserified even if they aren't commonJS
compatible.
var browserify = require('browserify')
, shim = require('browserify-shim');
var bundled = browserify({ debug: true })
// jquery attaches itself to the window as '$' so we assign the exports accordingly
.use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', exports: '$' }))
// underscore is commonJS compliant, so no further export is needed which we specify by assigning exports 'null'
.use(shim({ alias: 'underscore', path: './js/vendor/underscore.js', exports: null }))
.addEntry('./js/entry.js')
.bundle()
// it is important to call shim after bundle in order to inject shims registered via .use(shim(..))
.shim();
fs.writeFileSync(builtFile, bundled);
Install
npm install browserify-shim
Features
- shims non commonJS modules in order for them to be browserified by specifying an alias, the path to the file and
the identifier under which the module attaches itself to the global
window
object - handles even those modules out there that just declare a
var foo = ...
on the script level and assume it gets attached to thewindow
object since the only way they will ever be run is in the global context - "ahem, ... NO?!" - loads commonJS modules that are not residing in your
node_modules
from a specific path