SoFunction
Updated on 2025-03-04

Vue’s role and explanation

The role of vue

What is its function?

A simple understanding is to lock the version number of dependencies.

Generally speaking, front-end projects have a version number for file management dependencies. In the file, we can see that the dependent version number has ^ and ~ symbols in the first half.

  • ^: Locking the large version number, such as ^6.2.2, will match all versions, and the latest version number will be downloaded when updating.
  • ~: Lock the previous two version numbers, such as ^6.2.2, which will match all 6. versions, and the latest version numbers will be downloaded when updating.
  • *: Install the latest version number.

Different download times, npm download sources are different, or different machines, the nodejs dependency packages obtained from downloading may be different.

So the effect comes out at this time.

It is to fix the current version to ensure that the package you installed will not be installed on a new machine or new

Downloading source and dependency packages are inconsistent, which reduces a lot of unnecessary trouble when developing, deploying, or collaborating with multiple people.

Let's give an example

The dependencies of the project currently tested are as follows

  "devDependencies": {
    "dayjs": "~1.9.4",
    "file-saver": "^1.2.0",
    "lodash": "*"
  },

Generally speaking, a newly created project does not have this file, and it will be automatically generated when executing npm install.

After executing npm install, we go to the node-modules directory to see the version numbers of these three packages.

    "dayjs": "1.9.8",
    "file-saver": "1.3.8",
    "lodash": "4.17.21"

Look at the generated file

 "dependencies": {
    "dayjs": {
      "version": "1.9.8",
     "dev": true
    },
    "file-saver": {
      "version": "1.3.8",
      "dev": true
    },
    "lodash": {
      "version": "4.17.21",
      "dev": true
    }
  }

The version and version number of the node_module dependency package are the same.

dayjs matches the latest version of 1., file-saver matches the latest version, and lodash matches the latest version.

When we need to update the version of the dependent package, we can implement it by executing npm install xxx@, and it will also be updated accordingly.

My local npm version is 6.10.2. I directly modify the version number and then npm install, which can also implement the version and update of the dependent package.

There is a saying online that this modification will not be supported after version 5.

If the download dependency is yarn install, then the file is used.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.