Skip to content

Commit

Permalink
Support custom names for "browser" field resolution
Browse files Browse the repository at this point in the history
Fixes: #1917
  • Loading branch information
feross committed Aug 8, 2019
1 parent 8980670 commit 2af69b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -83,12 +83,19 @@ function Browserify (files, opts) {
self._transforms = [];
self._entryOrder = 0;
self._ticked = false;
self._bresolve = opts.browserField === false

var browserField = opts.browserField
self._bresolve = browserField === false
? function (id, opts, cb) {
if (!opts.basedir) opts.basedir = path.dirname(opts.filename)
resolve(id, opts, cb)
}
: bresolve
: typeof browserField === 'string'
? function (id, opts, cb) {
opts.browser = browserField
bresolve(id, opts, cb)
}
: bresolve
;
self._syntaxCache = {};

Expand Down
4 changes: 3 additions & 1 deletion readme.markdown
Expand Up @@ -447,7 +447,9 @@ useful for preserving the original paths that a bundle was generated with.
`opts.bundleExternal` boolean option to set if external modules should be
bundled. Defaults to true.

When `opts.browserField` is false, the package.json browser field will be ignored.
When `opts.browserField` is false, the package.json browser field will be
ignored. When `opts.browserField` is set to a `string`, then a custom field name
can be used instead of the default `"browser"` field.

When `opts.insertGlobals` is true, always insert `process`, `global`,
`__filename`, and `__dirname` without analyzing the AST for faster builds but
Expand Down

0 comments on commit 2af69b6

Please sign in to comment.