With your environment ready, it is time to create the project that will accompany us throughout the course: Colmena Bookings. In this lesson you will run the official scaffolding tool, start the Vite development server and take your time going through every generated file to understand what it does and how the files connect to one another. Then you will learn the anatomy of a Single File Component (a .vue file), clean up the example code and make your first change of your own: a header with the application's name and a counter of free rooms. Finally, you will see hot reloading and inspection with Vue DevTools in action.

Contents

  1. Creating the project with npm create vue@latest
  2. Installing dependencies and starting the development server
  3. A tour of the project structure
  4. How the application starts: from index.html to App.vue
  5. Anatomy of a Single File Component
  6. Cleaning up the example template
  7. Your first change: a header and a free-rooms counter
  8. Hot module replacement (HMR) and inspection with Vue DevTools
  9. A quick look at build and preview

  1. Creating the project with npm create vue@latest

Open a terminal in the folder where you keep your projects (for example, ~/projects) and run:

npm create vue@latest colmena-bookings
  • npm create vue@latest downloads and runs the latest version of the official create-vue scaffolding tool.
  • colmena-bookings is the name of the project folder; because you pass it in the command, the tool will not ask you for it.

The first time, npm may ask you to confirm downloading the create-vue package: answer y. Then answer the questions as we decided in the previous lesson: only ESLint and Prettier; "No" to everything else (and "Yes" to the Vue DevTools plugin if your version of the tool asks about it). When it finishes, you will see a message similar to this one:

Scaffolding project in /home/your-user/projects/colmena-bookings...

Done. Now run:

  cd colmena-bookings
  npm install
  npm run format
  npm run dev

  1. Installing dependencies and starting the development server

Follow the tool's instructions:

cd colmena-bookings
npm install
npm run format
npm run dev

What each command does:

Command What it does
cd colmena-bookings Moves into the project folder
npm install Reads package.json, downloads Vue, Vite and the other dependencies into node_modules/ and creates package-lock.json
npm run format Runs Prettier on src/ so the code follows the project's formatting
npm run dev Starts the Vite development server

The output of npm run dev will look something like this:

  VITE v7.x.x  ready in 350 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  Vue DevTools: Open http://localhost:5173/__devtools__/ as a separate window
  ➜  press h + enter to show help

Open http://localhost:5173/ in your browser and you will see the Vue welcome page. The server keeps running as long as the terminal is open; to stop it, press Ctrl+C. Leave that terminal open and use another one for the remaining commands.

Now is a good moment to do what we mentioned in the previous lesson: pin the project's Node version and create the Git repository.

node --version > .nvmrc   # saves the current Node version (e.g. v24.x.x)
git init
git add .
git commit -m "Initial project generated with create-vue"

Open the folder in VS Code with code .. If VS Code suggests installing the project's recommended extensions, accept: they are the same ones you installed in the previous lesson.

  1. A tour of the project structure

The scaffolding tool generates a structure like this one (it may vary slightly depending on the version):

colmena-bookings/
├── .vscode/               # Recommended extensions and settings for VS Code
├── node_modules/          # Installed dependencies (never edited or committed to Git)
├── public/
│   └── favicon.ico        # Files copied as-is when publishing
├── src/
│   ├── assets/            # CSS, images and other resources processed by Vite
│   │   ├── base.css
│   │   ├── logo.svg
│   │   └── main.css
│   ├── components/        # Reusable components (example ones, for now)
│   │   ├── icons/
│   │   ├── HelloWorld.vue
│   │   ├── TheWelcome.vue
│   │   └── WelcomeItem.vue
│   ├── App.vue            # Root component
│   └── main.js            # JavaScript entry point
├── .editorconfig
├── .gitignore
├── .nvmrc                 # We have just created this one ourselves
├── .prettierrc.json       # Prettier formatting rules
├── eslint.config.js       # ESLint rules
├── index.html             # HTML page served by Vite
├── jsconfig.json          # Helps the editor understand paths (the @ alias)
├── package.json           # Dependencies and scripts
├── package-lock.json      # Exact installed versions
├── README.md
└── vite.config.js         # Vite configuration

This table describes the most important files and folders:

