NPM & yarn package non intrusion acceleration solution – fast batch

Time:2021-2-21

1. Preface

No invasion means no passagenpm config set registry http://registry.npm.taobao.org/And so onregistry To achieve the purpose of acceleration.

If you’ve ever written a package, upload it tonpmThis replacementregistry The way you use itnpm publishYou need to switch back when you contractnpmThe official image address.

Now I’m using replacementregistry That’s the solution. But likenode-sassThis kind of binary file download still uses the foreign address. So I have the following pileregistryIt needs to be replaced

npm config set sass_ binary_ site  https://npm.taobao.org/mirrors/node-sass  #Node sass binary package image
npm config set electron_ mirror  https://npm.taobao.org/mirrors/electron/  #Electronic binary package image
npm config set puppeteer_ download_ host  https://npm.taobao.org/mirrors  #Binary packet image of puppeter
npm config set chromedriver_ cdnurl  https://npm.taobao.org/mirrors/chromedriver  #Binary package image of chromedriver
npm config set operadriver_ cdnurl  https://npm.taobao.org/mirrors/operadriver  #Binary package image of operadriver
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 image
npm config set node_ inspector_ cdnurl  https://npm.taobao.org/mirrors/node-inspector  #Binary package image of node inspector
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 image
yarn config set electron_ mirror  https://npm.taobao.org/mirrors/electron/  #Electronic binary package image
yarn config set puppeteer_ download_ host  https://npm.taobao.org/mirrors  #Binary packet image of puppeter
yarn config set chromedriver_ cdnurl  https://npm.taobao.org/mirrors/chromedriver  #Binary package image of chromedriver
yarn config set operadriver_ cdnurl  https://npm.taobao.org/mirrors/operadriver  #Binary package image of operadriver
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 image
yarn config set node_ inspector_ cdnurl  https://npm.taobao.org/mirrors/node-inspector  #Binary package image of node inspector

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

2️⃣ tbify

Github:tbify

principle

Based on the environment variable, the resource address with low speed of domestic request is replaced

  • Using environment variables to make package management tools(npmnpxyarnpnpmpnpx)Use Taobao source to install dependency;
  • Through the environment variablenvmnode-sassElectronPuppeteerCypressSharpAnd other packages use Taobao image to install their own resources.

Above all, this tool has no invasion to the package management tool itself. At the same time, the setting of environment variables is one-time, and will not produce any side effects. Please rest assured to use it.

install

# npm
npm install tbify --global

# yarn
yarn global add tbify

# pnpm
pnpm add --global tbify

use

For common package management commands,tbifyProvides the equivalent command to use the Taobao NPM image, except when publishing packages to NPMnpm publishYou can use the equivalent command to perform related operations

Original order Command to use Taobao NPM image Examples
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, addtbifyPrefix, for example:

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

3. Precautions

  1. If you have a replacement binary file before, you’d better change the download address back
  2. npmoryarnOfregistryBack to official

About me

Sunseekerx, front-end development, nodejs development, appletuni-appDevelopment, etc

Like to explore the technical implementation plan and details, perfectionists, can not seebug

Github:https://github.com/SunSeekerX

Personal blog:https://yoouu.cn/

Personal online notes:https://sunseekerx.yoouu.cn/

Recommended Today

Rest command line tool demo

https://www.bilibili.com/vide… In this tutorial, we’ll show you how to use therestyCommand line tools. cd ~ export PATH=/usr/local/openresty/bin:$PATH which resty It’s usually this path. We can go through it-VOption to check its version number. resty -V If you use usPre built Linux binary packageInstall openresty, then you should install itopenresty-restyBag. dnf list installed openresty-resty Because it’s […]