Vue Build & Tooling
Estimated reading: 3 minutes 278 views

Vue Build & Deployment – From Dev Server to Production (2025 Guide)


Introduction – Why Learn Vue Build & Deployment?

When developing with Vue.js, running npm run serve works great for local development. But before going live, your application must be compiled, optimized, and deployed. Vue CLI handles the build process efficiently, and you can deploy the output to platforms like GitHub Pages, Netlify, Firebase Hosting, Vercel, or a traditional web server.

In this guide, you’ll learn:

  • How to build your Vue app for production
  • What the build command does behind the scenes
  • Directory structure of the final build
  • How to deploy to popular platforms

1. Building the Vue App for Production

After development:

npm run build

Output:

This generates a /dist folder with minified and production-ready files:

dist/
├── css/
├── js/
├── index.html
├── favicon.ico

vue.config.js can customize this output if needed (e.g., outputDir).


2. What Happens During Build?

Process StageDescription
Code MinificationRemoves whitespace, comments, unused code
CSS ExtractionMoves inline styles to separate files
Chunk SplittingBreaks app into smaller, loadable pieces
Environment InjectionInjects NODE_ENV=production vars

3. vue.config.js Build Configuration

Customize output directory, base URL, source maps, etc.

// vue.config.js
module.exports = {
  publicPath: '/my-app/',
  outputDir: 'dist',
  assetsDir: 'static',
  productionSourceMap: false
};

4. Deployment Methods

A. GitHub Pages (Static Hosting)

npm install --save-dev gh-pages

Add to package.json:

"scripts": {
  "deploy": "gh-pages -d dist"
}

Then run:

npm run build
npm run deploy

Set publicPath: '/your-repo-name/' in vue.config.js.


B. Netlify

  1. Go to netlify.com
  2. Connect your GitHub repo
  3. Set build command: npm run build
  4. Set publish directory: dist/

C. Firebase Hosting

npm install -g firebase-tools
firebase login
firebase init

Set dist as public directory during setup.

firebase deploy

D. Vercel

  1. Install Vercel CLI
  2. Run vercel in root directory
  3. Choose dist as the output directory

E. Custom Hosting (FTP or cPanel)

  1. Run npm run build
  2. Upload files from /dist/ to your server’s public_html or root directory

5. Automating with CI/CD

Integrate Vue build into GitHub Actions, GitLab CI, or Jenkins for automatic deployment:

GitHub Actions Example:

name: Build & Deploy

on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - run: npm install
    - run: npm run build
    - run: npm run deploy

6. Environment Variables

Place environment-specific settings in .env files:

  • .env.production
  • .env.development
VUE_APP_API_URL=https://api.myapp.com

Prefix with VUE_APP_ to expose in Vue.


Summary – Recap & Next Steps

Vue’s build process optimizes your app for performance and security. Whether deploying to Netlify or GitHub Pages, understanding the build output and hosting options ensures a smooth go-live experience.

Key Takeaways:

  • Run npm run build to generate the dist/ folder
  • Use vue.config.js for custom paths or build tweaks
  • Deploy to Netlify, Firebase, GitHub Pages, or your own server
  • Manage environments with .env files

Real-World Relevance:
This workflow is essential for publishing SPAs, PWAs, admin dashboards, landing pages, and production-ready frontend systems.


FAQ Section

What does npm run build do in Vue?

It creates a minified, optimized production version of your app in the /dist folder.


Where should I deploy my Vue app?

Use Netlify, Firebase Hosting, GitHub Pages, Vercel, or traditional web hosting.


Can I change the output folder of the Vue build?

Yes. Set outputDir in vue.config.js.


How do I set a custom base path for deployment?

Set publicPath: '/custom-path/' in vue.config.js.


How do I use environment variables in Vue?

Define them in .env.production using the VUE_APP_ prefix.


Share Now :
Share

Vue Build & Deployment

Or Copy Link

CONTENTS
Scroll to Top