Vue.js course · Module 12: Testing & Deploy

Deployment

7 min read ·
In this lesson7

Deploying the application to a server - rocket launch! Your code flies to production like a rocket to Mars!

The dist folder from the previous lesson sits on your disk. It has to be carried into orbit: onto a server that serves the files to every technician at a permanent address and over HTTPS - and without manual copying for every fix. The answer is CI/CD, meaning Continuous Integration and Continuous Deployment - the automation of tests, builds and deployments that runs the whole launch procedure by itself after every code push.

Deployment on Vercel

The simplest way is to connect a Git repository in the Vercel dashboard. Vercel detects the Vite project on its own and sets the npm run build command and the dist directory, then deploys production after every push to the main branch and prepares a preview address for every pull request. If you prefer the terminal, use the Vercel CLI:

# Install Vercel CLI
npm install -g vercel

# Deploy
vercel

# Production deployment
vercel --prod

A plain vercel is short for vercel deploy, because deploy is the CLI's default command. Without a flag it creates a preview deployment at a unique address, and --prod publishes it on the production domain; only the very first deployment of a new project always goes to production. You can keep the settings in the repository, in a vercel.json file:

// vercel.json
{
  "buildCommand": "npm run build",
  "outputDirectory": "dist",
  "framework": "vite",
  "rewrites": [
    { "source": "/(.*)", "destination": "/index.html" }
  ]
}

The buildCommand, outputDirectory and framework fields repeat what Vercel detects by itself, but they do not depend on clicks in the dashboard. The most important part is the rewrites section.

Why an SPA needs address rewriting

An application with Vue Router is an SPA: the server has only index.html, and routes such as /gallery are handled by JavaScript in the browser. When a technician refreshes the page on /gallery, the browser asks the server for a non-existent /gallery file and gets a 404. The rewrite rule tells the server to return index.html for every path, and the router displays the right view.

Deployment on Netlify

Netlify works similarly: you connect the repository or use the CLI. The netlify deploy command publishes a draft version at a preview address, and with the --prod flag the production version:

# Install Netlify CLI
npm install -g netlify-cli

# Deploy
netlify deploy

# Production
netlify deploy --prod

The configuration goes into netlify.toml. The [build] section gives the build command and the directory to publish, and [[redirects]] does for the SPA what rewrites does on Vercel:

# netlify.toml
[build]
  command = "npm run build"
  publish = "dist"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

Status 200 means a rewrite, so the address stays unchanged. With a 301 code the browser would jump to the home page and the technician would lose the route.

Deployment on GitHub Pages

GitHub Pages hosts a site straight from the repository. The gh-pages package pushes the contents of dist to a separate branch:

npm install -D gh-pages

A project site lives at an address containing the repository name, for example https://user.github.io/repository-name/. That is why you set base in vite.config.js, the path from which Vite builds references to files:

// vite.config.js
export default defineConfig({
  base: '/repository-name/', // Repository name
  plugins: [vue()]
})

Without base the browser would look for scripts in the domain root and show a blank page; for a user site keep base: '/'. What remains is the deployment script:

// package.json
{
  "scripts": {
    "deploy": "npm run build && gh-pages -d dist"
  }
}

npm run deploy builds the application and publishes dist. GitHub Pages does not support rewrite rules, so refreshing a deep SPA route returns a 404. The Vite documentation also describes deploying through GitHub Actions instead of the gh-pages package.

Docker Deployment

Your own server requires a Docker image. The Dockerfile uses a multi-stage build: the first stage, on a Node image, builds the application, and the second, on a lightweight nginx, only serves it:

# Dockerfile
FROM node:24-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

FROM nginx:alpine

COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

COPY --from=builder carries only dist over from the first stage, so the source code, node_modules and Node itself stay out of the final image. The base image is Node 24, the current LTS version - Vite 8 requires at least Node 20.19 or 22.12, so the old node:18 would break the build. nginx still needs a rule for the SPA:

