packageJson

license

  • 开源许可证
  • 所有的包又应该有 license,以便让使用它的人知道是在什么授权下使用此包
  • 如果是公司内部的包或者不想别人用的包,应该赋值为UNLICENSE

homepage

代码托管库

"homepage":"https://your-package.org"

repostory

"repostory": {
	"type":"git",
	"url":"https://github.com/user/repo.git"
},
"repostory": "github:user/repo",

files

指定包含在项目中的文件,可以是:

  1. 单独的文件
  2. 整个文件夹
  3. 通配符
"files":[
	  "filename.js",
	  "directory/",
	  "glob/*.{js,json}"
]

main

项目入口文件,通常是CommonJs规范的入口文件

"main":"filename.js"

bin

随着项目一起被安装的可执行文件。

dependencies

"dependencied" : {
	"vue": "^2.0.0"
}

这是开发版和发布版都需要的依赖。

devDenpendencies

仅仅是开发阶段需要用到的依赖。

peerDependencies

平行依赖 一般用于:开发 A 包给主项目 main 用,A 包引用到了 B 包,主项目也用到了 B 包。此时,A 包引用 B 包应使用peerDependencies而不是dependencies。 如element-ui:

  • elementUI直接在dependencies引用vue的时候,就会出现 2 个vue模块。

    my-project
    | - node_modules
    	| - vue
    	| - element-ui
    		| - node_modules
    			| - vue
  • 但是当在peerDependencies引用vue的时候,就会只有一个vue模块。

    my-project
    | - node_modules
    	| - vue
    	| - element-ui

resolutions

解决版本依赖冲突(给yarn用的) 当main项目和main项目引用的的依赖A,同时依赖的B的两个不同的版本。这个时候就可以用resoutions去解决。在resolution里面指定B的版本号,main项目和A都会使用resolution里设置的B版本。 参考:

https://blog.csdn.net/qq_21567385/article/details/112644629

engines

指定你的包客户必须使用的版本,如node版本(通过检查process.versions),yarn版本。

os

同上,检查操作系统(通过检查process.platform

cpu

同上,(process.arch

private

如果不想发布到包管理器,设置为true