Require different values in a web browser.
This module allows you to explicitly load different modules on the client than on the server without the need for aliasing. You can point to polyfilled globals, custom objects or functions or nothing at all. Subsequently, Browserify will be "tricked" out of bundling the original module, keeping your file size small.
Installation
Node.js >= 4
is required. To install, type this at the command line:
npm install broquire
broquire(id[, browserValue])
In Node.js, the return value is always identical to regular require
.
In a web browser, an empty Object
will be returned if no browserValue
is given:
var broquire = require;var utilities = ;if utilitiescleanup === undefined utilities{};
If an Object
is passed, then it will be returned:
var broquire = require;var utilities = ;
If a String
is given, then window[browserValue]
will be returned:
var broquire = require;var URL = URL;
broquire.isBrowser
Has a value of true
when running in a web browser, and false
when running in Node.js
broquire.isServer
Has a value of true
when running in Node.js, and false
when running in a web browser.
FAQ
Why do I need to pass require
in to this function?
Every time Node.js executes a file, it gives you a version of require
that will resolve modules relative to that file and directory. Passing your require
to broquire
allows it to import modules exactly as you would with a regular require statement.