# nginx.conf
server {
  listen 80;
  server_name localhost;

  root /usr/share/nginx/html;
  index index.html;

  location / {
    try_files $uri $uri/ /index.html;
  }

  # Cache static assets
  location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
  }
}

try_files $uri $uri/ /index.html checks the file, then the directory, and as a last resort returns index.html. A one-year cache for assets is safe, because a code change changes the hash in the file name. All that is left is to build the image and run the container:

# Build and run
docker build -t gallery-app .
docker run -p 8080:80 gallery-app

-t gallery-app gives the image a name, and the dot points to the current directory as the build context. -p 8080:80 connects port 8080 of your computer with port 80 of the container, so the application runs at http://localhost:8080.

CI/CD with GitHub Actions

A GitHub Actions workflow is a YAML file in the .github/workflows directory, run on the events listed in the on section. This one goes through the launch procedure after every push to main:

# .github/workflows/deploy.yml
name: Deploy

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7

      - name: Setup Node
        uses: actions/setup-node@v7
        with:
          node-version: 24

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test

      - name: Build
        run: npm run build

      - name: Deploy to Vercel
        uses: amondnet/vercel-action@v42
        with:
          vercel-token: ${{ secrets.VERCEL_TOKEN }}
          vercel-org-id: ${{ secrets.ORG_ID }}
          vercel-project-id: ${{ secrets.PROJECT_ID }}
          vercel-args: '--prod'

The steps run in order: actions/checkout fetches the code, actions/setup-node installs Node, npm ci installs dependencies exactly as recorded in package-lock.json, then come the tests, the build and the deployment. When any step fails, the following ones do not run. In a full pipeline linting (npm run lint) also comes before the tests - you will see it in the project. secrets are secret keys from the repository settings, and amondnet/vercel-action is a community action - a project connected to Vercel through Git does not need this step.

Performance Checklist

  • Lazy load routes - views loaded only when their route is visited
  • Code splitting - libraries in separate bundles kept in the cache
  • Image optimization - images usually weigh more than the code
  • Minification - Vite does it by default
  • Gzip/Brotli compression - server-side compression
  • CDN for static assets - files closer to the user
  • Cache headers - long for hashed files, short for index.html
  • Preload critical resources - Vite adds modulepreload by itself
  • Remove console.logs - the minifier strips them once you enable the right option
  • Source maps for dev only - publish them only deliberately, e.g. sourcemap: 'hidden' for error reporting

My advice: to start with, choose Vercel or Netlify with Git integration - you get HTTPS, a CDN and pull request previews without any configuration. Save Docker for when the application has to stand on the station's own infrastructure. In the final project you tie tests, build and deployment into one pipeline.

Remember: CI/CD is an automatic pre-launch procedure that will not let you take off with a damaged system.

Code for this lesson: App.vue
<script setup>
import { ref, computed } from 'vue'

// NOVA LAB - CI/CD Pipeline Visualization
const pipelineStages = ref([
  { id: 1, name: 'Source', status: 'completed', duration: 2, icon: '' },
  { id: 2, name: 'Build', status: 'idle', duration: 45, icon: '' },
  { id: 3, name: 'Test', status: 'idle', duration: 30, icon: '' },
  { id: 4, name: 'Security Scan', status: 'idle', duration: 20, icon: '' },
  { id: 5, name: 'Deploy Staging', status: 'idle', duration: 25, icon: '' },
  { id: 6, name: 'Deploy Production', status: 'idle', duration: 30, icon: '' }
])

const pipelineRunning = ref(false)
const currentStage = ref(0)
const pipelineProgress = ref(0)

const logs = ref([
  '→ Pipeline ready to start...'
])

let stageInterval = null

const overallProgress = computed(() => {
  const completed = pipelineStages.value.filter(s => s.status === 'completed').length
  return Math.round((completed / pipelineStages.value.length) * 100)
})

const pipelineStatus = computed(() => {
  if (pipelineStages.value.some(s => s.status === 'failed')) return 'failed'
  if (pipelineStages.value.every(s => s.status === 'completed')) return 'success'
  if (pipelineRunning.value) return 'running'
  return 'idle'
})

