1、修改打包路径

在 vue.config.js 中添加  publicPath  配置,其中 teambition-vue 是你项目的 github 名字。否则会找不到资源。

module.exports = {
    ...
    // 部署到github
    publicPath: process.env.NODE_ENV === 'production' ? '/teambition-vue' : '/'
};

 

2、history 模式

GitHub 不支持单页面,使用 history 路由,会出现 404 ,所以把 index.html 的内容 copy 到 404.html 就可以巧妙的解决这个问题。

 

3、部署

进入 dist 目录,把内容推到远程即可

#! /bin/bash
npm run build
cd ./dist
cp index.html 404.html
git init
git remote add origin https://github.com/G-lory/teambition-vue.git
git add .
git commit -m 'deploy'
git checkout -b gh-pages
git push -u origin gh-pages -f

 

4、访问 https://g-lory.github.io/teambition-vue/ 即可。

即 https://<用户名>.github.io/<项目名>/

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-10-09
  • 2021-10-14
  • 2022-12-23
  • 2021-08-15
  • 2022-01-09
猜你喜欢
  • 2021-04-13
  • 2021-12-25
  • 2022-12-23
  • 2021-09-19
  • 2021-12-01
  • 2022-12-23
  • 2021-12-07
相关资源
相似解决方案