npm -v 查看當前版本號
npm init 初始化項目
npm install 依賴名稱 下載依賴
npm init執行後會生成package.json
{
"name": "npmdemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
}
npm install jquery 執行後在package.json文件中會增加依賴
{
"name": "npmdemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.5.1"
}
}
同時會生成package-lock.json的文件 , 此文件功能爲鎖定版本號
{
"name": "npmdemo",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"jquery": {
"version": "3.5.1",
"resolved": "https://registry.npm.taobao.org/jquery/download/jquery-3.5.1.tgz",
"integrity": "sha1-17TQjhv9uGrS8aPQOeoXMEcXq7U="
}
}
}
npm加速器 , 配置鏡像到taobao
在終端中輸入 npm config set registry https://registry.npm.taobao.org
#查看npm配置信息
npm config list
根據配置文件下載相對應得依賴
npm install
添加局部插件 , 僅供當前項目使用
npm install --save-dev eslint
或
npm install -D eslint
安裝全局插件 , 供所有項目使用
npm install -g webpack
更新包到最新版本
npm update 包名
全局更新
npm update -g 包名
卸載包
npm uninstall 包名
全局卸載
npm uninstall -g 包名