Back to blog

npm

npm使用

2.1使用npm配置淘宝镜像

#1.临时使用
npm--registryhttps://registry.npmmirror.cominstallexpress

#2.永久配置
npmconfigsetregistryhttps://registry.npmmirror.com
#验证配置
npmconfiggetregistry

#3.通过.npmrc文件配置(推荐)
#在项目根目录或用户主目录下创建.npmrc文件
echo"registry=https://registry.npmmirror.com">.npmrc

2.2安装使用cnpm

#安装cnpm
npminstall-gcnpm--registry=https://registry.npmmirror.com

#使用cnpm安装包
cnpminstallexpress

#查看cnpm版本
cnpm-v

三、常用的国内镜像源

1.淘宝NPM镜像(推荐)

https://registry.npmmirror.com

2.华为云镜像

https://mirrors.huaweicloud.com/repository/npm/

3.腾讯云镜像

http://mirrors.cloud.tencent.com/npm/

四、新项目运行前端三步走

1.npminstall 2.npmrunbuild 3.npmrundev