summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2020-07-10 23:37:20 -0700
committerMyles Borins <mylesborins@github.com>2020-07-16 17:09:13 -0400
commit17174e69ce32a27740794cc9baaf9ee433bb8281 (patch)
tree64f21e70eba4b2acb50055420f266da6fa276da7
parent1dd265384b24b17d9460689a6a478b123ebd61a7 (diff)
downloadnode-new-17174e69ce32a27740794cc9baaf9ee433bb8281.tar.gz
doc: clarify conditional exports guidance
PR-URL: https://github.com/nodejs/node/pull/34306 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
-rw-r--r--doc/api/esm.md18
1 files changed, 13 insertions, 5 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md
index d705e2d8ef..c9bb7473a8 100644
--- a/doc/api/esm.md
+++ b/doc/api/esm.md
@@ -456,7 +456,7 @@ Conditional exports can also be extended to exports subpaths, for example:
"exports": {
".": "./main.js",
"./feature": {
- "browser": "./feature-browser.js",
+ "node": "./feature-node.js",
"default": "./feature.js"
}
}
@@ -464,8 +464,16 @@ Conditional exports can also be extended to exports subpaths, for example:
```
Defines a package where `require('pkg/feature')` and `import 'pkg/feature'`
-could provide different implementations between the browser and Node.js,
-given third-party tool support for a `"browser"` condition.
+could provide different implementations between Node.js and other JS
+environments.
+
+When using environment branches, always include a `"default"` condition where
+possible. Providing a `"default"` condition ensures that any unknown JS
+environments are able to use this universal implementation, which helps avoid
+these JS environments from having to pretend to be existing environments in
+order to support packages with conditional exports. For this reason, using
+`"node"` and `"default"` condition branches is usually preferable to using
+`"node"` and `"browser"` condition branches.
#### Nested conditions
@@ -479,11 +487,11 @@ use in Node.js but not the browser:
{
"main": "./main.js",
"exports": {
- "browser": "./feature-browser.mjs",
"node": {
"import": "./feature-node.mjs",
"require": "./feature-node.cjs"
- }
+ },
+ "default": "./feature.mjs",
}
}
```