npm的包安裝分為本地安裝(local)、全局安裝(global)兩種,從敲的命令行來看,差別只是有沒有-g而已,比如:
文章源自四五設計網-http://www.wasochina.com/43989.html
[code]文章源自四五設計網-http://www.wasochina.com/43989.html
npm install grunt # 本地安裝文章源自四五設計網-http://www.wasochina.com/43989.html
npm install -g grunt-cli # 全局安裝文章源自四五設計網-http://www.wasochina.com/43989.html
[/code]文章源自四五設計網-http://www.wasochina.com/43989.html
下面分別解釋。文章源自四五設計網-http://www.wasochina.com/43989.html
1. npm install xxx -g 時, 模塊將被下載安裝到【全局目錄】中。文章源自四五設計網-http://www.wasochina.com/43989.html
【全局目錄】通過 npm config set prefix "目錄路徑" 來設置。文章源自四五設計網-http://www.wasochina.com/43989.html
通過 npm config get prefix 來獲取當前設置的目錄。文章源自四五設計網-http://www.wasochina.com/43989.html
2. npm install xxx ,則是將模塊下載到當前命令行所在目錄。文章源自四五設計網-http://www.wasochina.com/43989.html
例如:
[code]
c:\123>npm install xxx
[/code]
將會安裝到
[code]
c:\123\node_modules\xxx
[/code]
這種方式顯然是不好的,所以一般都會使用全局安裝方式統一安裝的一個目錄中去,這樣既方便管理、結構清晰還可以重復利用。


評論