Browser require for developing purposes
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
README.md
UNLICENSE
bower.json
index.js
package.json
stub.js

README.md

Broswer require()

Provide synchronous require in browser for development purposes. A convenient replacement for watchify (dynamic, no configs needed). Strives to be compliant with browserify, in that code using require-stub is fully browserifyable.

$ npm install --save-dev require-stub
<!-- provide `reqiure` -->
<script src="node_modules/require-stub/index.js"></script>

<!-- use require -->
<script>
	var assert = require("chai").assert;
	var Emitter = require("emitter");
</script>

If you find something doesn’t work, report a bug.

How does it work?

Via synchronous XMLHttpRequest. To resolve module paths used package.json closest to the current page. To stub native packages is used browser-builtins. Required scripts are evaled, so to provide module scopes.

Precautions

  • Don’t use in production: dynamic evals proved to be ~3x slower than browserified code. But it is good for perf testing.

Similar efforts

  • breq — resolves relative requirements.
  • TKRequire — resolves relative requirements.
  • smoothie.js — resolves relative requirements.

Best wishes,

Deema.

NPM