The "exports" field allows defining the entry points of a package. Through the use of conditional exports loader specific entries can be defined.
It can be a string an object or an array
If package.exports is a string an import or require of your package will always resolve to that string
If package.exports is an object you can define two types of fields.
Subpath export fields or conditional fields
Subpath export field specify the path that can be used by a consumer.
The entry point of a module uses the subpath field "."
.
Custom subpaths to the entry point can be defined using relative paths such as "./subpath"
.
Conditional fields can be used to define an entry point for specific loaders in Node.js or other environments. Node.js supports 4 conditional fields including "default", "import", "require", "node".
An exports object that only contains conditional fields is sugar for only defining an entry point subpath field.
Conditional fields can be composed e.g.:
"exports": {
"node": {
"require": "./path-to-some-file.js",
"import": "./path-to-some-file.mjs"
}
}