NPM入門筆記

weixin_33766168發表於2017-01-20

參考資料

NPM是啥

  • 基於Nodejs執行

  • 軟體模組管理工具(軟體包工具), 對應我這個Javaer來說,有點類似於Maven

  • 現在普遍用於web前端專案的管理, 主要是各種依賴庫的管理

  • 命令列形式執行

安裝

安裝Node

  • https://nodejs.org/en/download/

  • 速度非常快,完全不像國外的網站

  • windows, linux, 32/65bit, 各個版本齊全

  • 驗證成功:
    node --version

  • Node命令的語法跟通常有點不同, 首先,引數都是加兩個-的, 其次, 命令以.開頭,比如:

$ node
> console.log('Node is running');
Node is running
> .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.exit  Exit the repl
.help  Show repl options
.load  Load JS from a file into the REPL session
.save  Save all evaluated commands in this REPL session to a file> .exit

安裝NPM

  • Node裝完以後, npm連帶著就裝上了, 可以直接驗證
    $ npm --version

安裝軟體包

教程裡關於預設位置和引數的修改,就直接跳過了, 先嚐試使用

  • 先嚐試簡單的安裝
    npm install uglify-js --global

  • 發現預設源安裝好慢,簡直無法容忍,還是換一個吧,淘寶有國內映象:
    https://npm.taobao.org/
    安裝方式:
    npm install -g cnpm --registry=https://registry.npm.taobao.org
    以後就使用cnpm來代替npm了

  • 再次嘗試原來的命令
    cnpm install uglify-js --global
    迅速完成

  • 本地安裝: npm最好的地方在於, 預設情況下(不帶--global引數), 是安裝到本地資料夾的.
    npm install underscore

  • 檢視本地安裝包: npm list

  • 發現cnpm不是萬能的, 剛才的underscore就,沒有, 拿Vue來練手倒是成功了
    npm install vue

相關文章