0.0.0 • Published 11 years ago
requiremap v0.0.0
requiremap
A browserify transform stream for aliasing require
statements. You can use it to write your own transforms for things like custom
extensions and module resolution.
Installation
npm install requiremap
Usage
require('requiremap')(map)
Returns a browserify transform that calls map(file, node, update)
for each
require detected.
file
is the absolute path to the file requiring the module.node
is an AST node from falafel. In most cases, you should be fine gettingnode.value
for the module name.update(err, updated)
is a callback you should call with the new string to place in the require statement - this must be called. If you don't want to update it, just useupdate()
without any arguments.
var browserify = require('browserify')
var requiremap = require('requiremap')
var b = browserify()
b.add(__dirname + '/src/index.js')
// "async" -> "./a.js"
// "beefy" -> "./b.js"
// "./src" -> "./src"
b.transform(requiremap(function(file, node, update) {
if (node.value[0] === '/') return update()
if (node.value[0] === '.') return update()
update(null, './' + node.value.slice(0, 1))
}))
b.bundle.pipe(process.stdout)
0.0.0
11 years ago