Skip to content

Commit deb7824

Browse files
committed
tweak readme, closes #67
1 parent a2c685c commit deb7824

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

README.md

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ node.js resolve algorithm with [browser field](https://github.com/defunctzombie/
44

55
## api
66

7-
### resolve(id, opts={}, cb)
7+
### bresolve(id, opts={}, cb)
88

99
Resolve a module path and call `cb(err, path [, pkg])`
1010

@@ -17,20 +17,20 @@ Options:
1717
* `packageFilter` - transform the parsed `package.json` contents before looking at the `main` field
1818
* `paths` - `require.paths` array to use if nothing is found on the normal `node_modules` recursive walk
1919

20-
Options supported by [node-resolve](https://github.com/browserify/resolve#resolveid-opts-cb) can be used.
20+
Additionally, options supported by [node-resolve](https://github.com/browserify/resolve#resolveid-opts-cb) can be used.
2121

22-
### resolve.sync(id, opts={})
22+
### bresolve.sync(id, opts={})
2323

2424
Same as the async resolve, just uses sync methods.
2525

26-
Options supported by [node-resolve](https://github.com/browserify/resolve#resolvesyncid-opts) `sync` can be used.
26+
Additionally, options supported by [node-resolve](https://github.com/browserify/resolve#resolvesyncid-opts-cb) can be used.
2727

2828
## basic usage
2929

3030
you can resolve files like `require.resolve()`:
3131
``` js
32-
var resolve = require('browser-resolve');
33-
resolve('../', { filename: __filename }, function(err, path) {
32+
var bresolve = require('browser-resolve');
33+
bresolve('../', { filename: __filename }, function(err, path) {
3434
console.log(path);
3535
});
3636
```
@@ -49,37 +49,34 @@ var shims = {
4949
http: '/your/path/to/http.js'
5050
};
5151

52-
var resolve = require('browser-resolve');
53-
resolve('fs', { modules: shims }, function(err, path) {
52+
var bresolve = require('browser-resolve');
53+
bresolve('http', { modules: shims }, function(err, path) {
5454
console.log(path);
5555
});
5656
```
5757

5858
```
5959
$ node example/builtin.js
60-
/home/substack/projects/browser-resolve/builtin/fs.js
60+
/home/substack/projects/browser-resolve/builtin/http.js
6161
```
6262

6363
## browser field
6464
browser-specific versions of modules
6565

66-
``` js
66+
``` json
6767
{
6868
"name": "custom",
6969
"version": "0.0.0",
7070
"browser": {
7171
"./main.js": "custom.js"
72-
},
73-
"chromeapp": {
74-
"./main.js": "custom-chromeapp.js"
7572
}
7673
}
7774
```
7875

7976
``` js
80-
var resolve = require('browser-resolve');
81-
var parent = { filename: __dirname + '/custom/file.js' /*, browser: 'chromeapp' */ };
82-
resolve('./main.js', parent, function(err, path) {
77+
var bresolve = require('browser-resolve');
78+
var parent = { filename: __dirname + '/custom/file.js' };
79+
bresolve('./main.js', parent, function(err, path) {
8380
console.log(path);
8481
});
8582
```
@@ -89,6 +86,28 @@ $ node example/custom.js
8986
/home/substack/projects/browser-resolve/example/custom/custom.js
9087
```
9188

89+
You can use different package.json properties for the resolution, if you want to allow packages to target different environments for example:
90+
91+
``` json
92+
{
93+
"browser": { "./main.js": "custom.js" },
94+
"chromeapp": { "./main.js": "custom-chromeapp.js" }
95+
}
96+
```
97+
98+
``` js
99+
var bresolve = require('browser-resolve');
100+
var parent = { filename: __dirname + '/custom/file.js', browser: 'chromeapp' };
101+
bresolve('./main.js', parent, function(err, path) {
102+
console.log(path);
103+
});
104+
```
105+
106+
```
107+
$ node example/custom.js
108+
/home/substack/projects/browser-resolve/example/custom/custom-chromeapp.js
109+
```
110+
92111
## skip
93112

94113
You can skip over dependencies by setting a
@@ -123,9 +142,9 @@ so that `require('tar')` will just return `{}` in the browser because you don't
123142
intend to support the `.parse()` export in a browser environment.
124143

125144
``` js
126-
var resolve = require('browser-resolve');
145+
var bresolve = require('browser-resolve');
127146
var parent = { filename: __dirname + '/skip/main.js' };
128-
resolve('tar', parent, function(err, path) {
147+
bresolve('tar', parent, function(err, path) {
129148
console.log(path);
130149
});
131150
```
@@ -141,6 +160,6 @@ MIT
141160

142161
# upgrade notes
143162

144-
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.
163+
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 `bresolve()`.
145164

146165
This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update.

0 commit comments

Comments
 (0)