When npm is installed-how does –save-dev let semver saved in package.json begin with ~ instead of?

  node.js, question

For example, I did itnpm install --save-dev delAfter that, package.json inside automaticallydevDependenciesAdded a dependency, but I don’t want him to^At the beginning, I hope he defaults to~The beginning. Do you need any special settings for this

{
  "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"
  }
}

I hope this is the result after executing the installation command.

{
  "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"
  }
}

First of all, make clear the difference between the two:

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

Then there may be command lines to use:

  • npm install
  • npm install [@/]@