"exports"


{
  "exports": "./index.js"
}

"exports" 字段允许定义包的入口点,当通过 node_modules 查找或自引用加载到其自身的名称的名称导入时。 Node.js 12+ 支持它作为 "main" 的替代方案,它可以支持定义子路径导出条件导出,同时封装内部未导出的模块。

条件导出也可以在 "exports" 中用于为每个环境定义不同的包入口点,包括包是通过 require 还是通过 import 引用。

"exports" 中定义的所有路径必须是以 ./ 开头的相对文件 URL。

{
  "exports": "./index.js"
}

The "exports" field allows defining the entry points of a package when imported by name loaded either via a node_modules lookup or a self-reference to its own name. It is supported in Node.js 12+ as an alternative to the "main" that can support defining subpath exports and conditional exports while encapsulating internal unexported modules.

Conditional Exports can also be used within "exports" to define different package entry points per environment, including whether the package is referenced via require or via import.

All paths defined in the "exports" must be relative file URLs starting with ./.