Introduction#
npm and yarn change the default download repository center address, you must set it or it will be painfully slow.
Generally, the mirror site provided by the Taobao team is used: https://npmmirror.com.
Automated Source Switching Settings#
It is recommended to use the open-source tool chsrc for automatic settings.
Steps:
- Download the executable file for your operating system from the Releases page. I am using Windows, so I downloaded
chsrc-x64-windows.exe
. - Then open the terminal and execute
chsrc-x64-windows.exe list
to see the software that supports source switching, etc. - Since we are using nodejs, execute
chsrc-x64-windows.exe set nodejs
in the terminal, and then wait for it to complete; this process is automatic.
Manual Global Settings#
npm Global Settings#
npm config set registry https://registry.npmmirror.com
npm config set disturl https://npmmirror.com/mirrors/node
# Set the following according to your situation
npm config set electron_mirror https://registry.npmmirror.com/electron/
npm config set sass_binary_site https://registry.npmmirror.com/node-sass/
yarn Global Settings#
yarn config set registry https://registry.npmmirror.com -g
yarn config set disturl https://npmmirror.com/mirrors/node -g
# Set the following according to your situation
yarn config set electron_mirror https://registry.npmmirror.com/electron/ -g
yarn config set sass_binary_site https://registry.npmmirror.com/node-sass/ -g
Manually Set yarn for a Single Project#
Create a .yarnrc
file in the project root directory, then paste the following content into it and save:
registry https://registry.npmmirror.com
disturl https://npmmirror.com/mirrors/node
# Set the following according to your situation
electron_mirror https://registry.npmmirror.com/electron/
sass_binary_site https://registry.npmmirror.com/node-sass/
Note#
The above configuration will only be used when adding new dependencies, the download addresses of old dependency packages are saved in the lock file and need to be modified manually. For example, the modification method for yarn.lock
is as follows:
Replace all instances of https://registry.yarnpkg.com
in the yarn.lock
file with https://registry.npmmirror.com
.