当前位置:   article > 正文

上传前端node_modules依赖包镜像至Nexus_shell 脚本把node_modules包上传到nexus

shell 脚本把node_modules包上传到nexus

一、构建项目依赖镜像

1、安装yarn
npm install -g yarn
  • 1
2、先我们需要设置⼀个⽬录作为我们的“离线镜像”存储,我们可以通过yarn config 命令来实现。
默认在C盘中 C:\Users\Admin\npm-packages-offline-cache下,之后会在当前项⽬路径⽣成⼀个npm-packages-offline-cache 文件夹用来存放构建的.tgz离线⽂件
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
  • 1
3、移动配置文件到项目路径,以便离线镜像仅用于此项目。
mv ~/.yarnrc ./
  • 1
4、删除之前的node_modules和yarn.lock并重新构建
rm -rf node_modules/ yarn.lock
yarn install
  • 1
  • 2

二、上传镜像制Nexus依赖库

1、连接服务器,创建上传目录。
cd /home
makir npm
cd /npm
  • 1
  • 2
  • 3
2、上传node_modules依赖包,并解压到当前目录下。
unzip node_modules.zip
cd node_modules
  • 1
  • 2
3、授权并登录Nexus。
chmod a+x uploadUpmOffline.sh
npm login -u admin -p admin  --registry=http://192.168.100.100:8080/repository/npm-test/
  • 1
  • 2
4、执行上传脚本,上传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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
./uploadUpmOffline.sh
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/41433
推荐阅读
相关标签
  

闽ICP备14008679号