"main"
- 类型: <string>
{
"main": "./index.js"
}
当通过 node_modules
查找按名称导入时,则 "main"
字段定义了包的入口点。
其值为路径。
当包具有 "exports"
字段时,则在按名称导入包时,这将优先于 "main"
字段。
它还定义了通过 require()
加载包目录时使用的脚本。
// 这解析为 ./path/to/directory/index.js。
require('./path/to/directory');
- Type: <string>
{
"main": "./index.js"
}
The "main"
field defines the entry point of a package when imported by name
via a node_modules
lookup. Its value is a path.
When a package has an "exports"
field, this will take precedence over the
"main"
field when importing the package by name.
It also defines the script that is used when the package directory is loaded
via require()
.
// This resolves to ./path/to/directory/index.js.
require('./path/to/directory');