首先贴文档
cli.vuejs.org/zh/guide/de…
如果不看文档就上传dist文件,基本上就是获得一个404或者空白页面
将vue发布到gitee上,第一步是修改路径
-
在
vue.config.js
中设置正确的publicPath
。如果打算将项目部署到
https://<USERNAME>.github.io/
上,publicPath
将默认被设为"/"
,你可以忽略这个参数。如果打算将项目部署到
https://<USERNAME>.github.io/<REPO>/
上 (即仓库地址为https://github.com/<USERNAME>/<REPO>
),可将publicPath
设为"/<REPO>/"
。举个例子,如果仓库名字为“my-project”,那么vue.config.js
的内容应如下所示:module.exports = { publicPath: process.env.NODE_ENV === 'production' ? '/my-project/' : '/' } 复制代码
2.添加shell脚本和新的dist仓库,实现自动化
在项目目录下,创建内容如下的 deploy.sh
(可以适当地取消注释) 并运行它以进行部署
#!/usr/bin/env sh
# 当发生错误时中止脚本
set -e
# 构建
yarn build
# cd 到构建输出的目录下
cd dist
# 部署到自定义域域名
# echo 'www.example.com' > CNAME
git init
git add .
git commit -m 'deploy'
# 部署到 https://<USERNAME>.github.io
# git push -f gitee@gitee.com:<USERNAME>/<USERNAME>.github.io.git master
# 部署到 https://<USERNAME>.github.io/<REPO>
git push -f git@gitee.com:xmy16211127/test1.git master:gh-pages
cd -
复制代码
在终端使用sh deploy.sh即可运行
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END