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

Multiple Entry Points

Creating separate bundles for different pages or applications within a single Webpack configuration.

Multiple Entry Points

You'll learn how to configure Webpack to generate separate bundles for different pages or applications from a single configuration.

What It Means

When building larger projects, you often have multiple HTML pages (like index.html, about.html, admin.html) or separate applications that don't need to share the same JavaScript bundle. Multiple entry points let you tell Webpack to create distinct bundles for each page, so users only download the code they actually need.

Think of it like different entrances to a building—each door leads to a specific section, and people only enter through the door relevant to their destination.

Why This Matters

Instead of forcing every page to load one giant bundle.js containing all your code, you create focused bundles:

  • home.bundle.js for the homepage
  • dashboard.bundle.js for the admin dashboard
  • checkout.bundle.js for the checkout flow

Each page gets only what it needs, improving load times and performance.

Basic Configuration

// webpack.config.js
module.exports = {
  entry: {
    home: './src/home.js',
    about: './src/about.js',
    contact: './src/contact.js'
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};

The [name] placeholder in filename gets replaced with each entry point's key (home, about, contact), creating three separate bundles.

Then in your HTML:

<!-- index.html -->
<script src="dist/home.bundle.js"></script>

<!-- about.html -->
<script src="dist/about.bundle.js"></script>

Key Takeaway: Multiple entry points let you split your application into separate bundles per page or feature, reducing unnecessary code downloads and improving performance for multi-page applications.