建湖做網(wǎng)站哪家公司好/seo排名優(yōu)化推廣報(bào)價(jià)
在平時(shí)開發(fā)當(dāng)中,我們經(jīng)常會(huì)使用 Npm,yarn 來構(gòu)建 web 項(xiàng)目。但是npm默認(rèn)的源的服務(wù)器是在國(guó)外的,如果沒有梯子的話。會(huì)感覺特別特別慢,所以,使用國(guó)內(nèi)的源是非常有必要的。
在這里插入圖片描述
Nnpm, yarn 常用命令
常用命令:
功能/工具名稱 | yarn | npm |
---|---|---|
安裝全部依賴 | yarn / yarn install | npm install |
添加一個(gè)/多個(gè)依賴 | yarn add xx | npm install xx |
刪除一個(gè)/多個(gè)依賴 | yarn remove | npm uninstall |
搜索 package 包 | / | npm search |
yarn:
Yarn 是由 Facebook、Google、Exponent 和 Tilde 聯(lián)合推出了一個(gè)新的 JS 包管理工具 。
安裝:
npm install -g yarn
執(zhí)行?yarn xxx
?命令報(bào)以下錯(cuò)誤時(shí):
在這里插入圖片描述
操作以下步驟進(jìn)行策略更改:
- 使用管理員身份運(yùn)行 cmd 或 Power shell
- 輸入:set-executionpolicy remotesigned
- 輸入”Y“,回車保存
npm,yarn 使用國(guó)內(nèi)源
原淘寶 npm 域名即將停止解析!!使用老域名的請(qǐng)盡快更新到新域名!
《淘寶 NPM 鏡像站喊你切換新域名啦》
https://npm.taobao.org?和? https://registry.npm.taobao.org?將在 2022.06.30
號(hào)正式下線和停止 DNS 解析。
域名切換規(guī)則:
https://npm.taobao.org?=>?https://npmmirror.com
https://registry.npm.taobao.org?=>?https://registry.npmmirror.com
yarn 配置源:
有兩種方式,一種是臨時(shí)配置的,一種是永久配置的
臨時(shí)使用
如果只是一次性使用,可以使用下面的命令
npm --registry?https://registry.npm.taobao.org?install XXX(模塊名)
全局配置
這種設(shè)置是全局的,以后每次都會(huì)自動(dòng)讀取已經(jīng)設(shè)置好的源
// 查詢?cè)磞arn config get registry// 更換國(guó)內(nèi)源yarn config set registry https://registry.npmmirror.com// 恢復(fù)官方源yarn config set registry https://registry.yarnpkg.com// 刪除注冊(cè)表yarn config delete registry
npm 配置源:
注意 npm 更換國(guó)內(nèi)鏡像源之后,將無法再使用?npm search
命令,需要恢復(fù)為官方源才可以使用,如果恢復(fù)官方源后還不可使用,運(yùn)行刪除注冊(cè)表命令后重試即可。
// 查詢?cè)磏pm config get registry// 更換國(guó)內(nèi)源npm config set registry https://registry.npmmirror.com// 恢復(fù)官方源npm config set registry https://registry.npmjs.org// 刪除注冊(cè)表npm config delete registry