Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/requiremap
A browserify transform stream for aliasing require statements
https://github.com/hughsk/requiremap
Last synced: 8 days ago
JSON representation
A browserify transform stream for aliasing require statements
- Host: GitHub
- URL: https://github.com/hughsk/requiremap
- Owner: hughsk
- License: other
- Created: 2013-08-02T22:00:31.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-02T22:00:41.000Z (over 11 years ago)
- Last Synced: 2024-10-17T16:41:26.608Z (22 days ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# requiremap #
A [browserify](http://browserify.org) transform stream for aliasing `require`
statements. You can use it to write your own transforms for things like custom
extensions and module resolution.## Installation ##
``` bash
npm install requiremap
```## Usage ##
### `require('requiremap')(map)` ###
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](http://ghub.io/falafel).
In most cases, you should be fine getting `node.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 use `update()` without
any arguments.``` javascript
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)
```