npm安装时--save-dev如何让保存在package.json中的semver以~开头,而不是^开头 ?


比如我执行了 npm install --save-dev del 后,package.json里自动在 devDependencies 添加了一条依赖,但是我不希望他是以 ^ 开头,我希望他默认是以 ~ 开头。这个需要什么特殊设置吗


 {
  "name": "xxx",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "xxxx",
  "license": "MIT",
  "devDependencies": {
    "del": "^1.1.1"
  }
}

希望执行完安装命令后是这样的结果


 {
  "name": "xxx",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "xxxx",
  "license": "MIT",
  "devDependencies": {
    "del": "~1.1.1"
  }
}

npm node.js

哆啦炼金术师 9 years, 10 months ago

首先明确这两个的区别:

  • ~version "Approximately equivalent to version" See semver(7)
  • ^version "Compatible with version" See semver(7)

然后可能有用到的命令行:

  • npm install
  • npm install [@/]@
发呆的懒猫 answered 9 years, 10 months ago


 npm install qqtea --save-dev --save-prefix=~

clipboard.png

clipboard.png

CCP和冰岛人 answered 9 years, 10 months ago

Your Answer