Browserify (2024)

Table of Contents
More Community

Browsers don't have the require method defined, but Node.js does. With Browserify you can write code that uses require in the same way that you would use it in Node.

Here is a tutorial on how to use Browserify on the command line to bundle up a simple file called main.js along with all of its dependencies:

main.js

var unique = require('uniq');var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];console.log(unique(data));

Install the uniq module with npm:

npm install uniq

Now recursively bundle up all the required modules starting at main.js into a single file called bundle.js with the browserify command:

browserify main.js -o bundle.js

Browserify parses the AST for require() calls to traverse the entire dependency graph of your project.

Drop a single <script> tag into your html and you're done!

<script src="bundle.js"></script>

More

  • Read the Browserify Handbook
  • Use many of the tens of thousands of modules on NPM in the browser
  • Use watchify, a browserify compatible caching bundler, for super-fast bundle rebuilds as you develop.
  • Use tinyify for optimized, tree-shaked bundles in production environments.
  • Use --debug when creating bundles to have Browserify automatically include Source Maps for easy debugging.
  • Check out tools like Beefy or run-browser which make automating browserify development easier.
  • process.nextTick(), __dirname, and __filename node-isms work
  • Get browser versions of the node core libraries events, stream, path, url, assert, buffer, util, querystring, http, vm, and crypto when you require() them

Community

Join irc.freenode.net/#browserify for help, or tweet @browserify.

Browserify (2024)
Top Articles
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 5801

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.