Skip to content

Commit 6a4dd28

Browse files
docs: document package.json's "exports" fields' conditional exports
1 parent e17d3c1 commit 6a4dd28

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ If `main` is not set, it defaults to `index.js` in the package's root folder.
341341

342342
### exports
343343

344-
The exports field is an object that maps entry points to modules. It supports wild cards (`*`) and explicit names.
344+
The exports field is an object that maps entry points to modules. This field is supported by Node.js versions including and higher than 12. It acts a more featureful alternative to the `main` field. It supports wild cards (`*`) and explicit names.
345345

346346
For example, you could have:
347347

@@ -351,14 +351,16 @@ For example, you could have:
351351
".": "./index.js",
352352
"./*": "./*.js",
353353
"./*.js": "./*.js",
354-
"./foo": "./path/to/foo.js"
354+
"./foo": "./path/to/foo.js",
355+
"./package.json": "./package.json",
356+
"./
355357
}
356358
}
357359
```
358360

359361
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>
360362
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>
363+
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"`.
362364

363365
### browser
364366

0 commit comments

Comments
 (0)