node.js模組依賴及版本號碼

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   使用   sp   

摘要:

  Node.js最重要的一個檔案就是package.json,其中的配置參數決定了功能。例如下面就是一個例子

{  "name": "test",  "version": "1.0.0",  "description": "test",  "main": "main.js",  "keywords": [    "test"  ],  "author": "wade",  "license": "MIT",  "dependencies": {    "express": "^4.10.1"  },  "devDependencies": {    "jslint": "^0.6.5"  }}

 

dependencies與devDependencies:  

  一個node package有兩種依賴,一種是dependencies,另一種是devDependencies,其中前者依賴的項是正常運行該包時所需要的依賴項,而後者則是開發的時候需要的依賴項,像一些進行單元測試之類的包。簡單來記就是下面的

"dependencies": {}     //生產環境

"devDependencies": {}//開發環境

  在package.json所在目錄執行npm install的時候,devDependencies裡面的模組也會被安裝的。如果我們只想安裝dependencies裡面的包,可以執行

npm install --production

如果只安裝devDependencies,可以執行

npm install --dev

同理,使用npm install node_module –save自動更新dependencies欄位值,使用npm install node_module –save-dev自動更新devDependencies欄位值。

版本號碼:

  每一個模組後面對應的就是他的版本號碼,如"^4.10.1"。下面是幾個版本的運算式

運算式 版本範圍
>=1.2.7 大於等於1.2.7
>=1.2.7 <1.3.0 1.2.7,1.2.8,1.2.9
1.2.3 - 2.3.4 >=1.2.3 <=2.3.4
1.2 - 2.3.4 >=1.2.0 <=2.3.4
1.2.3 - 2.3 >=1.2.3 <2.4.0
1.2.3 - 2 >=1.2.3 <3.0.0
* >=0.0.0
1.x(等價於1.X) >=1.0.0 <2.0.0
1.2.x >=1.2.0 <1.3.0
""(等價於*) >=0.0.0
1(等價於1.x.x) >=1.0.0 <2.0.0
1.2(等價於1.2.x) >=1.2.0 <1.3.0
~1.2.3(>=1.2.3 <1.(2+1).0) >=1.2.3 <1.3.0
~1.2(>=1.2.0 <1.(2+1).0) >=1.2.0 <1.3.0
~1(>=1.0.0 <(1+1).0.0) >=1.0.0 <2.0.0
~0.2.3(>=0.2.3 <0.(2+1).0) >=0.2.3 <0.3.0
~0.2(>=0.2.0 <0.(2+1).0) >=0.2.0 <0.3.0
~0(>=0.0.0 <(0+1).0.0) >=0.0.0 <1.0.0
~1.2.3-beta.2 >=1.2.3-beta.2 <1.3.0
^1.2.3 >=1.2.3 <2.0.0
^0.2.3 >=0.2.3 <0.3.0
^0.0.3 >=0.0.3 <0.0.4
^1.2.3-beta.2 >=1.2.3-beta.2 <2.0.0
^0.0.3-beta >=0.0.3-beta <0.0.4
^1.2.x >=1.2.0 <2.0.0
^0.0.x >=0.0.0 <0.1.0
^0.0 >=0.0.0 <0.1.0
^1.x >=1.0.0 <2.0.0
^0.x >=0.0.0 <1.0.0

 

參考文獻:

  http://stackoverflow.com/questions/22343224/difference-between-tilde-and-caret-in-package-json

  https://www.npmjs.org/doc/misc/npm-config.html#production

 

node.js模組依賴及版本號碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.