Course contentsShow
← Web Development
Lesson 1384 of 2,98225. Build Tools and BundlersFree lesson

Multi-Page Applications in Vite

Configuring Vite to handle multiple HTML entry points for multi-page application architectures.

Multi-Page Applications in Vite

What You'll Learn

You'll learn how to configure Vite to build applications with multiple HTML entry points, each representing a different page or section of your site.

Beyond Single-Page Apps

While Vite excels at single-page applications, many projects need traditional multi-page architectures—think marketing sites with separate pages for home, about, and contact, or admin dashboards with distinct login and main application views. Vite handles this elegantly through explicit entry point configuration.

Configuring Multiple Entry Points

In your vite.config.js file, you define multiple HTML files using the build.rollupOptions.input object. Each key becomes an entry point:

// vite.config.js
export default {
  build: {
    rollupOptions: {
      input: {
        main: '/index.html',
        about: '/about.html',
        contact: '/contact.html'
      }
    }
  }
}

How It Works

Each HTML file you specify acts as an independent entry point. Vite analyzes each one, discovers linked assets (CSS, JavaScript, images), and builds optimized bundles. If pages share code, Vite automatically creates shared chunks to avoid duplication—efficient by default.

During development, you navigate between pages using regular links (<a href="/about.html">), and Vite's dev server serves them with HMR support intact. In production builds, each HTML file gets its own optimized output with proper asset hashing and chunking.

Typical Structure

Your project might look like:

/index.html
/about.html
/contact.html
/src/
  main.js
  about.js
  contact.js

Each HTML file links to its corresponding JavaScript entry point.

Key Takeaway: Vite supports multi-page applications through build.rollupOptions.input configuration, treating each HTML file as an independent entry point while automatically optimizing shared code between pages.