Entry Points
The entry point is where webpack starts building the internal dependency graph. From the entry point, webpack determines which modules and libraries the entry depends on (directly and indirectly).Overview
Every webpack build starts from one or more entry points. Entry points tell webpack where to start and follow the graph of dependencies to know what to bundle.Configuration
Single Entry Syntax
The simplest entry configuration is a single string:Object Syntax
For multiple entry points, use object syntax:Array Syntax
Pass an array of file paths to create a “multi-main entry”:Entry Descriptor
For advanced configuration, use entry descriptor objects:Entry Options
Entry descriptors provide fine-grained control over how entry chunks are created and loaded.
| Option | Description |
|---|---|
import | Module(s) that are loaded on startup |
filename | Specifies the name of each output file on disk |
dependOn | Entry points that the current entry depends on |
chunkLoading | Method of loading chunks (e.g., ‘jsonp’, ‘import-scripts’) |
asyncChunks | Create async chunks for this entry |
layer | Specify the layer for this entry |
runtime | Name of the runtime chunk |
How Entry Points Work
Internally, webpack uses theEntryPlugin to process entry points:
The
compilation.addEntry method starts the dependency resolution process, creating an entry point in the module graph.Dynamic Entry
Entry points can be functions that return a configuration:Multiple Entry Points
When using multiple entry points, consider these patterns:Separate App and Vendor Entries
Multi-Page Application
Best Practices
- Use descriptive names - Entry point names become part of the output filename
- Split by page - For multi-page apps, create one entry per page
- Share common code - Use
dependOnor optimization.splitChunks to share code between entries - Consider runtime - Specify a shared runtime chunk to avoid duplication
Related Concepts
- Output - Configure where webpack emits bundles
- Dependency Graph - How webpack builds the module graph
- Loaders - Transform files as they’re added to the dependency graph