Skip to content

Deploying a Vue App

Vue is a progressive JavaScript framework for building user interfaces and single-page applications. It is known for its simplicity, flexibility, and reactive data binding, making it a popular choice for modern web development.

This guide explains how to deploy a Vue application to Klutch.sh, both with and without a Dockerfile. It covers installation, sample code, and deployment steps.

Prerequisites

  • Node.js & npm installed (Download)
  • Git and GitHub account
  • Klutch.sh account

Getting Started: Create a Vue App

  1. Create a new Vue app using Vite (recommended):
    Terminal window
    npm create vite@latest my-vue-app -- --template vue
    cd my-vue-app
    npm install
  2. Start the development server:
    Terminal window
    npm run dev
    Your app should be running at http://localhost:5173.

Sample Code (src/App.vue)

Replace the contents of src/App.vue with:

<template>
<div>
<h1>Hello from Vue on Klutch.sh!</h1>
</div>
</template>
<script setup>
// No script needed for this example
</script>
<style>
h1 { color: #42b983; }
</style>

Deploying Without a Dockerfile

Vue apps built with Vite are static sites after build. Klutch.sh can deploy static sites directly.

  1. Push your Vue app to a GitHub repository.
  2. Log in to Klutch.sh.
  3. Create a new project.
  4. Create a new app:
    • Select your Vue GitHub repository and branch
    • Choose “Static Site” as the app type
    • Set build command: npm run build
    • Set output directory: dist
    • Configure region, compute, and environment variables as needed
  5. Click “Create” to deploy. Klutch.sh will build and serve your static Vue app.

Deploying With a Dockerfile

If you need custom server logic or want to use a Dockerfile:

  1. Add a Dockerfile to your project root. Example:
    # Build stage
    FROM node:20-alpine AS builder
    WORKDIR /app
    COPY package*.json ./
    RUN npm install
    COPY . .
    RUN npm run build
    # Production stage
    FROM nginx:alpine
    COPY --from=builder /app/dist /usr/share/nginx/html
    EXPOSE 80
    CMD ["nginx", "-g", "daemon off;"]
  2. Push your code (with Dockerfile) to GitHub.
  3. In Klutch.sh, create a new app and select the Dockerfile option when prompted.
  4. Set service details and environment variables as needed.
  5. Click “Create” to deploy. Klutch.sh will build your Docker image and serve your Vue app via Nginx.

Resources


Deploying Vue to Klutch.sh is fast and flexible. Use static site deployment for most cases, or Dockerfile for custom setups.