"main"


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

"main" 字段定义了通过 node_modules 查找按名称导入时包的入口点。它的值是一个路径。

🌐 The "main" field defines the entry point of a package when imported by name via a node_modules lookup. Its value is a path.

如果存在,"exports" 字段在按名称导入包时优先于 "main" 字段。

🌐 The "exports" field, if it exists, takes precedence over the "main" field when importing the package by name.

它还定义了在通过 require() 加载包目录时使用的脚本。

🌐 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');