You'll need to install Node.js and npm. Download here
Check that worked by running
npm and making sure it actually prints something out.
Install browserify with
npm install -g browserify
Install watchify with
npm install -g watchify
Step 1: Make sure prerequisites are installed, or install them if they are not.
Step 2: Set up your directory with npm init.
Step 3: Install any npm modules you'd like to use. In this example I used two modules.
npm install --save arithmetic npm install --save repeat-string
var arithmetic = require('arithmetic'); arithmetic.add(2, 4);
browserify newway.js -o bundle.jsIf you use browserify like this, you'll have to make a new bundle every time you make a change. To make it a bit easier, you can run this watchify command, which will create your new bundle every time you save your file.
watchify newway.js -o bundle.js
Step 6: Now you include a script tag with bundle.js
Include the script tag generated by the build tool.
<!-- Include a bundle which was generated. --> <script src="bundle.js"></script>