Search code examples
webpackvue.jsvuejs2travis-cisurge.sh

Deploying a vue project to surge.sh


I've been trying to deploy my Vue project to Surge.sh all day, the project uses the webpack-simple template.

The funny this is, if I deploy it manually from my CLI, it'll work, but if I push it to GitHub and deploy it from Travis CI, it won't work. If I deploy it from Travis, it won't include the dist/ folder so the site won't work.

Here's my Travis CI configuration :

language: node_js
node_js:
  - "node"
  - "7"
cache:
  directories:
    - node_modules/
    - dist/
install:
  - npm install
after_success:
  - surge --project . --domain mydomain.surge.sh

And I did added two enviroment variables, which is SURGE_TOKEN & SURGE_LOGIN. I really don't know what do right now. So please, help.


Solution

  • The reason your dist folder is missing after the Travis build step is because the environment is cleaned up after each step.

    In order to prevent this, you need to specify a deploy: section in your .travis.yml and set the skip_cleanup: true setting.

    Luckily for you, Travis CI supports Surge.sh deployment directly, so you don’t need to use the surge CLI tool directly in an after_success step. Have a look at the linked instructions above and see how you go.

    Update:

    I think you need to add a script: step to build your site before you deploy it. Otherwise I don't think this command is being called by anything else.

    Something like:

    install:
      - npm install
    script:
      - npm run build
    deploy:
      provider: etc...