1 ️ ⃣ preface

No invasion, is not through the NPM config set registry http://registry.npm.taobao.org/ such as type of command to modify the registry to achieve the purpose of accelerating.

If you have written a package and uploaded it to NPM, this way of replacing Registry requires switching back to the official NPM mirror address when you publish using NPM.

At present, I solve the problem by replacing Registry. However, binary files like Node-sass are still downloaded from foreign addresses. So I have the following bunch of Registry to replace

npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass # Node-sass binary package mirroring
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/ # electron Binary packet mirroring
npm config set puppeteer_download_host https://npm.taobao.org/mirrors # puppeteer binary package mirroring
npm config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver # ChromeDriver binary package image
npm config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver # operadriver Binary package mirror
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs # PhantomJS binary package image
npm config set selenium_cdnurl https://npm.taobao.org/mirrors/selenium Selenium binary package mirroring
npm config set node_inspector_cdnurl https://npm.taobao.org/mirrors/node-inspector # Node-inspector binary package image
npm config set node_sqlite3_binary_host_mirror https://npm.taobao.org/mirrors
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/

yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass # Node-sass binary package mirroring
yarn config set electron_mirror https://npm.taobao.org/mirrors/electron/ # electron Binary packet mirroring
yarn config set puppeteer_download_host https://npm.taobao.org/mirrors # puppeteer binary package mirroring
yarn config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver # ChromeDriver binary package image
yarn config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver # operadriver Binary package mirror
yarn config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs # PhantomJS binary package image
yarn config set selenium_cdnurl https://npm.taobao.org/mirrors/selenium Selenium binary package mirroring
yarn config set node_inspector_cdnurl https://npm.taobao.org/mirrors/node-inspector # Node-inspector binary package image

Copy the code

Very inconvenient, recently found a non-intrusion solution tool, tried for a while, very easy to use.

2 ️ ⃣ tbify

Making: tbify

The principle of

Based on environmental variables, the resource addresses with poor domestic request speed are replaced, which can be divided into two points:

  • Using environment variables to enable package management tools (npm,npx,yarn,pnpm,pnpx) Use Taobao source to install dependencies;
  • Using environment variables such asnvm,node-sass,Electron,Puppeteer,Cypress,SharpSuch packages use Taobao image to install their own resources.

Above, this tool to the package management tool itself zero intrusion, at the same time, the setting of environment variables is one-time, will not produce any side effects, please rest assured to use.

The installation

# npm
npm install tbify --global

# yarn
yarn global add tbify

# pnpm
pnpm add --global tbify
Copy the code

use

For common package management commands, tbify provides the equivalent command to use Taobao NPM mirror, except that NPM publish must be used when publishing packages to NPM.

The original order Use the command of Taobao NPM image The sample
nvm tnvm(ortbify nvm) TNVM install 8.0.0
npm tnpm(ortbify npm) tnpm install react
npx tnpx(ortbify npx) tnpx kill-port 3000
yarn tyn(ortbify yarn) tyn add react
pnpm tpm(ortbify pnpm) tpm add react
pnpx tpx(ortbify pnpx) tpx kill-port 3000

For other commands, use the tbify prefix, such as:

tbify printenv npm_config_registry
# -> https://r.npm.taobao.org
Copy the code

3️ attention

  1. If you have a replacement binary file download address better change back
  2. npmyarnregistryChange it back to official

About me

SunSeekerX, front-end development, Nodejs development, applets, Uni-app development, etc

Like to discuss technical implementation schemes and details, perfectionist, not afraid of bugs.

Github:github.com/SunSeekerX

Personal blog: yoouu.cn/

Personal online notes: sunseekerx.yoouu.cn/