关于npm:npm功能介绍及常用命令

10次阅读

共计 1618 个字符,预计需要花费 5 分钟才能阅读完成。

npm 性能

特地阐明:所有 -g 全局操作,在 mac 下都须要增加 sudo 权限执行

性能:

  • 包管理工具(包含:下载,删除,更新,查看,链接,公布)

装置:

  • 随着 node 的装置会主动装置(版本升级:sudo npm install npm -g)

毛病:

  • 默认源服务器在国外:须要设置成国内的代理源,或者应用 proxy 代理网络拜访

    • 丢包

npm 常用命令

npm 常用命令

  • npm 版本查看:npm -v
  • npm 帮忙文档:

    • npn help // 简略帮忙文档
    • npm -l // 具体帮忙文档
    • npm config –help // 查看子命令,简略文档
    • npm help config // 查看子命令, 具体文档
  • 查看 npm 配置文件:

    • npm config list // 查看
    • npm config edit // 编辑

npm 依赖相干命令

  • 装置依赖

    • 本地装置

      • 无需打包(devDependencies):

        • npm i prettier,npm i prettier -D // 两种写法成果一样
      • 须要打包(dependencies 对象中):

        • npm install vue-router@0.7.13 -S // 装置指定版本的依赖
      • 装置 package.json 指定的依赖:

        • npm i
    • 全局装置 (要执行全局装置的命令):

      • npm i typescript -g
  • 卸载依赖

    • npm uninstall react
    • npm uninstall typescript -g
  • 革除 npm 缓存:

    • npm cache clean
    • npm cache clean –force

npm 代理设置相干

  • 代理设置:npm 会通过你的代理地址,申请近程包

    • npm config set proxy=http://127.0.0.1:2012 //
    • npm config set https-proxy http://127.0.0.1:2012 // 成果和下面一样
  • npm 源指定 (这里设置会永恒失效,倡议应用 nrm 来治理,不便切换淘宝源,和官网源,毕竟有工夫淘宝源同步时效有问题,没官网精确)

    • npm config set registry=http://registry.npmjs.org // 应用 npm 官网源
    • npm config set registry https://registry.npmmirror.com // 应用淘宝源
    • npm install -g cnpm –registry=https://registry.npm.taobao.org // install 和 registry 联结应用,cnpm ,npm 命令离开 【举荐】
  • 勾销代理

    • npm config delete proxy // 勾销网络代理
    • npm config delete https-proxy // 勾销 http 协定的代理
    • npm config set proxy null
    • npm config set https-proxy null
  • npm 代理设置查看

    • npm get registry // 代理源查看
    • npm get proxy, npm get http-proxy
    • npm get registry

其余

  • npm link // 连贯到本地
  • npm unlink myCli // 勾销连贯到本地
  • npm view react versions // 查看某个依赖的全副版本:

公布包三步曲命令

  • npm init // 初始化:本地生成 package.json 文件
  • npm login // 登陆:也能够应用 npm adduser 命令注册
  • npm publish // 公布 (吊销公布:npm unpublish myCli@1.0.1)

nrm 根本应用

  • npm i nrm -g // 全局装置 nrm
  • nrm ls // 查看源列表
  • nrm test // 测试源速度
  • nrm use taobao // 应用指定的源

参考资料

  • npm 菜鸟教程:https://www.runoob.com/nodejs…
  • 淘宝 npm 镜像设置:http://www.npmmirror.com/?spm…
  • npm 官网命令大全:https://docs.npmjs.com/cli/v8…
  • 整顿总结:npm 常用命令与操作篇 https://zhuanlan.zhihu.com/p/…
正文完
 0