browserify require('modules') in the browser Use a node-style require() to organize your browser code and load modules installed by npm. browserify will recursively analyze all the require() calls in your…
browserify
require('modules') in the browser
Use a node-style require() to organize your browser code
and load modules installed by npm.
browserify will recursively analyze all the require() calls in your app in
order to build a bundle you can serve up to the browser in a single `
tag.


getting started
If you're new to browserify, check out the
browserify handbook
and the resources on browserify.org.
example
Whip up a file, main.js with some require()s in it. You can use relative'./foo.js'
paths like and '../lib/bar.js' or module paths like 'gamma'node_modules/
that will search using
node's module lookup algorithm.
js
var foo = require('./foo.js');
var bar = require('../lib/bar.js');
var gamma = require('gamma');
var elem = document.getElementById('result');
var x = foo(100) + bar('baz');
elem.textContent = gamma(x);
Export functionality by assigning onto module.exports or exports:
js
module.exports = function (n) { return n * 111 }
Now just use the browserify command to build a bundle starting at main.js:
$ browserify main.js > bundle.js
All of the modules that main.js needs are included in the bundle.js from arequire()
recursive walk of the graph using
required.
To use this bundle, just toss a into your
html!
install
With npm do:
npm install browserify
usage
Usage: browserify [entry files] {OPTIONS}
Standard Options:
--outfile, -o Write the browserify bundle to this file.
If unspecified, browserify prints to stdout.
--require, -r A module name or file to bundle.require()
Optionally use a colon separator to set the target.
--entry, -e An entry point of your app
--ignore, -i Replace a file with an empty stub. Files can be globs.
--exclude, -u Omit a file from the output bundle. Files can be globs.
--external, -x Reference a file from another bundle. Files can be globs.
--transform, -t Use a transform module on top-level files.
--command, -c Use a transform command on top-level files.
--standalone -s Generate a UMD bundle for the supplied export name.
This bundle works with other module systems and sets the name
given as a window global if no module system is found.
--debug -d Enable source maps that allow you to debug your files
separately.
--help, -h Show this message
For advanced options, type `browserify --help advanced`.
Specify a parameter.
Advanced Options:
--insert-globals, --ig, --fast [default: false]
Skip detection and always insert definitions for process, global,
__filename, and __dirname.
benefit: faster builds
cost: extra bytes
--insert-global-vars, --igv
Comma-separated list of global variables to detect and define.
Default: __filename,__dirname,process,Buffer,global
--detect-globals, --dg [default: true]
Detect the presence of process, global, __filename, and __dirname and define
these values when present.
benefit: npm modules more likely to work
cost: slower builds
--ignore-missing, --im [default: false]
Ignore `require()` statements that don't resolve to anything.
--noparse=FILE
Don't parse FILE at all. This will make bundling much, much faster for giant
libs like jquery or threejs.
--no-builtins
Turn off builtins. This is handy when you want to run a bundle in node which
provides the core builtins.
--no-commondir
Turn off setting a commondir. This is useful if you want to preserve the
original paths that a bundle was generated with.
--no-bundle-external
Turn off bundling of all external modules. This is useful if you only want
to bundle your local files.
--bare
Alias for both --no-builtins, --no-commondir, and sets --insert-global-vars
to just "__filename,__dirname". This is handy if you want to run bundles in
node.
--no-browser-field, --no-bf
Turn off package.json browser field resolution. This is also handy if you
need to run a bundle in node.
--transform-key
Instead of the default package.json#browserify#transform field to list
all transforms to apply when running browserify, a custom field, like, e.g.
package.json#browserify#production or package.json#browserify#staging
can be used, by for example running:
* `browserify index.js --transform-key=production > bundle.js`
* `browserify index.js --transform-key=staging > bundle.js`
--node
Alias for --bare and --no-browser-field.
--full-paths
Turn off converting module ids into numerical indexes. This is useful for
preserving the original paths that a bundle was generated with.
--deps
Instead of standard bundle output, print the dependency array generated by
module-deps.
--no-dedupe
Turn off deduping.
--list
Print each file in the dependency graph. Useful for makefiles.
--extension=EXTENSION
Consider files with specified EXTENSION as modules, this option can used
multiple times.
--global-transform=MODULE, -g MODULE
Use a transform module on all files after any ordinary transforms have run.
--ignore-transform=MODULE, -it MODULE
Do not run certain transformations, even if specified elsewhere.
--plugin=MODULE, -p MODULE
Register MODULE as a plugin.
Passing arguments to transforms and plugins:
For -t, -g, and -p, you may use subarg syntax to pass options to the
transforms or plugin function as the second parameter. For example:
-t [ foo -x 3 --beep ]
will call the `foo` transform for each applicable file by calling:
foo(file, { x: 3, beep: true })
compatibility
Many npm modules that don't do IO will just work after being
browserified. Others take more work.
Many node built-in modules have been wrapped to work in the browser, but only
when you explicitly require() or use their functionality.
When you require() any of these modules, you will get a browser-specific shim:
- assert
- buffer
- console
- constants
- crypto
- domain
- events
- http
- https
- os
- path
- punycode
- querystring
- stream
- string_decoder
- timers
- tty
- url
- util
- vm
- zlib
- process
- Buffer
- global - top-level scope object (window)
- __filename - file path of the currently executing file
- __dirname - directory path of the currently executing file
more examples
external requires
You can just as easily create a bundle that will export a require() function sorequire()
you can modules from another script tag. Here we'll create abundle.js with the through
and duplexer modules.
$ browserify -r through -r duplexer -r ./my-file.js:my-module > bundle.js
Then in your page you can do:
html
var through = require('through');
var duplexer = require('duplexer');
var myModule = require('my-module');
/* ... */
external source maps
If you prefer the source maps be saved to a separate .js.map source map file, you may use
exorcist in order to achieve that. It's as simple as:
$ browserify main.js --debug | exorcist bundle.js.map > bundle.js
Learn about additional options here.
multiple bundles
If browserify finds a required function already defined in the page scope, it
will fall back to that function if it didn't find any matches in its own set of
bundled modules.
In this way, you can use browserify to split up bundles among multiple pages to
get the benefit of caching for shared, infrequently-changing modules, while
still being able to use require(). Just use a combination of --external and--require to factor out common dependencies.
For example, if a website with 2 pages, beep.js:
js
var robot = require('./robot.js');
console.log(robot('beep'));
and boop.js:
js
var robot = require('./robot.js');
console.log(robot('boop'));
both depend on robot.js:
js
module.exports = function (s) { return s.toUpperCase() + '!' };
$ browserify -r ./robot.js > static/common.js
$ browserify -x ./robot.js beep.js > static/beep.js
$ browserify -x ./robot.js boop.js > static/boop.js
Then on the beep page you can have:
html
while the boop page can have:
html
This approach using -r and -x works fine for a small number of split assets,
but there are plugins for automatically factoring out components which are
described in the
partitioning section of the browserify handbook.
api example
You can use the API directly too:
js
var browserify = require('browserify');
var b = browserify();
b.add('./browser/main.js');
b.bundle().pipe(process.stdout);
methods
js
var browserify = require('browserify')
browserify([files] [, opts])
Returns a new browserify instance.
files
String, file object, or array of those types (they may be mixed) specifying entry file(s).
opts
Object.
files and opts are both optional, but must be in the order shown if both are
passed.
Entry files may be passed in files and / or opts.entries.
External requires may be specified in opts.require, accepting the same formatsfiles
that the argument does.
If an entry file is a stream, its contents will be used. You should pass
opts.basedir when using streaming files so that relative requires can be
resolved.
opts.entries has the same definition as files.
opts.noParse is an array which will skip all require() and global parsing for
each file in the array. Use this for giant libs like jquery or threejs that
don't have any requires or node-style globals but take forever to parse.
opts.transform is an array of transform functions or modules names which will
transform the source code before the parsing.
opts.ignoreTransform is an array of transformations that will not be run,
even if specified elsewhere.
opts.plugin is an array of plugin functions or module names to use. See the
plugins section below for details.
opts.extensions is an array of optional extra extensions for the module lookup.js
machinery to use when the extension has not been specified.
By default browserify considers only and .json files in such cases.
opts.basedir is the directory that browserify starts bundling from for.
filenames that start with .
opts.paths is an array of directories that browserify searches when lookingbasedir
for modules which are not referenced using relative path. Can be absolute or
relative to . Equivalent of setting NODE_PATH environmental variablebrowserify
when calling command.
opts.commondir sets the algorithm used to parse out the common paths. Usefalse to turn this off, otherwise it uses the
commondir module.
opts.fullPaths disables converting module ids into numerical indexes. This is
useful for preserving the original paths that a bundle was generated with.
opts.builtins sets the list of built-ins to use, which by default is set inlib/builtins.js in this distribution.
opts.bundleExternal boolean option to set if external modules should be
bundled. Defaults to true.
When opts.browserField is false, the package.json browser field will beopts.browserField
ignored. When is set to a string, then a custom field name"browser"
can be used instead of the default field.
When opts.insertGlobals is true, always insert process, global,__filename, and __dirname without analyzing the AST for faster builds but
larger output bundles. Default false.
When opts.detectGlobals is true, scan all files for process, global,__filename, and __dirname, defining as necessary. With this option npm
modules are more likely to work but bundling takes longer. Default true.
When opts.ignoreMissing is true, ignore require() statements that don't
resolve to anything.
When opts.debug is true, add a source map inline to the end of the bundle.
This makes debugging easier because you can see all the original files if
you are in a modern enough browser.
When opts.standalone is a non-empty string, a standalone module is created.
with that name and a umd wrapper.
You can use namespaces in the standalone global export using a in the string'A.B.C'
name as a separator, for example . The global export will be sanitized
and camel cased.
Note that in standalone mode the require() calls from the original source willrequire()
still be around, which may trip up AMD loaders scanning for calls.
You can remove these calls with
derequire:
$ npm install derequire
$ browserify main.js --standalone Foo | derequire > bundle.js
html
// Now you can address `Foo` by name in your HTML document
Foo.bar();
opts.insertGlobalVars will be passed toopts.vars
insert-module-globals
as the parameter.
opts.externalRequireName defaults to 'require' in expose mode but you can
use another name.
opts.bare creates a bundle that does not include Node builtins, and does not__dirname
replace global Node variables except for and __filename.
opts.node creates a bundle that runs in Node and does not use the browser{ bare: true, browserField: false }`.
versions of dependencies. Same as passing
Note that if files do not contain javascript source code then you also need to
specify a corresponding transform for them.
All other options are forwarded along to
module-deps
and [browser-pack](https
…
Members
-
browserify ★ PINNED
browser-side require() the node.js way
JavaScript ★ 15k 1y agoExplain → -
browserify-handbook ★ PINNED
how to build modular applications with browserify
JavaScript ★ 4.6k 1y agoExplain → -
watchify ★ PINNED
watch mode for browserify builds
JavaScript ★ 1.8k 1y agoExplain → -
brfs ★ PINNED
browserify fs.readFileSync() static asset inliner
JavaScript ★ 557 1y agoExplain → -
tinyify ★ PINNED
a browserify plugin that runs various optimizations, so you don't have to install them all manually. makes your bundles tiny!
JavaScript ★ 408 2mo agoExplain → -
resolve ★ PINNED
Implements the node.js require.resolve() algorithm
JavaScript ★ 796 12d agoExplain → -
events
Node's event emitter for all engines.
JavaScript ★ 1.4k 1y agoExplain → -
crypto-browserify
partial implementation of node's `crypto` for the browser
JavaScript ★ 681 7mo agoExplain → -
wzrd.in
browserify as a service.
JavaScript ★ 637 1y agoExplain → -
browserify-website
the code that runs http://browserify.org
HTML ★ 598 1y agoExplain → -
rustify
Rust WebAssembly transform for Browserify
JavaScript ★ 492 1y agoExplain → -
webworkify
launch a web worker that can require() in the browser with browserify
JavaScript ★ 420 1y agoExplain → -
detective
Find all calls to require() no matter how deeply nested using a proper walk of the AST
JavaScript ★ 415 1y agoExplain → -
factor-bundle
factor browser-pack bundles into common shared bundles
JavaScript ★ 398 1y agoExplain → -
commonjs-assert
Node.js's require('assert') for all engines
JavaScript ★ 301 1y agoExplain → -
sha.js
Streamable SHA hashes in pure javascript
JavaScript ★ 297 8mo agoExplain → -
node-util
node.js util module as a module
JavaScript ★ 254 1y agoExplain → -
http-browserify
node's http module, but for the browser
JavaScript ★ 245 1y agoExplain → -
module-deps
walk the dependency graph to generate a stream of json output
JavaScript ★ 208 1y agoExplain → -
vm-browserify
require('vm') like in node but for the browser
JavaScript ★ 206 1y agoExplain → -
pbkdf2
PBKDF2 with any supported hashing algorithm in Node
JavaScript ★ 202 1mo agoExplain → -
bundle-collapser
convert bundle paths to IDs to save bytes in browserify bundles
JavaScript ★ 193 1y agoExplain → -
path-browserify
The path module from Node.js for browsers
JavaScript ★ 192 1y agoExplain → -
static-eval
evaluate statically-analyzable expressions
JavaScript ★ 177 1y agoExplain → -
browser-pack
pack node-style source files from a json stream into a browser bundle
JavaScript ★ 173 1y agoExplain → -
stream-browserify
the stream module from node core for browsers
JavaScript ★ 105 1y agoExplain → -
common-shakeify
browserify tree shaking plugin using `common-shake`
JavaScript ★ 104 4d agoExplain → -
randombytes
random bytes from browserify stand alone
JavaScript ★ 102 1y agoExplain → -
browser-resolve
resolve function which support the browser field in package.json
JavaScript ★ 101 1y agoExplain → -
awesome-browserify
:crystal_ball: A curated list of awesome Browserify resources, libraries, and tools.
★ 100 9y agoExplain → -
diffie-hellman
pure js diffie-hellman
JavaScript ★ 95 1y agoExplain → -
syntax-error
detect and report syntax errors in source code strings
JavaScript ★ 81 1y agoExplain → -
static-module
convert module usage to inline expressions
JavaScript ★ 75 1y agoExplain → -
ify-loader
Webpack loader to handle browserify transforms as intended.
JavaScript ★ 68 1y agoExplain → -
browserify-aes
aes, for browserify
JavaScript ★ 62 1y agoExplain → -
createHmac
Node style HMAC for use in the browser, with native implementation in node
JavaScript ★ 61 1y agoExplain → -
browser-unpack
parse a bundle generated by browser-pack
JavaScript ★ 58 1y agoExplain → -
browserify-zlib
Full zlib module for browserify
JavaScript ★ 58 1y agoExplain → -
stream-splicer
streaming pipeline with a mutable configuration
JavaScript ★ 56 1y agoExplain → -
createHash
Node style hashes for use in the browser, with native hash functions in node
JavaScript ★ 54 4mo agoExplain → -
browserify-sign
createSign and createVerify in your browser
JavaScript ★ 48 1mo agoExplain → -
md5.js
node style md5 on pure JavaScript
JavaScript ★ 44 1y agoExplain → -
labeled-stream-splicer
stream splicer with labels
JavaScript ★ 43 1y agoExplain → -
ripemd160
JavaScript component to compute the RIPEMD160 hash of strings or bytes.
JavaScript ★ 34 9mo agoExplain → -
console-browserify
Emulate console for all the browsers
JavaScript ★ 33 1y agoExplain → -
buffer-xor
A simple module for bitwise-xor on buffers
JavaScript ★ 32 1y agoExplain → -
to-buffer
Pass in a string, get a buffer back. Pass in a buffer, get the same buffer back.
JavaScript ★ 31 2mo agoExplain → -
publicEncrypt
publicEncrypt/privateDecrypt for browserify
JavaScript ★ 28 1y agoExplain → -
insert-module-globals
insert implicit module globals into a module-deps stream
JavaScript ★ 26 1y agoExplain → -
createECDH
browserify version of crypto.createECDH
JavaScript ★ 25 1y agoExplain → -
timers-browserify
timers module for browserify
JavaScript ★ 24 1y agoExplain → -
cipher-base
abstract base class for crypto-streams
JavaScript ★ 21 9mo agoExplain → -
EVP_BytesToKey
No description.
JavaScript ★ 21 1y agoExplain → -
parse-asn1
No description.
JavaScript ★ 20 9mo agoExplain → -
browserify-cipher
No description.
JavaScript ★ 19 1y agoExplain → -
browserify-rsa
No description.
JavaScript ★ 19 1y agoExplain → -
tty-browserify
the tty module from node core for browsers
JavaScript ★ 18 1y agoExplain → -
deps-sort
sort module-deps output for deterministic browserify bundles
JavaScript ★ 16 1y agoExplain → -
acorn-node
the acorn javascript parser, preloaded with plugins for syntax parity with recent node versions
JavaScript ★ 13 1y agoExplain → -
admin
administrative procedures for the browserify org
★ 12 6y agoExplain → -
hash-base
abstract base class for hash-streams
JavaScript ★ 11 9mo agoExplain → -
discuss
discuss project organization, initiatives, and whatever!
★ 11 8y agoExplain → -
browserify-des
DES for browserify
JavaScript ★ 10 1y agoExplain → -
randomfill
No description.
JavaScript ★ 9 1y agoExplain → -
buffer-reverse
A lite module for byte reversal on buffers.
JavaScript ★ 6 1y agoExplain → -
uglifyify ⑂
A browserify transform which minifies your code using UglifyJS2
JavaScript ★ 4 4mo agoExplain → -
detective-esm
find es module dependencies [experimental]
JavaScript ★ 3 1y agoExplain → -
perf-hooks-browserify
[WIP] The perf_hooks node module API for browserify
JavaScript ★ 3 1y agoExplain → -
envify ⑂
:wrench: Selectively replace Node-style environment variables with plain strings.
JavaScript ★ 3 4d agoExplain → -
hash-test-vectors
No description.
JavaScript ★ 3 1y agoExplain → -
pseudorandombytes
pseudorandombytes for the browser
JavaScript ★ 3 1y agoExplain → -
.github
Housing of Browserify's GitHub configuration and base files
★ 2 4mo agoExplain → -
timing-safe-equal
No description.
JavaScript ★ 2 1y agoExplain → -
crypto-packages-ownership ⑂
npm owner powertool
JavaScript ★ 1 3y agoExplain → -
scrypt
No description.
JavaScript ★ 1 1y agoExplain → -
acorn5-object-spread ⑂ ▣
Spread and rest properties support in acorn 5
JavaScript ★ 0 8y agoExplain →
No repos match these filters.