代码上传到github
打包src
yarn build
出现一个dist目录
npm install -g serve
# 偏爱用 yarn global add serve
# -s 参数的意思是将其架设在 Single-Page Application 模式下
# 这个模式会处理即将提到的路由问题
serve -s dist
出现项目的serve
# 在github上新建一个仓库
把项目关联仓库
在vue.config.js
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/my-project/'
: '/'
}
在github上再创建一个项目-website
在本地项目目录下,创建内容如下的 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
# -website 的ssh替换 git@github.com:<USERNAME>/<REPO>.git
cd -
在终端上
sh deploy.sh
代码更新
sh deploy.sh