Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: esm: improve dual package hazard docs #30345

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
doc: merge intro language
  • Loading branch information
GeoffreyBooth committed Nov 14, 2019
commit a0d7c997637a647231862025c2c70908954a4592
23 changes: 7 additions & 16 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,13 @@ unspecified.
There are two fields that can define entry points for a package: `"main"` and
`"exports"`. The `"main"` field is supported in all versions of Node.js, but its
capabilities are limited: it only defines the main entry point of the package.
The `"exports"` field can also be used to define the main entry point of the
package, as well as other defined entry points; and the package can be
encapsulated, so that extra effort is required to reference files within the
package that aren’t the defined public API. `"exports"` can also map an entry
point to different files per environment, for example for all environments
versus browser environments; and with `--experimental-conditional-exports`
`"exports"` can define separate files for Node.js CommonJS and ES module
environments.
The `"exports"` field, part of [Package Exports][], provides an alternative to
`"main"` where the package main entry point can be defined while also
encapsulating the package, preventing any other entry points besides those
defined in `"exports"`. If package entry points are defined in both `"main"` and
`"exports"`, the latter takes precedence in versions of Node.js that support
`"exports"`. [Conditional Exports][] can also be used within `"exports"` to
define different package entry points per environment.

#### <code>package.json</code> <code>"main"</code>

Expand Down Expand Up @@ -233,14 +232,6 @@ The `"main"` field can point to exactly one file, regardless of whether the
package is referenced via `require` (in a CommonJS context) or `import` (in an
ES module context).

[Package Exports][] provide an alternative to `"main"` where the package main
entry point can be defined while also encapsulating the package, preventing any
other entry points besides those defined in `"exports"`. If package entry points
are defined in both `"main"` and `"exports"`, the latter takes precedence in
versions of Node.js that support `"exports"`. [Conditional Exports][] can also
be used within `"exports"` to define different package entry points per
environment.

#### Package Exports

By default, all subpaths from a package can be imported (`import 'pkg/x.js'`).
Expand Down