📖 Scenario: You have built a simple Vue app and want to share it with friends by putting it on a static hosting service like GitHub Pages or Netlify.This project will guide you through preparing your Vue app for deployment and configuring it for static hosting.
🎯 Goal: Prepare a Vue 3 app for static hosting by setting the correct base URL, building the app, and adding a deployment configuration file.
📋 What You'll Learn
Create a Vue 3 app with a basic App.vue component
Set the base option in vite.config.js for static hosting
Build the app using the Vue CLI or Vite build command
Add a netlify.toml file to configure Netlify deployment
💡 Why This Matters
🌍 Real World
Deploying Vue apps to static hosting services is common for personal projects, portfolios, and small business websites.
💼 Career
Understanding deployment prepares you for real-world frontend roles where you must publish apps for users to access.
Progress0 / 4 steps
1
Create a basic Vue 3 app
Create a file called App.vue with a template that shows <h1>Welcome to My Vue App</h1> and a script section exporting a default empty object.
Vue
Hint
Use the <template> tag for HTML and <script setup> for Vue 3 script.
2
Set the base URL in vite.config.js
In vite.config.js, import defineConfig from 'vite' and export default a config object with base set to '/my-vue-app/'.
Vue
Hint
The base option tells Vite the root path your app will be served from.
3
Build the Vue app for production
Run the build command npm run build or yarn build to create the dist folder with static files ready for deployment.
Vue
Hint
This step is done in the terminal, but type the command exactly as npm run build in the editor to confirm.
4
Add Netlify deployment config
Create a file called netlify.toml with these lines: [build] publish = "dist" command = "npm run build" to tell Netlify how to build and serve your app.
Vue
Hint
This file tells Netlify where your built files are and how to build your app.
Practice
(1/5)
1. What is the main purpose of running npm run build in a Vue project before deployment?
easy
A. To start the development server for testing
B. To create optimized static files ready for hosting
C. To install project dependencies
D. To generate backend API endpoints
Solution
Step 1: Understand the build command role
npm run build compiles Vue files into static assets like HTML, CSS, and JS.
Step 2: Identify deployment needs
Static hosting requires these optimized files to serve the app efficiently.
Final Answer:
To create optimized static files ready for hosting -> Option B
Quick Check:
Build creates static files = A [OK]
Hint: Build command prepares files for static hosting [OK]
Common Mistakes:
Confusing build with starting dev server
Thinking build installs dependencies
Expecting backend code generation
2. Which folder should you upload to your static hosting service after building a Vue app?
easy
A. dist
B. src
C. node_modules
D. public
Solution
Step 1: Identify build output folder
Vue's build process outputs static files into the dist folder.
Step 2: Understand hosting requirements
Static hosts serve files from the dist folder contents, not source or dependencies.
Final Answer:
dist -> Option A
Quick Check:
Upload dist folder = B [OK]
Hint: Upload the dist folder contents for deployment [OK]
Common Mistakes:
Uploading source code instead of built files
Uploading node_modules which is unnecessary
Uploading public folder only
3. After deploying a Vue app's dist folder to GitHub Pages, what will happen if you visit the site URL?
medium
A. You will see the raw source code files
B. You will get a server error because GitHub Pages doesn't support Vue
C. You will see the Vue app running as expected
D. You will be redirected to the Vue CLI homepage
Solution
Step 1: Understand GitHub Pages hosting
GitHub Pages serves static files, perfect for Vue apps built into static assets.
Step 2: Predict site behavior
Visiting the URL loads the static files, so the Vue app runs normally in the browser.
Final Answer:
You will see the Vue app running as expected -> Option C
Quick Check:
Static hosting runs Vue app = A [OK]
Hint: Static hosting runs built Vue app directly [OK]
Common Mistakes:
Thinking GitHub Pages can't host Vue apps
Expecting server errors on static hosts
Confusing source code with built app
4. You deployed your Vue app to Firebase Hosting but the app shows a blank page. What is the most likely cause?
medium
A. You did not configure Firebase to serve the dist folder
B. You uploaded the src folder instead of dist
C. You used the wrong Firebase project ID
D. You forgot to run npm run build before deploying
Solution
Step 1: Check build and upload correctness
Assuming build and upload are correct, the blank page often means Firebase isn't serving the right folder.
Step 2: Verify Firebase hosting config
Firebase needs firebase.json to point to dist as the public directory to serve files.
Final Answer:
You did not configure Firebase to serve the dist folder -> Option A
Quick Check:
Firebase config public folder = D [OK]
Hint: Check Firebase public folder setting matches dist [OK]
Common Mistakes:
Uploading wrong folder but blaming build
Ignoring firebase.json public directory setting
Assuming project ID causes blank page
5. You want to deploy a Vue app with client-side routing to Netlify. Which step is essential to ensure routing works correctly on page reload?
hard
A. Rename dist folder to public
B. Disable JavaScript in the browser
C. Use server-side rendering instead of static hosting
D. Add a _redirects file with /index.html 200 rule
Solution
Step 1: Understand client-side routing issue
On reload, Netlify tries to find the route as a file and fails without redirect.
Step 2: Use Netlify redirect rule
Adding a _redirects file with /index.html 200 tells Netlify to serve index.html for all routes.
Final Answer:
Add a _redirects file with /index.html 200 rule -> Option D
Quick Check:
Redirect rule fixes routing reload = C [OK]
Hint: Use _redirects file for client-side routing on Netlify [OK]
Common Mistakes:
Ignoring redirect rules causing 404 on reload
Thinking JavaScript disabling helps routing
Confusing folder names for deployment
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.