# .npmrc 常用配置

# 1. 镜像源

示例:

  • .npmrc:

    # 全局镜像源
    registry=https://registry.npmjs.org/
    
    # 包名以 `@xyz` 打头的包,走这个镜像源
    # 只能以 scope 来区分镜像源
    @xyz:registry=http://192.168.1.100/registry
    
  • package.json

    {
      "dependencies": {
        "@xyz/editor": "1.0.3"
      }
    }
    

参考:

# 2. 限制项目的 node 版本

说明:

  • 使用 npm install 安装项目依赖时,限制 node 的版本

使用:

  • package.json:

    {
      "engines": {
        "node": ">= 14.15.0"
      }
    }
    
  • .npmrc:

    engine-strict = true
    

参考:

本章目录