Item Purpose Will you edit it often?
index.html The SPA's only HTML page. It contains the <div id="app"> and loads src/main.js as a module Rarely (title, language, favicon)
src/main.js Creates the Vue application with createApp, imports the global styles and mounts it on #app Yes, when adding the router, stores or plugins
src/App.vue Root component: the first one to be rendered, which will contain all the others Yes
src/components/ Folder for reusable components Constantly (from module 3 onwards)
src/assets/ Resources processed by Vite: CSS, images, fonts. They can be imported from code Sometimes
public/ Resources served as-is, unprocessed, from the site root (/favicon.ico) Rarely
vite.config.js Vite plugins (.vue support, DevTools) and path aliases Rarely
package.json Project name, dependencies and npm scripts When installing packages
eslint.config.js and .prettierrc.json Quality and formatting rules shared by the team Hardly ever

3.1 package.json and its scripts

Open package.json. You will see something like this (the exact versions will vary):

{
  "name": "colmena-bookings",
  "version": "0.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "lint": "eslint . --fix",
    "format": "prettier --write src/"
  },
  "dependencies": {
    "vue": "^3.5.0"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^6.0.0",
    "eslint": "^9.0.0",
    "eslint-plugin-vue": "^10.0.0",
    "prettier": "^3.0.0",
    "vite": "^7.0.0",
    "vite-plugin-vue-devtools": "^8.0.0"
  }
}
  • "type": "module": the project uses ES modules (import/export), including in the configuration files.
  • dependencies: what the application needs in order to run in the browser. Right now, just vue.
  • devDependencies: tools used only during development and build (Vite, ESLint, Prettier...).
  • scripts: shortcuts you run with npm run <name>:
Script Actual command Use
dev vite Development server with hot reloading
build vite build Builds the application for production into the dist/ folder
preview vite preview Serves the output of build locally so you can check it
lint eslint . --fix Checks the code and fixes what it can
format prettier --write src/ Formats every file in src/

3.2 vite.config.js

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

