package.json概述
當執行npm install指令的時候,會根據package.json檔案中的設定自動下載所需的模組
紀錄這個專案的各種模組,以及專案的設定資訊(例如名稱、版本、授權等)
name:必填的
必須小於等於214個字符,不能以.或_開頭,不能有大寫字母,因為名稱最終成為URL的一部分因此不能包含任何非URL安全字符。
version:必填的
名稱和版本一起構成一個標識符,該標識符被認為是完全唯一的
description
是一個字串組成的數組,有助於人們在npm庫中搜尋的時候發現你的模組
private
如果這個屬性被設定為true,npm將拒絕發布它,這是為了防止一個私有模組被無意間發佈出去
homepage
項目的主頁地址
bugs
用於專案問題的回饋issue地址或一個郵箱。
license
是目前專案的協議,讓使用者知道他們有何權限來使用你的模組,以及使用該模組有哪些限制。
author
author是具體一個人,contributors表示一群人,他們都表示當前專案的共享者。同時每個人都是一個物件。具有name欄位和可選的url及email欄位。
scripts 執行腳本指令
執行腳本指令的npm命令列縮寫,例如start指定了執行npm run start時,所要執行的命令。
dependencies 指定了專案運作所依賴的模組
當安裝依賴的時候使用–save參數表示將該模組寫入dependencies屬性
devDependencies
–save-dev表示將該模組寫入devDependencies屬性。
peerDependencies
bundledDependencies 指定發佈的時候會被一起打包的模組
engines 欄位指明了該模組運作的平台
例如Node或npm的某個版本或瀏覽器。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| { "name": "unit_test_project", //必填的 "private": true, "version": "0.0.0", "description": "unit_test", "keywords":["node.js","unit test", "theme"], "homepage": "https://zhiqianduan.com", "author": "larahuang", "man" :[ "./doc/calc.1" ] "type": "module", "bugs": { "url" : "https://github.com/owner/project/issues", "email" : "project@hostname.com" } "scripts": { "dev": "vite", "build": "vue-tsc -b && vite build", "test:unit": "vitest --environment jsdom", "preview": "vite preview" }, "config": { "port" : "5173" }, "dependencies": { "vue": "^3.4.31" }, "devDependencies": { "@vitejs/plugin-vue": "^5.0.5", "@vue/test-utils": "^2.4.6", "jsdom": "^24.1.1", "typescript": "^5.2.2", "vite": "^5.3.4", "vitest": "^2.0.4", "vue-tsc": "^2.0.24" }, { "engines" : { "node" : ">=0.10.3 <0.12", "npm" : "~1.0.20" } } }
|
參考資料
package.json文件