更新时间:2023-12-03 23:40:34
来自 npm文档:
主要字段是模块ID,是您的主要入口点 程序.也就是说,如果您的软件包名为foo,并且有用户安装 它,然后确实require("foo"),然后您的主模块的导出 对象将被返回.
The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned.
这应该是相对于包根目录的模块ID 文件夹.
This should be a module ID relative to the root of your package folder.
对于大多数模块,拥有主脚本和 通常不会太多.
For most modules, it makes the most sense to have a main script and often not much else.
简而言之:
index.js
不同,则仅在package.json
中需要一个main
参数.例如,人们经常将入口指向lib/index.js
或lib/<packagename>.js
,在这种情况下,相应的脚本必须在package.json
中描述为main
.main
,只是因为必须明确定义入口点require('yourpackagename')
.main
parameter in your package.json
if the entry point to your package differs from index.js
in its root folder. For example, people often put the entry point to lib/index.js
or lib/<packagename>.js
, in this case the corresponding script must be described as main
in package.json
.main
, simply because the entry point require('yourpackagename')
must be defined unambiguously.