Vue.js 使用travis在gh页面上一页接一页地隐藏
我一直在研究如何在Vue.js 使用travis在gh页面上一页接一页地隐藏,vue.js,travis-ci,github-pages,vue-cli-3,Vue.js,Travis Ci,Github Pages,Vue Cli 3,我一直在研究如何在vue CLI 3中创建gh页面 我有一个项目: 我遵循了以下指示: 因此,我添加了.travis.yml: language: node_js node_js: - "node" cache: npm script: npm run build deploy: provider: pages skip_cleanup: true github_token: $GITHUB_TOKEN_Movies local_dir: dist on: b
vue CLI 3
中创建gh页面
我有一个项目:
我遵循了以下指示:
因此,我添加了.travis.yml
:
language: node_js
node_js:
- "node"
cache: npm
script: npm run build
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN_Movies
local_dir: dist
on:
branch: master
我还添加了deploy.sh
文件:
#!/usr/bin/env sh
# abort on errors
set -e
# build
npm run build
# navigate into the build output directory
cd dist
# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME
git init
git add -A
git commit -m 'deploy'
# if you are deploying to https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f https://github.com/aniaska4/Playlist.git master:gh-pages
cd -
接下来,我通过travisci
进行了一次部署,成功了。但是当我的gh页面
创建时,我的控制台中有一个空白页面和错误
在网络中,它如下所示:
有错误的请求URL,我是对的吗?应该是:我真的不知道如何修复。有什么想法吗?正如您所发现的,部署本身没有问题,您的资产是您的GitHub页面。vue cli
应用程序无法正确解析资产的原因是,脚本文件上无法识别未以vue\u APP\u前缀的环境变量
考虑到上述情况,process.env.NODE\u env
始终是一个假值,它会导致每个环境上的publicPath
都是/
。您应该为不同的环境使用env文件来定义变量
首先,在项目的根目录上创建一个.env.local
文件,内容如下。这些变量将为您的本地开发加载。(npm运行服务
)
然后在根项目目录中再次创建.env.production
文件。这些将在您进行生产构建时注入。(npm run dist
,因此vue cli服务构建--生产模式
)
最后,在vue.config.js
文件中更改publicPath
键,以获取vue环境变量:
publicPath:process.env.VUE\u APP\u PUBLIC\u路径
再次部署您的项目,您将看到您的publicPath随生产路径而更改,您的资产将按预期加载。无帮助?:(也许有人知道解决方法。请帮忙这太神奇了!它很有效!我花了这么多天来解决我的问题,但我不知道如何解决。非常感谢你。你让我度过了美好的一天:)
publicPath: process.env.NODE_ENV === 'production'
? '/Playlist/'
: '/',
VUE_APP_PUBLIC_PATH="/"
VUE_APP_PUBLIC_PATH="/Playlist/"