"exports"
-
类型:<Object> | <string> | <string[]>
¥Type: <Object> | <string> | <string[]>
{
"exports": "./index.js"
}
"exports"
字段允许在通过 node_modules
查找或 self-reference 加载到其自己的名称的名称导入时定义包的 入口点。它在 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
引用。
¥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
.
"exports"
中定义的所有路径必须是以 ./
开头的相对文件 URL。
¥All paths defined in the "exports"
must be relative file URLs starting with
./
.