A simple, node.js-like require() for the browser.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.npmignore
.travis.yml
README.md
package.json
require.js
require.min.js

README.md

NPM Version Build Status

simple-browser-require

simple-browser-require is a simple, node.js-like require() for the browser. It is not an asynchronous script loader.

Usage

Wrapping each module in a require.register call:

require.register('my/module/id', function(module, exports, require) {
	// module code here
});

...allows the require function to return the module's public contents:

var lib = require('my/module/id');

...exposed by decorating the exports object:

var myModuleVar = 'my module';

exports.myModuleMethod = function() {
  return myModuleVar;
};

...or overwritting the exports object completely:

function MyModule() {
  this.myVar = 'my instance var';
};

MyModule.prototype.myMethod = function() {
  return this.myVar;
};

module.exports = MyModule;

Each module is supplied with a require function that resolves relative module ids:

var lib = require('./my/lib'); // in current package
var SomeClass = require('../someclass'); // in parent package
var util = require('utils/util'); // from root package