Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,24 @@ 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"
}
}
}
```

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, include
a `"defaut"` condition where possible. Always providing a `"default"` condition
ensures that any unknown JS environments are able to use a universal
implementation where possible, which helps avoid JS environments from having to
pretend to be existing environments to support packages with conditional
exports. Where possible, `"node"` and `"default"` conditions can be preferable
to `"browser"` conditions.

#### Nested conditions

Expand All @@ -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",
}
}
```
Expand Down