From 70126748fd271ed24e8f267b5fb27731a5d4dc04 Mon Sep 17 00:00:00 2001 From: NBTX Date: Sat, 24 Aug 2019 17:20:19 +0100 Subject: [PATCH] Set up travis for GitHub Pages deployment --- .travis.yml | 47 +++++++++++++++++++++++++++++++++++++++++++---- nuxt.config.js | 20 +++++++++++++++++++- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a533aa377..0f3db1b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,47 @@ +# == INSTRUCTIONS FOR SETTING UP TRAVIS (and GitHub Pages) == +# +# 1. Find this repository in your Travis-CI dashboard. +# open settings and add an environment variable called +# GITHUB_ACCESS_TOKEN and set it to your personal access token.addons: +# See: https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line +# +# **DO NOT TURN ON 'Display value in build log'!!!!** +# +# 2. Push the code to the repository. +# 3. Profit! + + + language: node_js node_js: - - "node" + - "12" + +env: + - MY_VAR=EverythignIsAwesome + - NODE_ENV=TEST + - DEPLOY_ENV=GH_PAGES + +cache: + directories: + - "node_modules" + +branches: + only: + - "master" + +install: + - "npm install" + - "npm run generate" + notifications: webhooks: https://www.travisbuddy.com -env: -- MY_VAR=EverythignIsAwesome -- NODE_ENV=TEST \ No newline at end of file + +deploy: + provider: pages + skip_cleanup: true + # Refer to: https://docs.travis-ci.com/user/deployment/pages/#Setting-the-GitHub-token + github_token: $GITHUB_ACCESS_TOKEN + target-branch: gh-pages + local_dir: dist + on: + branch: master \ No newline at end of file diff --git a/nuxt.config.js b/nuxt.config.js index 3bb5ff8bb..394f7527d 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,3 +1,4 @@ + // Some helpful application constants. // TODO: Use these when rendering the pages (rather than just for head/meta tags...) const meta = { @@ -6,6 +7,18 @@ const meta = { description: "The Postwoman API request builder helps you create your requests faster, saving you precious time on your development." }; +// Sets the base path for the router. +// Important for deploying to GitHub pages. + +// -- Travis includes the author in the repo slug, +// so if there's a /, we need to get everything after it. +let repoName = process.env.TRAVIS_REPO_SLUG.split('/').pop() || ''; +const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? { + router: { + base: `/${repoName}/` + } +} : {}; + export default { mode: 'spa', /* @@ -134,5 +147,10 @@ export default { */ generate: { fallback: true - } + }, + + /* + ** Router configuration + */ + ...routerBase }