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 tonpm
This replacementregistry
The way you use itnpm publish
You need to switch back when you contractnpm
The official image address.
Now I’m using replacementregistry
That’s the solution. But likenode-sass
This kind of binary file download still uses the foreign address. So I have the following pileregistry
It 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(
npm
、npx
、yarn
、pnpm
、pnpx
)Use Taobao source to install dependency; - Through the environment variable
nvm
、node-sass
、Electron
、Puppeteer
、Cypress
、Sharp
And 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,tbify
Provides the equivalent command to use the Taobao NPM image, except when publishing packages to NPMnpm publish
You 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, addtbify
Prefix, for example:
tbify printenv npm_config_registry
# -> https://r.npm.taobao.org
3. Precautions
- If you have a replacement binary file before, you’d better change the download address back
-
npm
oryarn
Ofregistry
Back to official
About me
Sunseekerx, front-end development, nodejs development, appletuni-app
Development, 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/