npm常用的命令大全(精選)
阿新 • • 發佈:2021-01-08
npm主要是node包管理和釋出的工具。
一.常用的nodeJS中npm的命令:
1.(下載包) 下載後的包放在當前路徑下面 npm install express 下載express模組
npm install <name>
2.-g 將包安裝到全域性環境中,我PC的全域性環境是:C:\Users\qinbb\AppData\Roaming\npm,但是在程式碼中直接通過require()的方式是沒有辦法呼叫全域性安裝的包的
npm install <name> -g
3.<name>指的是需要下載的包名, --save是指下載的包中包含package.json,將資訊寫入package.json中
方法就可以根據dependencies配置安裝所有的依賴包(類似於maven的pom檔案),這樣程式碼提交到github時,就不用提交node_modules這個檔案夾了。
npm install <name> --save
4.刪除下載的包並且刪除package.json中的dependencies配置
npm uninstall <name> --save
5.更新模組
npm update <name>
6.查詢模組是否過時
npm outdated
7.更改模組內容再重建
npm rebuild <name>
8.檢視node模組的package.json資料夾 檢視package.json資料夾中某個標籤,$npm view mouleNames lableName
npm view <name>
9.檢視某個模組的package.json中的dependencies 模組依賴關係
npm view <name> dependencies
10.檢視安裝的模組,搜尋是從程式碼執行的當前目錄開始的,搜尋結果取決於當前使用的目錄中的node_modules下的內容
npm list
11.引導你建立一個package.json檔案,包括名稱、版本、作者這些資訊等
npm init
12.檢視當前包的安裝路徑 npm root -g:檢視全域性的包的安裝路徑
npm root
13.檢視npm安裝的版本檢視npm安裝的版本
npm -v
14.檢視所有可以下載包的版本 如: npm info antd
npm info 包名
15.如果你開啟的是別人的專案,這個時候一般是沒有任何依賴包的,但是所以需要的包已在package.json裡面寫好了,這個時候我們就可以使用npm install
來安裝所有專案中需要的依賴包了
npminstallpackagename -g 或--global
16npm set
用來設定環境變數
$ npm set init-author-name 'Your name'
$ npm set init-author-email 'Your email'
$ npm set init-author-url 'http://yourdomain.com'
$ npm set init-license 'MIT'
上面命令等於為 npm init
設定了預設值,以後執行 npm init
的時候,package.json 的作者姓名、郵件、主頁、許可證欄位就會自動寫入預設的值。這些資訊會存放在使用者主目錄的 ~/.npmrc 檔案,使得使用者不用每個專案都輸入。如果某個專案有不同的設定,可以針對該專案執行 npm config
。
二.vue-cli 工程常用的 npm 命令有哪些?
1. npm install:下載 node_modules 資源包的命令
2. npm run dev:啟動 vue-cli 開發環境的 npm命令
3.npm run build:vue-cli 生成 生產環境部署資源 的 npm命令
4.npm run build--report:用於檢視 vue-cli 生產環境部署資原始檔大小的 npm命令