使用nodeJS有一段時間了,npm也是隨時都在用,因此呢,須要把一些遇到的問題和常見用法作一個簡單小結。 vue
1、最最最容易產生的疑問:
npm i --save , npm i --save-dev , npm i 三者區別
關於前二者的區別的答案,處處都有。
他倆的區別主要是:node
使用save安裝的模塊,是生產環境(運行環境)須要使用的模塊,好比:vue,axios,jsonp等,它們會被添加到package.json配置文件的dependencies位置;ios
使用save-dev安裝的模塊,是開發環境中使用的模塊,例如在開發環境中對es6,es7進行編譯的,而在生產環境中代碼已經轉義打包完畢了,再也不須要這些模塊。如:babel模塊,eslint模塊,autoprefixer, mocha等,用於編譯,轉義,語法檢查、測試等的功能模塊;這些模塊就須要被添加到package.json文件的devdependencies位置。es6
效果同 npm install XXX --savenpm
--no-save: Prevents saving to dependencies.
2、npm 版本查看json
npm -v 5.6.0
3、升級npm版本axios
npm install npm -g
4、卸載模塊babel
npm uninstaill XXX(模塊名) //卸載後使用,如下命令查看 npm ls
5、更新模塊測試
npm update XXX npm update XXX -g
-g 把該模塊在全局更新到最新版本,沒有-g是把當前node_modules子目錄中的對應模塊更新到最新版本。 jsonp
6、使用淘寶鏡像npm,用cnpm代替npm
若是使用npm速度比較慢,能夠採用淘寶定製的cnpm來代替npm。
npm install -g cnpm --registry=https://registry.npm.taobao.org 這樣就可使用cnpm來安裝模塊了: cnpm install XXX
也能夠不用cnpm,對單個模塊使用淘寶鏡像安裝,
npm install XXX@latest --save --registry=https://registry.npm.taobao.org
關於淘寶鏡像可查閱:http://npm.taobao.org/。
7、關於命令別名縮寫
npm install = npm i npm i --save = npm i -S npm i --save-dev = npm i -D
8、指定安裝模塊的版本
npm install XXX@latest npm install XXX@0.1.1
Install the version of the package that is referenced by the specified tag. If the tag does not exist in the registry data for that package, then this will fail.
npm install更詳細的信息見:https://docs.npmjs.com/cli/in...