npm的使用

1,553 阅读1分钟

npm是Node Package Manger 的缩写,是node的包管理工具。

npm的使用说明如下:
以underscore插件为例

// 查看所有安装的包
npm list

// 查看underscore最新的版本
npm info underscore

// 查看underscore最新的版本(同 npm info underscore)
npm view underscore version

// 查看underscore所有的版本
npm view underscore versions

// 安装underscore特定版本
npm install underscore@1.8.0

// 查看underscore包的版本信息
npm ls underscore

// 查看全局中underscore包的版本信息
npm ls underscore -g

// 卸载underscore
npm uninstall underscore

// 只装生产环境的包
npm i --production

// 查看过期包
npm outdated

// 版本更新
npm update

// 清除缓存
npm cache clean --force

// 注册npm仓库账号 www.npmjs.com 上面的账号
npm adduser

// 上传包
npm publish

// 查看npm源:
npm config get registry

// 切换npm源方法一:
npm config set registry registry.npmjs.org

// 切换npm源方法二:
nrm use npm

// 卸载包

查看当前项目引用了哪些包
npm ls
卸载包:
npm unpublish --force

// npm 安装git上发布的包

# 这样适合安装公司内部的git服务器上的项目
npm install git+https://git@github.com:lurongtao/gp-project.git

#或者以ssh的方式
npm install git+ssh://git@github.com:lurongtao/gp-project.git

在项目中一般这样用:
"devDependencies": {
    "@anyi/anyi-ui": "git+http://downloader:downloader@gogs.pms.anyi-tech.com/anyi-front/anyi-ui.git#1.2.37",
    ........
    ........
}