Skip to content

Commit e17d3c1

Browse files
docs: document package.json's "exports" field
1 parent 9bffa13 commit e17d3c1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/lib/content/configuring-npm/package-json.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,27 @@ not much else.
339339

340340
If `main` is not set, it defaults to `index.js` in the package's root folder.
341341

342+
### exports
343+
344+
The exports field is an object that maps entry points to modules. It supports wild cards (`*`) and explicit names.
345+
346+
For example, you could have:
347+
348+
```json
349+
{
350+
"exports": {
351+
".": "./index.js",
352+
"./*": "./*.js",
353+
"./*.js": "./*.js",
354+
"./foo": "./path/to/foo.js"
355+
}
356+
}
357+
```
358+
359+
If someone installed your package with this in your `package.json`, they could `require("my-package")` and it would be mapped to `./node_modules/my-package/index.js` because of `".": "./index.js"`.<br>
360+
If they did `require("my-package/bar")` or `require("my-package/bar.js")`, it would be mapped to `./node_modules/my-package/bar.js` because of the wild cards (`*`).<br>
361+
If they did `require("my-package/foo")` it would be mapped to `./node_modules/my-package/path/to/foo.js` because of the explicit mapping `"./foo": "./path/to/foo.js"`.<br>
362+
342363
### browser
343364

344365
If your module is meant to be used client-side the browser field should be

0 commit comments

Comments
 (0)