function startPipeline() {
  pipelineRunning.value = true
  currentStage.value = 0
  pipelineProgress.value = 0
  logs.value = ['Starting CI/CD Pipeline...']

  // Reset all stages except first
  pipelineStages.value.forEach((stage, index) => {
    stage.status = index === 0 ? 'completed' : 'idle'
  })

  runNextStage()
}

function runNextStage() {
  if (currentStage.value >= pipelineStages.value.length - 1) {
    completePipeline()
    return
  }

  currentStage.value++
  const stage = pipelineStages.value[currentStage.value]
  stage.status = 'running'

  logs.value.push(`⏳ Running: ${stage.name}...`)

  pipelineProgress.value = 0
  const increment = 100 / (stage.duration / 10)

  stageInterval = setInterval(() => {
    pipelineProgress.value += increment

    if (pipelineProgress.value >= 100) {
      clearInterval(stageInterval)
      stage.status = 'completed'
      logs.value.push(`${stage.name} completed successfully`)

      setTimeout(() => {
        runNextStage()
      }, 500)
    }
  }, 100)
}

function completePipeline() {
  pipelineRunning.value = false
  logs.value.push('Pipeline completed successfully!')
  logs.value.push('Mars Mission deployed to production!')
}

function resetPipeline() {
  if (stageInterval) clearInterval(stageInterval)
  pipelineRunning.value = false
  currentStage.value = 0
  pipelineProgress.value = 0

  pipelineStages.value.forEach((stage, index) => {
    stage.status = index === 0 ? 'completed' : 'idle'
  })

  logs.value = ['→ Pipeline reset. Ready to start...']
}
</script>

<template>
  <div class="cicd-dashboard">
    <div class="header">
      <h1>CI/CD Pipeline Monitor</h1>
      <p>NOVA LAB Automated Deployment System</p>
    </div>

    <div class="pipeline-status" :class="pipelineStatus">
      <div class="status-indicator">
        <template v-if="pipelineStatus === 'idle'">Idle</template>
        <template v-else-if="pipelineStatus === 'running'">Running</template>
        <template v-else-if="pipelineStatus === 'success'">Success</template>
        <template v-else-if="pipelineStatus === 'failed'">Failed</template>
      </div>
      <div class="overall-progress">
        Progress: {{ overallProgress }}%
      </div>
    </div>

    <div class="pipeline-visualization">
      <div
        v-for="stage in pipelineStages"
        :key="stage.id"
        class="pipeline-stage"
        :class="stage.status"
      >
        <div class="stage-icon">{{ stage.icon }}</div>
        <div class="stage-name">{{ stage.name }}</div>
        <div class="stage-status">
          <template v-if="stage.status === 'idle'"></template>
          <template v-else-if="stage.status === 'running'"></template>
          <template v-else-if="stage.status === 'completed'"></template>
          <template v-else-if="stage.status === 'failed'"></template>
        </div>
        <div v-if="stage.status === 'running'" class="stage-progress">
          <div class="progress-bar">
            <div class="progress-fill" :style="{ width: pipelineProgress + '%' }"></div>
          </div>
        </div>
      </div>
    </div>

    <div class="logs-panel">
      <h3>Pipeline Logs</h3>
      <div class="logs">
        <div v-for="(log, index) in logs" :key="index" class="log-entry">
          {{ log }}
        </div>
      </div>
    </div>

    <div class="controls">
      <button
        @click="startPipeline"
        :disabled="pipelineRunning"
        class="start-btn"
      >
        ▶Start Pipeline
      </button>
      <button
        @click="resetPipeline"
        class="reset-btn"
      >
        Reset
      </button>
    </div>
  </div>
</template>

<style scoped>
.cicd-dashboard {
  background: linear-gradient(135deg, #0a0e27 0%, #1a1e3f 100%);
  color: #00ff88;
  padding: 2rem;
  min-height: 100vh;
  font-family: 'Courier New', monospace;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
  border-bottom: 2px solid #00b4d8;
  padding-bottom: 1rem;
}

.header h1 {
  color: #00ff88;
  text-shadow: 0 0 10px #00ff88;
  margin: 0;
}

.pipeline-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 2rem;
  border: 2px solid;
}

