9
头图

foreword

Hello everyone, my name is Lin Sanxin. uses the most and easy-to-understand words to describe the most difficult knowledge points. is my .

background

I don’t know if you have noticed during development, but there are two files in your project:

  • package.json
  • package-lock.json

It should be that many people usually do not pay attention to the relationship between these two files! Let me tell you a little bit today, so that when the interviewer asks next time, everyone can also hold a cup~~

example

background

In package.json , the version of vue is ^2.6.14 .

"vue": "^2.6.14",

^ means that if Vue updates the minor version 2.6.15 under the major version 2 in a few days, then when you npm install , Vue will automatically upgrade to 2.6.15

caused problems

For example, there are programmer A and programmer B two developers

  • Programmer A: The version of Vue was 2.6.14 when he took over the project, and he has been using this version
  • Programmer B: Join this project a month later, at this time Vue has been upgraded to 2.9.14 , and it will be automatically upgraded when npm install

Summary: This will lead to different versions of Vue when two people are developing, which will lead to some problems and errors in cooperative development.

package-lock.json

package-lock.json can solve the above problems, his role is: lock the version number of the installation module

For example, there are two developers, , programmer A and programmer B.

  • Programmer A: The version of Vue was 2.6.14 when he took over the project, and this version was locked at package-lock.json
  • Programmer B: Join this project a month later. At this time, Vue has been upgraded to 2.9.14 and npm install . It is reasonable to say that it will be automatically upgraded. However, since the version package-lock.json is locked in 2.6.14 , the automatic upgrade is prevented, and the guaranteed version is still 2.6.14

Epilogue

I'm Lin Sanxin, an enthusiastic front-end rookie programmer. If you are motivated, like the front-end, and want to learn the front-end, then we can make friends and fish together haha, touch the fish group, add me, please note [Si No]

image.png


Sunshine_Lin
2.1k 声望7.1k 粉丝