Original address: Http://www.oschina.net/p/browserify
Browserify allows you to organize your browser-side JavaScript code in a way that is similar to Node's require (), which allows front-end JavaScript to directly use some of the libraries that node NPM installs.
Installation:
Install -G browserify
Example
This is the content of Main.js, which uses require () to load libraries and files as normal Nodejs programs:
var foo = require ('./foo.js '); var bar = require ('.. /lib/bar.js '); var gamma = require (' gamma '); var elem = document.getElementById (' result '); var x = foo (+) + bar (' baz '= gamma (x);
How to export:
function return n * 111}
Compile with browserify:
$ browserify main.js > Bundle.js
All other files required by Main.js are now compiled into bundle.js, including many layers of require () that are recursively compiled together.
Compiled JS can be used directly to the browser.
<src= "Bundle.js"></script>
Go browserify--using node. js for modular loading of JS