通過npm init 創建 package.json文件
參數:
name:項目名字
version: 版本號
description: 項目介紹
main: 項目的入口文件
scripts: npm提供給我們運行shell命令的入口
author:作者
license:標注我們項目的許可證權限,如果不想開源({"license":"UNLICENSED"}或{"private":true})
dependencies:項目運行時必要依賴,
peerDependencies: 針對特定版本開發
devDependencies:項目開發時所需依賴
homepage:項目主頁的網址
files:將軟件包作為依賴項安裝時要包含的條目
完整的package.json
{ "name": "Hello World", //name屬性就是你的模塊名稱 "version": "0.0.1", //version必須可以被npm依賴的一個node-semver模塊解析 "author": "張三", //"author"是一個碼農 "description": "第一個node.js程序", //一個描述,方便別人了解你的模塊作用,搜索的時候也有用。 "mian":"index.js", //main屬性指定了程序的主入口文件. "keywords":["node.js","javascript"], //一個字符串數組,方便別人搜索到本模塊 "repository": { //指定一個代碼存放地址,對想要為你的項目貢獻代碼的人有幫助。 "type": "git", "url": "https://path/to/url" }, "license":"MIT", //你應該為你的模塊制定一個協議,讓用戶知道他們有何權限來使用你的模塊,以及使用該模塊有哪些限制,如BSD-3-Clause 或 MIT之類的協議 "engines": {"node": "0.10.x"}, "bugs":{ //填寫一個bug提交地址或者一個郵箱,被你的模塊坑到的人可以通過這里吐槽 "url":"https://github.com/luoshushu", "email":"bug@example.com" }, "contributors":[{"name":"李四","email":"lisi@example.com"}], // "contributors"是一個碼農數組。 "scripts": { //指定了運行腳本命令的npm命令行縮寫。比如:輸入npm run start時,所要執行的命令是node index.js。 "start": "node index.js" }, "dependencies": { //指定了項目運行所依賴的模塊 "express": "latest", "mongoose": "~3.8.3", "handlebars-runtime": "~1.0.12", "express3-handlebars": "~0.5.0", "MD5": "~1.2.0" }, "devDependencies": { //指定項目開發所需要的模塊 "bower": "~1.2.8", "grunt": "~0.4.1", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-jshint": "~0.7.2", "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-clean": "~0.5.0", "browserify": "2.36.1", "grunt-browserify": "~1.3.0", } }
小程序 也可能用到這個
轉:https://www.jianshu.com/p/9879273a09a1
https://www.jianshu.com/p/68f2608c7976