Introduction#
npm and yarn change the default download repository center address. Be sure to set it, otherwise it will be extremely slow.
Usually, the mirror provided by the Taobao team is used: https://npmmirror.com.
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 own 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 own 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
Setting for Individual Yarn Projects#
Create a .yarnrc
file in the root directory of the project, and 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 own 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 dependencies are saved in the lock file and need to be manually modified. For example, the modification method for yarn.lock is as follows:
Replace all instances of https://registry.yarnpkg.com
with https://registry.npmmirror.com
in the yarn.lock
file.
References#
● https://www.cnblogs.com/myesn/p/14994938.html
● https://stackoverflow.com/questions/70590169/install-package-from-private-registry-using-yarn-in-docker
● https://www.cnblogs.com/fmixue/p/16375938.html