部署VUE项目
用两个仓库部署,一个放源码,一个放部署的代码(以下部署方式只会上传dist目录的文件)
- yarn build
打开build生成的链接 - yarn add global serve
- serve -s dist
- vue.config.js文件加入
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/my-project/' //仓库名
: '/'
}
- 创建文件deploy.sh写入
#!/usr/bin/env sh
# 当发生错误时中止脚本
set -e
# 构建
npm run build
# cd 到构建输出的目录下
cd dist
# 部署到自定义域域名
# echo 'www.example.com' > CNAME
git init
git add -A
git commit -m 'deploy'
# 部署到 https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
# 部署到 https://<USERNAME>.github.io/<REPO>
# git push -f git@github.com:<USERNAME>/<REPO>.git master:gh-pages
//以上两种部署方式二选一,并写入正确的仓库地址(一般用第二个)
cd -
- sh deploy.sh (运行脚本)
部署成功,打开仓库看地址即可
网友评论