export default defineConfig({
  plugins: [vue(), vueDevTools()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
  • vue(): the plugin that teaches Vite how to compile .vue files.
  • vueDevTools(): embeds Vue DevTools in the page during development (if your version does not include it, that is fine: you will use the browser extension).
  • alias: { '@': ... }: lets you write import X from '@/components/X.vue' instead of relative paths such as ../../components/X.vue. @ always points to src/.

  1. How the application starts: from index.html to App.vue

Take a look at index.html:

<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

The <div id="app"> is empty: Vue will fill it. The <script type="module"> tag loads src/main.js:

import './assets/main.css'

import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
  1. import './assets/main.css': imports the global styles. Vite injects that CSS into the page.
  2. import { createApp } from 'vue': instead of using the CDN's global Vue variable, we import the function from the installed package.
  3. import App from './App.vue': imports the root component. Thanks to the vue() plugin, Vite turns the .vue file into JavaScript.
  4. createApp(App).mount('#app'): creates the application with App as the root component and mounts it on the div. It is the same thing you did in the first lesson, but with the component in its own file.
flowchart LR
    A["index.html"] -->|"script type=module"| B["src/main.js"]
    B -->|"import"| C["src/App.vue"]
    B -->|"createApp(App).mount('#app')"| D["div#app rendered"]
    C -->|"imports"| E["src/components/*.vue"]

Take the opportunity to customise index.html: change lang="" to lang="en" and the title to <title>Colmena Bookings</title>.

  1. Anatomy of a Single File Component

A Single File Component (SFC) is a .vue file that brings the three parts of a component together in one place:

<script setup>
// 1. Logic: the component's JavaScript
const message = 'Hello from an SFC'
</script>

<template>
  <!-- 2. Template: the HTML the component generates -->
  <p class="greeting">{{ message }}</p>
</template>

<style scoped>
/* 3. Styles: CSS that only affects this component */
.greeting {
  color: darkgoldenrod;
}
</style>
Block What it contains Details
<script setup> The component's logic Everything you declare at the top level (variables, functions, imports) is automatically available in the template, with no return. This is the style we will use throughout the course; we will compare it with others in 01-05
<template> The HTML markup with Vue syntax It is compiled into an optimised render function. Its syntax is covered in 02-01
<style scoped> CSS styles With scoped, Vue adds a unique attribute (for example, data-v-7a7a37b1) to the component's elements and rewrites the selectors, so the CSS does not "leak" into other components

The order of the blocks does not matter; the official convention recommends <script>, then <template> and then <style>. Compare this with the CDN example from the first lesson: there we needed setup() and a return; with <script setup> the compiler takes care of that for us.

  1. Cleaning up the example template

The project comes with demo components that we do not need. Let's delete them:

rm -r src/components/*
rm src/assets/logo.svg

On Windows (PowerShell) you can use Remove-Item -Recurse src/components/* and Remove-Item src/assets/logo.svg, or simply delete them from VS Code.

Replace the contents of src/assets/main.css with some simple base styles for Colmena (you can keep base.css, but we will no longer import it):

/* src/assets/main.css: global styles for Colmena Bookings */
:root {
  --color-honey: #f5a623;
  --color-honey-dark: #c47f00;
  --color-text: #2b2b2b;
  --color-background: #fffaf0;
  font-family: system-ui, sans-serif;
}

body {
  margin: 0;
  color: var(--color-text);
  background: var(--color-background);
}

CSS variables (--color-honey, etc.) will let us reuse Colmena's brand colours in every component.

If you look at the browser now, you will see an error: App.vue still imports the components we have just deleted. We will fix that in the next step.

  1. Your first change: a header and a free-rooms counter

Replace the entire contents of src/App.vue with:

<script setup>
import { ref } from 'vue'

// Colmena has 5 rooms in its catalogue; at the start, they are all free
const freeRooms = ref(5)

function bookRoom() {
  if (freeRooms.value > 0) {
    freeRooms.value--
  }
}
</script>

<template>
  <header class="header">
    <h1>Colmena Bookings</h1>
    <p>Room booking for the Colmena coworking space</p>
  </header>

  <main class="content">
    <p>
      Rooms free right now: <strong>{{ freeRooms }}</strong>
    </p>
    <button class="button" @click="bookRoom">Book a room</button>
  </main>
</template>

<style scoped>
.header {
  padding: 1.5rem 2rem;
  background: var(--color-honey);
}

.header h1 {
  margin: 0;
}

.content {
  padding: 2rem;
}

.button {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 6px;
  background: var(--color-honey-dark);
  color: white;
  cursor: pointer;
}
</style>

Let's go through it piece by piece:

  • import { ref } from 'vue': we import ref from the vue package. With the CDN we took it from the global variable; here it is imported like any other ES module.
  • const freeRooms = ref(5): a reactive data item that starts at 5 (the five rooms in the catalogue). As in the first lesson, in JavaScript you access it with .value and in the template without it. We will explain why it works this way in Reactivity: ref and reactive.
  • function bookRoom(): decreases the counter without going below zero. Because it is declared in <script setup>, the template can use it directly.
  • <header> and <main>: in Vue 3 a component can have several root elements (Vue 2 allowed only one).
  • {{ freeRooms }} and @click="bookRoom": the interpolation and click event you already know.
  • <style scoped>: the styles affect only this component; they use the CSS variables defined in main.css.

Save the file: the browser will show the Colmena Bookings header and the counter. Click the button and you will see the number go down to 0.

For now the counter is just a standalone number. In module 2 we will replace it with the real list of rooms, displayed with v-for (List Rendering), and in module 3 we will split the interface into our own components.

Save this point in Git:

git add .
git commit -m "Clean up the template and add a header and free-rooms counter"

  1. Hot module replacement (HMR) and inspection with Vue DevTools

8.1 Hot Module Replacement

With the server running, try this experiment:

  1. Click the button twice: the counter shows 3.
  2. In App.vue, change the button text to "Book a room now" and save.
  3. The browser updates the button without reloading the page and the counter is still at 3.

This is hot reloading, or Hot Module Replacement (HMR): Vite swaps out only the module that changed. When you change only the template or the styles, the state is preserved. If you modify the <script setup> block, Vue recreates the component and the state is reset (the counter goes back to 5). If something stops responding, a manual reload (F5) always restores the page.

8.2 Vue DevTools

Open the developer tools (F12) and go to the Vue tab (or, if your project includes the plugin, click the small floating button at the bottom of the page, or press Alt+Shift+D):

  1. In the component tree you will see App. Select it.
  2. In the right-hand panel, under setup, freeRooms appears with its current value.
  3. Double-click the value, type 2 and press Enter: the page updates instantly.
  4. Click the application's button and watch the value change in DevTools.

You have just seen reactivity working live in both directions: changes to the state are reflected in the view, no matter who triggers them.

  1. A quick look at build and preview

Although going to production is covered in Building for Production, it is worth knowing that these two commands exist:

npm run build     # generates the optimised version in dist/
npm run preview   # serves it locally (by default at http://localhost:4173)

Try them if you are curious; the dist/ folder is already included in .gitignore, so it will not be committed to the repository.

Common Mistakes and Tips

  • Running npm run dev outside the project folder. npm will say it cannot find package.json. Check where you are with pwd (or cd on Windows).
  • Forgetting npm install. You will see errors such as "vite: not found". You need to install dependencies after creating or cloning a project.
  • Port 5173 is already in use. Vite will automatically use the next free one (5174...). Check the URL shown in the terminal.
  • A blank screen after cleaning up the template. It is almost always an import of a deleted file. Check the browser console and the terminal: the message tells you the file and the line.
  • Writing freeRooms.value in the template, or freeRooms without .value in the script. You do not use .value in the template; you do in the script.
  • Committing node_modules/ to Git. It is already in .gitignore; do not remove it. Anyone can regenerate it with npm install.
  • Tip: run npm run lint from time to time; ESLint will catch things such as variables you declare but never use.

Exercises

Exercise 1. Add a second paragraph to the header in App.vue with the text "3-storey building · 5 rooms" and give it a scoped italic style. Check that the counter keeps its value when you save (HMR).

Exercise 2. Add a "Release a room" button that increments freeRooms without going above 5.

Exercise 3. Open the browser's developer tools (F12) and inspect a <p> in the header with the element inspector (the browser's Elements tab, not the Vue one). What odd attribute appears in the HTML, and why?

Solutions

Solution 1.

<template>
  <header class="header">
    <h1>Colmena Bookings</h1>
    <p>Room booking for the Colmena coworking space</p>
    <p class="detail">3-storey building · 5 rooms</p>
  </header>
  <!-- ... rest unchanged ... -->
</template>

<style scoped>
/* ... previous styles ... */
.detail {
  font-style: italic;
}
</style>

Because only the template and styles change, the counter keeps its value after saving.

Solution 2.

<script setup>
import { ref } from 'vue'

const totalRooms = 5
const freeRooms = ref(totalRooms)

function bookRoom() {
  if (freeRooms.value > 0) freeRooms.value--
}

function releaseRoom() {
  if (freeRooms.value < totalRooms) freeRooms.value++
}
</script>

And in the template: <button class="button" @click="releaseRoom">Release a room</button>. Notice that totalRooms is not reactive: it is a constant that never changes, so it does not need ref. Because you have modified the <script setup> block, the counter will have been reset when you saved: this is the expected HMR behaviour.

Solution 3. An attribute such as data-v-7a7a37b1 appears. It is the identifier Vue generates for <style scoped>: the .detail selector is transformed into .detail[data-v-7a7a37b1], so the style only affects this component's elements.

Conclusion

You have created the colmena-bookings project with npm create vue@latest, started the Vite server and you know the role of each file: index.html loads src/main.js, which creates the application with createApp and mounts the root component, App.vue. You know that a Single File Component brings together <script setup>, <template> and <style scoped>, you have cleaned up the example and written your first version of Colmena Bookings with a header and a reactive counter, and you have seen hot reloading and inspection with Vue DevTools in action.

We have been using createApp and mount almost without thinking. In the next lesson, Understanding the Vue Instance, we will see what really happens when an application is created, what a component instance is, and which stages every component goes through from the moment it is born until it disappears.

New edition · October 2026

Vue.js Course

Module 1: Introduction to Vue.js

Module 2: Vue.js Basics

Module 3: Vue.js Components

Module 4: Vue Router

Module 5: State Management with Vuex and Pinia

Module 6: Vue.js Directives

Module 7: Vue.js Plugins

Module 8: Testing in Vue.js

Module 9: Advanced Vue.js Concepts

Module 10: Building and Deploying Vue.js Applications

Module 11: Real-World Vue.js Projects

© Copyright 2026. All rights reserved