Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当你输入npm install后,发生了什么 #376

Open
ShileiLiu opened this issue Dec 30, 2019 · 0 comments
Open

当你输入npm install后,发生了什么 #376

ShileiLiu opened this issue Dec 30, 2019 · 0 comments

Comments

@ShileiLiu
Copy link

ShileiLiu commented Dec 30, 2019

npm install 是大家用的最多的命令,但你知道输入后发生了什么吗?

以npm install react --save 为例

首先,npm会发送一个GET请求到镜像服务器,查询当前镜像关于react的相关信息,请求地址是 镜像地址/react (http://123.13.321.123:80/repository/ynpm-all/react)
这个接口会返回一个JSON信息,在里面会有不同版本的信息
image
可以看到,里面的dist-tag属性下就是相关的版本信息,其中latest就是我们不指定版本的情况下安装的默认版本

然后,当npm确定你要安装的版本后(手动指定、package规则或者默认)会在version里面查找到报的下载地址
image

之后,npm会请求这个地址下载这个压缩包,这还没完,npm会将这个压缩包暂存在本地的缓存文件夹里,然后才会解压缩到我们要安装的目录下的node_modules里,这样整个下载过程才算结束

当然,这个缓存是方便下次下载时直接在缓存里取出的,可以通过npm clean cache命令清楚缓存(慎用~)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant