Deploy Vue on Cloudflare with GitHub Actions

💚 Vue 🟠 Cloudflare Pages & Workers ⚙️ GitHub Actions

Configuration Files

Production-ready configuration files with detailed comments and best practices. Each file works together as a complete deployment solution.
# .github/workflows/deploy.yml
name: Deploy Vue to Cloudflare Pages

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      deployments: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Build Vue app
        run: npm run build
        env:
          NODE_ENV: production

      - name: Deploy to Cloudflare Pages
        uses: cloudflare/pages-action@v1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: my-vue-app
          directory: dist
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}

# vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    outDir: 'dist',
    sourcemap: true,
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ['vue', 'vue-router'],
        },
      },
    },
  },
})

# package.json
{
  "name": "my-vue-app",
  "version": "0.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "run-p type-check build-only",
    "preview": "vite preview",
    "build-only": "vite build",
    "type-check": "vue-tsc --noEmit"
  },
  "dependencies": {
    "vue": "^3.3.11",
    "vue-router": "^4.2.5"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.0.0",
    "@vue/tsconfig": "^0.5.0",
    "npm-run-all2": "^6.1.1",
    "typescript": "~5.3.0",
    "vite": "^5.0.10",
    "vue-tsc": "^1.8.27"
  }
}

# tsconfig.json
{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

# env.d.ts
/// <reference types="vite/client" />

Prerequisites

  • Node.js 18+ installed
  • GitHub account with repository admin access
  • Cloudflare account (free tier works)
  • Git installed locally
  • Basic knowledge of Vue 3 and TypeScript

Deployment Steps

  • Create Vue app: npm create vue@latest my-vue-app
  • Select TypeScript, Vue Router (optional), and other features
  • Navigate to project: cd my-vue-app
  • Install dependencies: npm install
  • Test locally: npm run dev
  • Create GitHub repository and push code
  • In Cloudflare Dashboard → Pages → Create project
  • Get Account ID from Pages dashboard
  • Create API Token with Cloudflare Pages Edit permissions
  • Add CLOUDFLARE_API_TOKEN to GitHub Secrets
  • Add CLOUDFLARE_ACCOUNT_ID to GitHub Secrets
  • Create .github/workflows/deploy.yml
  • Update projectName in workflow
  • Commit and push to main branch
  • Monitor deployment in GitHub Actions
  • Access site at https://my-vue-app.pages.dev

Additional Notes

  • ⚡ Vue 3 Composition API with <script setup>
  • 🌍 Global CDN with 300+ edge locations
  • 🔒 Automatic HTTPS with SSL certificates
  • 🔄 Preview deployments for pull requests
  • 💰 Free tier: 500 builds/month, unlimited bandwidth
  • 📦 Optimized builds with code splitting
  • 🎯 Full TypeScript support
  • 🛣️ Vue Router for SPA navigation
  • ⚠️ For SSR, consider using Nuxt.js instead