-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
browser-resolve is only responsible for handling the browser field resolution. Consumers of this module who wish to provide alternatives to the core node modules should specify a `modules` option when calling resolve. The modules object is a key/value of core modulename -> path.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,20 @@ | |
|
||
node.js resolve algorithm with [browser](https://gist.github.com/shtylman/4339901) field support. | ||
|
||
# example | ||
## api | ||
|
||
## relative | ||
### resolve(pkg, opts={}, cb) | ||
|
||
Resolve a module path and call `cb(err, path)` | ||
|
||
Options: | ||
|
||
* filename - the calling filename where the require call originated (in the source) | ||
* paths - require.paths array to use if nothing is found on the normal node_modules recursive walk | ||
* packageFilter - transform the parsed package.json contents before looking at the "main" field | ||
* modules - object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
defunctzombie
via email
Author
Collaborator
|
||
|
||
## basic usage | ||
|
||
you can resolve files like `require.resolve()`: | ||
``` js | ||
|
@@ -19,13 +30,17 @@ $ node example/resolve.js | |
/home/substack/projects/node-browser-resolve/index.js | ||
``` | ||
|
||
## core | ||
## core modules | ||
|
||
or if you `require()` core modules you'll get a version that works in browsers: | ||
By default, core modules (http, dgram, etc) will return their same name as the path. If you want to have specific paths returned, specify a `modules` property in the options object. | ||
|
||
``` js | ||
var shims = { | ||
http: '/your/path/to/http.js' | ||
}; | ||
|
||
var resolve = require('browser-resolve'); | ||
resolve('fs', null, function(err, path) { | ||
resolve('fs', { modules: shims }, function(err, path) { | ||
console.log(path); | ||
}); | ||
``` | ||
|
@@ -35,11 +50,8 @@ $ node example/builtin.js | |
/home/substack/projects/node-browser-resolve/builtin/fs.js | ||
``` | ||
|
||
## custom | ||
|
||
and you can use the | ||
[browser field](https://gist.github.com/shtylman/4339901) to load | ||
browser-specific versions of modules: | ||
## browser field | ||
browser-specific versions of modules | ||
|
||
``` js | ||
{ | ||
|
@@ -113,3 +125,9 @@ $ node example/skip.js | |
# license | ||
|
||
MIT | ||
|
||
# upgrade notes | ||
|
||
Prior to v1.x this library provided shims for node core modules. These have since been removed. If you want to have alternative core modules provided, use the `modules` option when calling resolve. | ||
|
||
This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update. |
This file was deleted.
This file was deleted.
@shtylman I do agree that modules should be externalized but this is currently breaking browserify if it try to update to latest browser-resolve. Did you by chance move these out into another module that I can't find?