Deploy Vue
This guide will help you deploy a Vue application to Deployxa.
Overview
Vue.js is a progressive JavaScript framework for building user interfaces. Deployxa provides optimized deployments for Vue applications with automatic configuration.
Features:
- Automatic framework detection
- Vue 3 and Vue 2 support
- Vite and Vue CLI support
- Static site generation
- Automatic HTTPS
- Global CDN
Prerequisites
- A Vue application (Vue 3 recommended)
- A GitHub repository with your code
- A Deployxa account
Quick Start
1. Create Your Vue App
Using Vite (Recommended):
npm create vue@latest my-vue-app
cd my-vue-app
npm install
Using Vue CLI:
npm install -g @vue/cli
vue create my-vue-app
cd my-vue-app
2. Push to GitHub
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/my-vue-app.git
git push -u origin main
3. Deploy to Deployxa
- Go to Deployxa Dashboard
- Click "New Project"
- Select your GitHub repository
- Deployxa will automatically detect Vue
- Click "Deploy"
Your app will be live in under 30 seconds!
Configuration
Detected Settings
Deployxa automatically detects these settings:
| Setting | Value |
|---|---|
| Framework | Vue |
| Build Command | npm run build |
| Output Directory | dist |
| Start Command | Static site (no server needed) |
| Port | 80 |
Custom Configuration
If you need to customize settings:
- Go to Project → Settings → Build
- Modify settings as needed
- Save changes
Example Custom Settings:
{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"installCommand": "npm ci"
}
Environment Variables
Adding Environment Variables
- Go to Project → Environment
- Click "Add Variable"
- Enter key and value
- Click "Save"
Common Vue Environment Variables:
VITE_API_URL=https://api.example.com
VITE_APP_TITLE=My Vue App
VUE_APP_API_URL=https://api.example.com
VUE_APP_TITLE=My Vue App
Note:
- Vite uses
VITE_prefix - Vue CLI uses
VUE_APP_prefix - Variables are embedded at build time
Using Environment Variables
In Vite:
const apiUrl = import.meta.env.VITE_API_URL;
const appTitle = import.meta.env.VITE_APP_TITLE;
In Vue CLI:
const apiUrl = process.env.VUE_APP_API_URL;
const appTitle = process.env.VUE_APP_TITLE;
Build Process
What Happens During Build
- Install Dependencies:
npm installornpm ci - Run Build:
npm run build - Optimize Assets: Minify JS, CSS, images
- Generate Static Files: Create optimized HTML, JS, CSS
- Deploy to CDN: Distribute to global edge network
Build Output
Vue generates:
dist/- Build output directoryindex.html- Main HTML fileassets/- JavaScript and CSS bundles- Static assets (images, fonts)
Routing
Client-Side Routing
For single-page applications with routing:
Vue Router:
import { createRouter, createWebHistory } from 'vue-router';
import Home from './views/Home.vue';
import About from './views/About.vue';
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About }
]
});
export default router;
Handling 404s
Configure your deployment to handle client-side routing:
Option 1: Redirect to index.html
Deployxa automatically handles this for Vue apps.
Option 2: Custom 404 page
Create a 404.html file in your public directory.
Custom Domains
Adding a Custom Domain
- Go to Project → Domains
- Click "Add Domain"
- Enter your domain (e.g.,
example.com) - Configure DNS records
- Wait for verification
DNS Configuration
For Apex Domain (example.com):
Type: A
Name: @
Value: 76.76.21.21
For Subdomain (www.example.com):
Type: CNAME
Name: www
Value: cname.deployxa.com
SSL Certificate
Deployxa automatically provisions SSL certificates:
- Free Let's Encrypt certificates
- Automatic renewal
- HTTPS enforced
- Wildcard support
Performance Optimization
Code Splitting
Split your code for faster initial loads:
import { defineAsyncComponent } from 'vue';
const AsyncComponent = defineAsyncComponent(() =>
import('./components/AsyncComponent.vue')
);
Lazy Loading Routes
const routes = [
{
path: '/about',
component: () => import('./views/About.vue')
}
];
Image Optimization
Use optimized images:
<template>
<img src="@/assets/image.jpg?w=500&h=500&format=webp" />
</template>
Bundle Analysis
Analyze your bundle size:
npm install --save-dev rollup-plugin-visualizer
Add to vite.config.js:
import { visualizer } from 'rollup-plugin-visualizer';
export default {
plugins: [
visualizer({ open: true })
]
};
Monitoring
Viewing Logs
- Go to Project → Logs
- Select log type:
- Build Logs: Deployment process
- Runtime Logs: Client-side errors (if configured)
Monitoring Metrics
- Go to Project → Analytics
- View metrics:
- Page views
- Unique visitors
- Bandwidth usage
- Response times
Error Tracking
Implement error tracking:
Using Sentry:
npm install @sentry/vue
import * as Sentry from "@sentry/vue";
import { createApp } from 'vue';
const app = createApp(App);
Sentry.init({
app,
dsn: "YOUR_SENTRY_DSN",
});
Troubleshooting
Build Failed: Module Not Found
Problem: Module not found: Can't resolve 'package-name'
Solution:
- Check
package.jsonhas the dependency - Run
npm install package-namelocally - Commit and push changes
- Redeploy
Blank Page After Deployment
Problem: Application shows blank page
Solution:
- Check browser console for errors
- Verify build output directory is correct
- Ensure
index.htmlis in the root of output directory - Check environment variables are set correctly
Routing Not Working
Problem: Direct URL access returns 404
Solution:
- Deployxa automatically handles client-side routing
- If issue persists, check routing configuration
- Ensure you're using
createWebHistory()(notcreateWebHashHistory())
Environment Variables Not Working
Problem: Environment variables are undefined
Solution:
- Use correct prefix (
VITE_orVUE_APP_) - Redeploy after adding variables
- Check variable names match exactly
- Verify variables are set in correct environment
Slow Initial Load
Problem: Application takes too long to load
Solution:
- Enable code splitting
- Use lazy loading for routes
- Optimize images
- Remove unused dependencies
- Enable tree shaking
Best Practices
Project Structure
my-vue-app/
├── public/
│ └── favicon.ico
├── src/
│ ├── components/
│ ├── views/
│ ├── router/
│ ├── stores/
│ ├── App.vue
│ └── main.js
├── .env
├── .env.example
├── vite.config.js
├── package.json
└── README.md
Environment Variables
- Use
.env.localfor local development - Never commit
.envfiles - Use correct prefix for your build tool
- Document required variables in README
Performance
- Enable code splitting
- Use lazy loading for routes
- Optimize images
- Minimize bundle size
- Use Vue's built-in optimizations
Security
- Never expose secrets in client code
- Validate all inputs
- Use HTTPS only
- Keep dependencies updated
- Use Content Security Policy
Advanced Configuration
Vite Configuration
// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [vue()],
build: {
outDir: 'dist',
sourcemap: false,
minify: 'terser',
rollupOptions: {
output: {
manualChunks: {
vendor: ['vue', 'vue-router', 'pinia'],
},
},
},
},
server: {
port: 3000,
},
});
Vue CLI Configuration
// vue.config.js
module.exports = {
publicPath: '/',
outputDir: 'dist',
assetsDir: 'assets',
productionSourceMap: false,
configureWebpack: {
optimization: {
splitChunks: {
chunks: 'all',
},
},
},
};
Custom Build Script
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"analyze": "vite-bundle-visualizer"
}
}
Examples
Basic Vue App
<!-- src/App.vue -->
<template>
<div>
<h1>Vue on Deployxa</h1>
<p>Count: {{ count }}</p>
<button @click="count++">Increment</button>
</div>
</template>
<script setup>
import { ref } from 'vue';
const count = ref(0);
</script>
With API Integration
<!-- src/App.vue -->
<template>
<div>
<h1>Data from API</h1>
<pre>{{ data }}</pre>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const data = ref(null);
onMounted(async () => {
const response = await fetch(import.meta.env.VITE_API_URL + '/data');
data.value = await response.json();
});
</script>
With Routing
<!-- src/App.vue -->
<template>
<div>
<nav>
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
</nav>
<router-view />
</div>
</template>
<script setup>
import { RouterLink, RouterView } from 'vue-router';
</script>
Related Topics
Resources
Need Help? Contact support@deployxa.com or join our community Discord.