View on GitHub


literally replacing require calls with arbitrary code

Download this project as a .zip file Download this project as a tar.gz file


literalify is a browserify transform for replacing require calls with arbitrary code, e.g. to pretend browser globals are actually CommonJS modules.

This library uses browserify-transform-tools, so you can also supply the configuration by adding a literalify field to your project's package.json file.

license - MIT Dependencies

NPM status

Build Status Coverage Status


If you only want to convert globals-polluting libraries into CommonJS modules, moduleify would be sufficient. But in some cases you still want these libraries to be loaded via script-tags or have to use an existing non-browserified bundle.

In these cases the recommended approach seems to be to create shim modules for each browser global you want to use. But compared to just using window.myLibrary the overhead of creating a new shim module seems a bit extreme.

With literalify you don't have to choose: you can use require to load your legacy libraries without having to pollute your filesystem with those pesky shims.

Use Case: AngularJS

In the 1.2 release AngularJS has begun to move some core features into separate files. If you want to use AngularJS with browserify require calls that means you now have the option of either bundling AngularJS with all the extensions you want to use before browserify is applied or to wrap each extension in a separate module and make sure to load all of them explicitly in your start script. In either case you need to run the AngularJS files through browserify in order to be able to require them.

With literalify you can keep the AngularJS files out of browserify and let it simply replace all calls of require("angular") with references to window.angular without having to make manual changes to your code or AngularJS.



With NPM

npm install literalify

From source

git clone
cd literalify
npm install
make test

Basic usage example


window.$ = {
  makeAwesome: function(str) {
    return str.toUpperCase();


var makeAwesome = require('some-dependency').makeAwesome;
console.log(makeAwesome('needs more caps'));


<!doctype html>
<meta charset="utf-8">
<title>Look at the console!</title>
<script src="vendor/some-dependency.js"></script>
<script src="bundle.js"></script>


var browserify = require('browserify'),
    literalify = require('literalify'),
    b = browserify();

    'some-dependency': 'window.$'

Usage example with package.json


    "name": "my-awesome-project",
    "devDependencies": {
        "browserify": "*",
        "literalify": "*"
    "literalify": {"some-dependency": "window.$"}

Usage (API)

var browserify = require('browserify'),
    literalify = require('literalify'),
    b = browserify();


Usage (Shell)

browserify -t literalify ./app.js > bundle.js



Creates a browserify transform that will replace the given require calls with the given JavaScript expressions.


The MIT/Expat license. For more information, see or the accompanying LICENSE file.