"main"


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

"main" 字段定义了包目录通过 require() 加载时使用的脚本。 其值为路径。

require('./path/to/directory'); // 这解析为 ./path/to/directory/main.js。

当包具有 "exports" 字段时,则在按名称导入包时,这将优先于 "main" 字段。

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

The "main" field defines the script that is used when the package directory is loaded via require(). Its value is a path.

require('./path/to/directory'); // This resolves to ./path/to/directory/main.js.

When a package has an "exports" field, this will take precedence over the "main" field when importing the package by name.