每个包需要在其顶层目录下包含一个package.json文件,该文件不仅是包的说明,也影响npm安装包时的配置选项
更多参数详见参考文档https://npmjs.org/doc/json.html
{ "name": "cordova", "version": "3.0.4", "preferGlobal": "true",//如果安装包是作为命令行应用程序,应该全局模式安装,如果用户使用本地模式安装,则警告提醒 "description": "Cordova command line interface tool", "main": "cordova", //表示Node.js在调用某个模块的时候,将寻找main指向的路径作为模块的接口,在这里Node将寻找同目录下的cordova文件,并尝试从它那加载模块; //如果没有cordova,Node还是会尝试寻找cordova.js或者cordova.node作为包的接口。 //相当于这是初始化函数,返回此文件中export的对象内容 "engines":{ "node":">=0.9.9" //指定使用node的版本 }, "engineStrict":true, //如果确定模块只能能在engines 参数指定的版本正常工作,则设置此参数 "bin": { "cordova": "./bin/cordova" //用户在命令行输入时,解析参数执行此文件cordova文件
#!/usr/bin/env node var CLI = require('../src/cli'); new CLI(process.argv);
}, "scripts": { "test": "jasmine-node --color spec" //存储一些默认运行命令脚本信息 //cordova test 执行 jasmine-node --color spec }, "repository": { "type": "git", "url": "https://git-wip-us.apache.org/repos/asf/cordova-cli.git" // 存储位置 }, "bugs":{ "url" : "https://issues.apache.org/jira/browse/CB", "email" : "dev@cordova.apache.org" }, "keywords": [ "cordova", "client", "cli" ], "dependencies": { "colors":">=0.6.0", "elementtree":"0.1.3", "plugman":"0.10.0", "plist":"0.4.x", "xcode":"0.5.1", "express":"3.0.0", "shelljs":"0.1.2", "ncallbacks":"1.0.0", "request":"2.22.0", "ripple-emulator":"0.9.18", "semver":"1.1.0", "glob":"3.2.x", "follow-redirects":"0.0.x", "prompt":"0.2.7", "tar":"0.1.x", "open": "0.0.3", "npm":"1.3.x", "optimist":"0.6.0" }, /*依赖模块列表 version 版本号必须精确匹配 >version 必须大于当前版本号 >=version 必须大于等于 <version 小于 <=version 小于等于 ~1.2.3 := >=1.2.3-0 <1.3.0-0 1.3.0-beta 不满足 ~1.2.3支持条件 ~1.2 := >=1.2.0-0 <1.3.0-0 以1.2开始的版本 1.2.x := >=1.2.0-0 <1.3.0-0 以1.2开始的版本 ~1 := >=1.0.0-0 <2.0.0-0 以1开始的版本 1.x := >=1.0.0-0 <2.0.0-0 以1开始的版本 1.2.x 1.2.0, 1.2.1,等,不超过 1.3.0 http://... 见链接地址 * 匹配任意版本 "" 匹配任意版本 version1 - version2 等价于 >=version1 <=version2. range1 || range2 range1 或 range2均可 git... 见git地址 user/repo见 'GitHub ' 地址 */ "devDependencies": { "jasmine-node":"1.8.x" }, / /开发阶段使用的模块,在用户使用时不需要依赖的模块 "author": "Anis Kadri", //开发者 "contributors": [ {"name": "Brian LeRoux","email": "b@brian.io"}, {"name": "Fil Maj", "email": "maj.fil@gmail.com"}, {"name": "Mike Reinstein", "email":"reinstein.mike@gmail.com"}, {"name": "Darry Pogue", "email":"darryl@dpogue.ca"}, {"name": "Michael Brooks", "email":"michael@michaelbrooks.ca"}, {"name": "Braden Shepherdson", "email":"braden@chromium.org"}, {"name": "Gord Tanner", "email":"gtanner@gmail.com"}, {"name": "Tim Kim", "email": "timk@adobe.com"}, {"name": "Benn Mapes", "email": "Benn.Mapes@gmail.com"}, {"name": "Michael Wolf", "email": "Michael.Wolf@Cynergy.com"}, {"name": "Andrew Grieve", "email": "agrieve@chromium.org"}, {"name": "Bryan Higgins", "email": "bhiggins@blackberry.com"}, {"name": "Don Coleman", "email": "dcoleman@chariotsolutions.com"}, {"name": "Germano Gabbianelli", "email": "tyron.mx@gmail.com"}, {"name": "Ian Clelland", "email": "iclelland@chromium.org"}, {"name": "Lucas Holmqust", "email": "lholmqui@redhat.com"}, {"name": "Matt LeGrand", "email": "mlegrand@gmail.com"}, {"name": "Michal Mocny", "email": "mmocny@gmail.com"}, {"name": "Sam Breed", "email": "sam@quickleft.com"}, {"name": "Tommy-Carlos Williams", "email": "tommy@devgeeks.org"}, {"name": "Rubén Norte", "email": "rubennorte@gmail.com"} //贡献者人员信息 ], "license": "Apache version 2.0" }