2016-02-26 160 views
0

當我試圖安裝一個單獨的模塊到項目中,像一飲而盡,它安裝所有node_module ...爲什麼NPM install安裝所有node_modules

我不知道這些模塊來的,我得到這樣99文件夾放入node_modules文件夾中,當我只想安裝一個。

+0

這不是真的。這只是吞噬需要的所有軟件包。這是javascript開發的文化:開發人員編寫小部分代碼(有時非常小),易於維護,然後使用其他人員的代碼來獲取所需功能。開發人員沒有浪費時間編寫代碼來打印顏色(他們使用粉筆)或編寫代碼來並行管理產卵任務(他們使用編排器)等等。所以吞嚥依賴於13個包,它們本身依賴於更多的包等。 – slebetman

+0

[npm dependancies installation,confused]可能重複(https://stackoverflow.com/questions/31317925/npm-dependancies-installation-confused) –

回答

0

這是按設計。 @https://docs.npmjs.com/cli/install,總結爲:該命令將安裝一個軟件包以及它所依賴的任何軟件包。

這裏是算法定義在頁面:

load the existing node_modules tree from disk 
clone the tree 
fetch the package.json and assorted metadata and add it to the clone 
walk the clone and add any missing dependencies 
    dependencies will be added as close to the top as is possible 
    without breaking any other modules 
compare the original tree with the cloned tree and make a list of 
actions to take to convert one to the other 
execute all of the actions, deepest first 
    kinds of actions are install, update, remove and move 
相關問題