"exports"


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

“exports” 字段允许定义在通过名称导入包时的 入口点,无论是通过 node_modules 查找加载,还是通过 自我指涉 加载到其自身名称。它在 Node.js 12 及以上版本中受到支持,作为 "main" 的替代方案,可以支持定义 子路径导出条件导出,同时封装内部未导出的模块。

【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.】

条件性出口 也可以在 "exports" 中使用,以根据不同环境定义不同的包入口点,包括该包是通过 require 还是通过 import 引用。

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

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