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

Core Webpack Concepts: Entry and Output

Configuring entry points where Webpack starts bundling and output settings for where files are generated.

Core Webpack Concepts: Entry and Output

You'll learn how to tell Webpack where to start bundling and where to put the results.

When you run Webpack, it needs two critical pieces of information: where to begin building your dependency graph, and where to save the final bundle. Think of it like giving someone directions—you need a starting point and a destination.

Entry: Where Webpack Starts

The entry point is the file where Webpack begins its work. It analyzes this file, follows all its imports, then follows those imports, and so on, building a complete map of your application's dependencies.

In webpack.config.js, you specify entry like this:

module.exports = {
  entry: './src/index.js'
};

This tells Webpack: "Start at src/index.js and trace all the modules it needs."

You can also define multiple entry points for applications with separate bundles:

module.exports = {
  entry: {
    main: './src/index.js',
    admin: './src/admin.js'
  }
};

Output: Where Bundles Go

The output configuration tells Webpack where to write the bundled files and what to name them.

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};

Here, Webpack creates a bundle.js file inside a dist folder.

For multiple entries, use placeholders:

output: {
  filename: '[name].bundle.js',
  path: path.resolve(__dirname, 'dist')
}

The [name] placeholder uses the entry point's key name (like main or admin).

Key Takeaway: Entry tells Webpack where to start, output tells it where to finish—together they form the foundation of every Webpack configuration.