Skip to content
On this page

package.json配置详解

创建package.json文件

js
// -y 代表所有的基础参数均为默认
npm init -y

参数说明

js
{
    /**
    *  包名,如果期望发布企业包(如@dt-frames/ui),需要将npm账号改为企业账号,
    *  可以参考地址https://blog.csdn.net/weixin_43990297/article/
    *  details/122359702
    */ 
    "name": "@dt-frames/ui", 
    // 发布的版本,必须以'大版本号.小版本号.小小版本号'这种格式命名   
	"version": "1.0.37",
    // npm包的关键字
	"keywords": [
		"ui",
		"dt-ui"
	],
    // 指定加载的入口文件
    "main": "src/index.ts",
    // 如果发布npmn包,files中的文件都会推送到npm服务器
    "files": [
        "LICENSE",
        "Readme.md",
        "index.js",
        "lib/"
    ],
    // 发布npm需要配置源,否则拉不下来,我用的是下面这个
	"publishConfig": {
		"access": "public",
		"registry": "https://registry.npmjs.org/"
	},
    // npm包指向的文件
	"exports": {
		"import": "./es/index.js",
		"require": "./lib/index.js"
	},
    // npm包类型指向的文件
	"types": "./es/index.d.ts",
    // 是否进行摇树优化
	"sideEffects": false,
}