首页 > Web开发 > 详细

package.json 配置全解

时间:2020-10-26 12:30:09      阅读:24      评论:0      收藏:0      [点我收藏+]

默认值

  • "scripts": {"start": "node server.js"}
    如果包的根目录有server.js文件,npm会默认将start命令设置为node server.js
  • "scripts":{"preinstall": "node-waf clean || true; node-waf configure build"}
    如果包的根目录有wscript文件,npm会默认将preinstall命令用node-waf进行编译。
  • "scripts":{"preinstall": "node-gyp rebuild"}
    如果包的根目录有binding.gyp文件,npm会默认将preinstall命令用node-gyp进行编译。
  • "contributors": [...]
    如果包的根目录有AUTHORS文件,npm会默认逐行按Name <email> (url)格式处理,邮箱和url是可选的。#号和空格开头的行会被

name

包名,必填

version

包版本 ,x.x.x  要符合语义化版本规则  ,必须能被node-server解析

改变包应该同时改变version

description

包的描述,便于在 npm search 中查找包

keywords

关键字 数组 字符串。方便npm search 中查找

homepage

项目官网的url

main

入口文件,一般是index.js

scripts

指定的运行脚本的npm命令行缩写,默认是空的test

author

作者的信息

license 

许可证,默认是ISC 有的默认是MIT ;

你应该要指定一个许可证,让人知道使用的权利和限制的。

如果你又更复杂的许可条件,或者想要提供给更多地细节,可以这样:

"licenses" : [   { "type" : "MyLicense"   , "url" : "http://github.com/owner/project/path/to/license"   } ]??  

bugs

项目提交问题的url 和(或)邮件地址。  可以是对象也可以是字符串

{ "url" : "http://github.com/owner/project/issues"
, "email" : "project@hostname.com"
}? 

 

files

是包里面包含文件的数组。如果包含文件夹,则文件夹下面的文件都包含。也可以用.npmignore文件。

bin

repository

代码存放的地址

config

字段用于添加命令行的环境变量

"config" hash可以用来配置用于包脚本中的跨版本参数。在实例中,如果一个包有下面的配置:

{ "name" : "foo"
, "config" : { "port" : "8080" } } 

然后有一个“start”命令引用了npm_package_config_port环境变量,用户可以通过npm config set foo:port 8001来重写他。

dependencies

在生产环境中需要用到的依赖

devDependencies

在开发、测试环境中用到的依赖

browserslist

指定该模板供浏览器使用的版本

"repository" :
  { "type" : "git"
  , "url" : "http://github.com/isaacs/npm.git"
  }

"repository" :
  { "type" : "svn"
  , "url" : "http://v8.googlecode.com/svn/trunk/"
  }? 

 

package.json 配置全解

原文:https://www.cnblogs.com/xuefang-yang/p/13877446.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!