一、構建項目依賴鏡像
1、安裝yarn
npm install -g yarn
2、先我們需要設置?個?錄作為我們的“離線鏡像”存儲,我們可以通過yarn config 命令來實現(xiàn)。
默認在C盤中 C:\Users\Admin\npm-packages-offline-cache下,之后會在當前項?路徑?成?個npm-packages-offline-cache 文件夾用來存放構建的.tgz離線?件
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
3、移動配置文件到項目路徑,以便離線鏡像僅用于此項目。
mv ~/.yarnrc ./
4、刪除之前的node_modules和yarn.lock并重新構建
rm -rf node_modules/ yarn.lock
yarn install
二、上傳鏡像制Nexus依賴庫
1、連接服務器,創(chuàng)建上傳目錄。
cd /home
makir npm
cd /npm
2、上傳node_modules依賴包,并解壓到當前目錄下。
unzip node_modules.zip
cd node_modules
3、授權并登錄Nexus。
chmod a+x uploadUpmOffline.sh
npm login -u admin -p admin --registry=http://192.168.100.100:8080/repository/npm-test/
4、執(zhí)行上傳腳本,上傳node_modules鏡像
#!/bin/bash
for file in $(ls /home/npm/node_modules)
do
if [ "${file##*.}" = "tgz" ]; then
npm publish /home/npm/node_modules/$file --registry=http://192.168.100.100:8080/repository/npm-test/
fi
done
./uploadUpmOffline.sh
文章來源地址http://www.zghlxwxcb.cn/news/detail-828542.html
文章來源:http://www.zghlxwxcb.cn/news/detail-828542.html
到了這里,關于上傳前端node_modules依賴包鏡像至Nexus的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!