{"id":18458777,"url":"https://github.com/browserify/browser-resolve","last_synced_at":"2025-05-16T04:04:16.787Z","repository":{"id":6958764,"uuid":"8210977","full_name":"browserify/browser-resolve","owner":"browserify","description":"resolve function which support the browser field in package.json","archived":false,"fork":false,"pushed_at":"2024-12-21T10:04:28.000Z","size":146,"stargazers_count":102,"open_issues_count":5,"forks_count":68,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-24T11:40:20.638Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/browserify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-15T01:07:01.000Z","updated_at":"2024-08-27T15:51:17.000Z","dependencies_parsed_at":"2022-09-06T11:11:47.806Z","dependency_job_id":null,"html_url":"https://github.com/browserify/browser-resolve","commit_stats":null,"previous_names":["shtylman/node-browser-resolve"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Fbrowser-resolve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Fbrowser-resolve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Fbrowser-resolve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Fbrowser-resolve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/browserify","download_url":"https://codeload.github.com/browserify/browser-resolve/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464891,"owners_count":22075570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T08:20:01.471Z","updated_at":"2025-05-16T04:04:16.765Z","avatar_url":"https://github.com/browserify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# browser-resolve [![Build Status](https://travis-ci.org/browserify/browser-resolve.png?branch=master)](https://travis-ci.org/browserify/browser-resolve)\n\nnode.js resolve algorithm with [browser field](https://github.com/defunctzombie/package-browser-field-spec) support.\n\n## api\n\n### bresolve(id, opts={}, cb)\n\nResolve a module path and call `cb(err, path [, pkg])`\n\nOptions:\n\n* `basedir` - directory to begin resolving from\n* `browser` - the 'browser' property to use from package.json (defaults to 'browser')\n* `filename` - the calling filename where the `require()` call originated (in the source)\n* `modules` - object with module id/name -\u003e path mappings to consult before doing manual resolution (use to provide core modules)\n* `packageFilter` - transform the parsed `package.json` contents before looking at the `main` field\n* `paths` - `require.paths` array to use if nothing is found on the normal `node_modules` recursive walk\n\nAdditionally, options supported by [node-resolve](https://github.com/browserify/resolve#resolveid-opts-cb) can be used.\n\n### bresolve.sync(id, opts={})\n\nSame as the async resolve, just uses sync methods.\n\nAdditionally, options supported by [node-resolve](https://github.com/browserify/resolve#resolvesyncid-opts-cb) can be used.\n\n## basic usage\n\nyou can resolve files like `require.resolve()`:\n``` js\nvar bresolve = require('browser-resolve');\nbresolve('../', { filename: __filename }, function(err, path) {\n    console.log(path);\n});\n```\n\n```\n$ node example/resolve.js\n/home/substack/projects/browser-resolve/index.js\n```\n\n## core modules\n\nBy 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.\n\n``` js\nvar shims = {\n    http: '/your/path/to/http.js'\n};\n\nvar bresolve = require('browser-resolve');\nbresolve('http', { modules: shims }, function(err, path) {\n    console.log(path);\n});\n```\n\n```\n$ node example/builtin.js\n/home/substack/projects/browser-resolve/builtin/http.js\n```\n\n## browser field\nbrowser-specific versions of modules\n\n``` json\n{\n  \"name\": \"custom\",\n  \"version\": \"0.0.0\",\n  \"browser\": {\n    \"./main.js\": \"custom.js\"\n  }\n}\n```\n\n``` js\nvar bresolve = require('browser-resolve');\nvar parent = { filename: __dirname + '/custom/file.js' };\nbresolve('./main.js', parent, function(err, path) {\n    console.log(path);\n});\n```\n\n```\n$ node example/custom.js\n/home/substack/projects/browser-resolve/example/custom/custom.js\n```\n\nYou can use different package.json properties for the resolution, if you want to allow packages to target different environments for example:\n\n``` json\n{\n  \"browser\": { \"./main.js\": \"custom.js\" },\n  \"chromeapp\": { \"./main.js\": \"custom-chromeapp.js\" }\n}\n```\n\n``` js\nvar bresolve = require('browser-resolve');\nvar parent = { filename: __dirname + '/custom/file.js', browser: 'chromeapp' };\nbresolve('./main.js', parent, function(err, path) {\n    console.log(path);\n});\n```\n\n```\n$ node example/custom.js\n/home/substack/projects/browser-resolve/example/custom/custom-chromeapp.js\n```\n\n## skip\n\nYou can skip over dependencies by setting a\n[browser field](https://gist.github.com/defunctzombie/4339901)\nvalue to `false`:\n\n``` json\n{\n  \"name\": \"skip\",\n  \"version\": \"0.0.0\",\n  \"browser\": {\n    \"tar\": false\n  }\n}\n```\n\nThis is handy if you have code like:\n\n``` js\nvar tar = require('tar');\n\nexports.add = function (a, b) {\n    return a + b;\n};\n\nexports.parse = function () {\n    return tar.Parse();\n};\n```\n\nso that `require('tar')` will just return `{}` in the browser because you don't\nintend to support the `.parse()` export in a browser environment.\n\n``` js\nvar bresolve = require('browser-resolve');\nvar parent = { filename: __dirname + '/skip/main.js' };\nbresolve('tar', parent, function(err, path) {\n    console.log(path);\n});\n```\n\n```\n$ node example/skip.js\n/home/substack/projects/browser-resolve/empty.js\n```\n\n# license\n\nMIT\n\n# upgrade notes\n\nPrior 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()`.\n\nThis was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrowserify%2Fbrowser-resolve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrowserify%2Fbrowser-resolve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrowserify%2Fbrowser-resolve/lists"}