.pipeline-status.idle {
  background: rgba(128, 128, 128, 0.1);
  border-color: #888;
}

.pipeline-status.running {
  background: rgba(0, 180, 216, 0.2);
  border-color: #00b4d8;
  animation: pulse 2s infinite;
}

.pipeline-status.success {
  background: rgba(0, 255, 136, 0.2);
  border-color: #00ff88;
}

.pipeline-status.failed {
  background: rgba(255, 0, 0, 0.2);
  border-color: #ff0000;
}

.status-indicator {
  font-size: 1.3rem;
  font-weight: bold;
}

.pipeline-visualization {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}

.pipeline-stage {
  background: rgba(0, 180, 216, 0.1);
  border: 2px solid #00b4d8;
  border-radius: 8px;
  padding: 1rem;
  display: grid;
  grid-template-columns: 50px 1fr 50px;
  align-items: center;
  gap: 1rem;
  transition: all 0.3s;
}

.pipeline-stage.running {
  border-color: #00b4d8;
  background: rgba(0, 180, 216, 0.2);
  box-shadow: 0 0 20px rgba(0, 180, 216, 0.3);
}

.pipeline-stage.completed {
  border-color: #00ff88;
  background: rgba(0, 255, 136, 0.1);
}

.stage-icon {
  font-size: 2rem;
  text-align: center;
}

.stage-name {
  color: #fff;
  font-size: 1.1rem;
}

.stage-status {
  font-size: 1.5rem;
  text-align: center;
}

.stage-progress {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
}

.progress-bar {
  height: 8px;
  background: rgba(0, 255, 136, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #00b4d8, #00ff88);
  transition: width 0.3s;
}

.logs-panel {
  background: rgba(0, 180, 216, 0.1);
  border: 1px solid #00b4d8;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.logs-panel h3 {
  color: #00b4d8;
  margin-top: 0;
}

.logs {
  background: #000;
  border-radius: 4px;
  padding: 1rem;
  max-height: 200px;
  overflow-y: auto;
  font-family: monospace;
}

.log-entry {
  color: #00ff88;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.start-btn, .reset-btn {
  padding: 1rem 2rem;
  font-size: 1rem;
  font-family: 'Courier New', monospace;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid;
  transition: all 0.3s;
}

.start-btn {
  background: #00ff88;
  color: #0a0e27;
  border-color: #00ff88;
}

.start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.start-btn:hover:not(:disabled) {
  box-shadow: 0 0 20px #00ff88;
}

.reset-btn {
  background: rgba(0, 180, 216, 0.2);
  color: #00b4d8;
  border-color: #00b4d8;
}

.reset-btn:hover {
  background: #00b4d8;
  color: #0a0e27;
}
</style>

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. How do you deploy a Vue application to the Vercel platform?

  2. 2. What build settings are needed for deployment on Netlify?

These are 2 of 4 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Code editor

    Complete the vercel.json file with buildCommand, outputDirectory, framework, and rewrites for SPA configuration.

  • Vertical ordering

    Arrange the CI/CD pipeline stages from first to last:

  • Vertical ordering

    Arrange the CI/CD pipeline stages from code to production:

  • Click in order

    Arrange the Docker image build command:

  • Horizontal ordering

    Arrange the Vite configuration for GitHub Pages:

  • Code editor

    Complete a Dockerfile with a multi-stage build: the build stage (node) and the production stage (nginx).

  1. QuestionDeployment on Vercel
  2. QuestionNetlify - build configuration
  3. Coding taskPractice: Vercel configuration
  4. Put in orderCI/CD process
  5. Put in orderCI/CD pipeline for Vue
  6. Click in orderDocker build - commands
  7. QuestionSPA routing on a server
  8. Put in orderGitHub Pages - base path
  9. Coding taskPractice: Dockerfile
  10. QuestionCI/CD - GitHub Actions

Useful articles