这里记录下项目侧如何离线安装,本文和公司业务耦合性高,不过懂得人可以借鉴
# start.sh
work_dir=$(cd `dirname $0`; pwd) //dirname $0,取得当前执行的脚本文件的父目录;
node_v=$(node -v)
cd $work_dir
if [ ! -e ./phoenix/build ]; then
echo "请先打包好phoenix"
elif [ ! -e ./porpoise/dist ]; then
echo "请先打包好porpoise内容"
else
npm run offline-install
npm run build
./node_modules/.bin/pm2 delete whale
./node_modules/.bin/pm2 start app.js --name "whale"
fi
不直接用pwd,是因为执行脚本的时候不一定在项目路径下
在项目下新建yarn,目录结构如下
yarn-v1.17.3.tar.gz 安装包可以在官网下载 (https://github.com/yarnpkg/yarn/releases/tag/v1.17.3)
# online-install.sh
#!/bin/bash SH_FILE_PATH=$(cd `dirname $0`; pwd) # $REPO_PATH/yarn cd $SH_FILE_PATH/../ rm -rf node_modules/* yarn.lock yarn-error.log npm install $SH_FILE_PATH/yarn-v1.17.3.tar.gz --no-save npx yarn config set registry https://registry.npm.taobao.org npx yarn config set yarn-offline-mirror $SH_FILE_PATH/yarn-offline-mirror //设置后执行yarn install会将镜像缓存在yarn-offline-mirror文件夹下 npx yarn config set yarn-offline-mirror-pruning false npx yarn cache clean npx yarn install npx yarn config list
#offline-install.sh #!/bin/bash SH_FILE_PATH=$(cd `dirname $0`; pwd) # $REPO_PATH/yarn cd $SH_FILE_PATH/../ rm -rf node_modules/ npm install $SH_FILE_PATH/yarn-v1.17.3.tar.gz --no-save npx yarn config set yarn-offline-mirror $SH_FILE_PATH/yarn-offline-mirror npx yarn cache clean npx yarn install --offline
这个是官网的离线文档https://yarnpkg.com/blog/2016/11/24/offline-mirror/
ps:
对于个人仓库的npm包,由于yarn生成的镜像的文件命名为name-版本号;如
#package.json { "dependencies": { "setprototypeof": "^1.2.0", "star-graph": "git+http://git.sz.haizhi.com/xieyuzhong/star-graph.git"
} }
生成的tgz包为setprototypeof-1.2.0.tgz;所以star-graph的镜像包不能准确生成导致离线安装失败;对于可以单独备份然后copy到node_modules