Browserify is an awesome tool, which allows you to use node modules in your browser. Over 70% of the node modules will run right away! And it will bundle up all of your dependencies. If you want to find out more about writing CommonJS modules for Browserify have a look into the documentation.
This task has some additional utilities for handling errors and logging the bundling process. Put these into a util folder in your gulp folder:
Using CommonJS Modules
Writing CommonJS modules is quite nice. You just export your function, object, string, integer or whatever you like to export as a module or just individually:
Later you import your modules and use them:
Loading non-CommonJS files
I need to install browserify-shim:
$ npm install --save-dev firstname.lastname@example.org
I open my package.json file and need to add a few lines:
Within "browerify-shim" you decide where to map this require to. To include jQuery or Modernizr later you would write:
You have to run npm install once you added a new entry to your package.json file.