Configuration File
Webpack uses awebpack.config.js file (or other variants) to define how your application should be bundled:
webpack.config.js
Core Configuration Options
Entry and Context
Configure entry points and base directory for resolving modules
Output
Control how webpack writes compiled files to disk
Module
Configure how different module types are processed
Resolve
Configure how modules are resolved
Optimization
Customize webpack’s optimization behavior
Plugins
Add additional functionality through plugins
Dev Server
Configure the webpack development server
DevTool
Control source map generation for debugging
Advanced Configuration
Externals
Exclude dependencies from the output bundles
Performance
Configure performance hints and budgets
Node
Configure Node.js polyfills and mocks
Stats
Control compilation output statistics
Top-Level Options
Sets the mode webpack will use. This enables different default optimizations.
The base directory (absolute path) for resolving entry points and loaders.Default:
process.cwd()Environment to build for (e.g., ‘web’, ‘node’, ‘electron-main’).
Fail out on the first error instead of tolerating it.Default:
falseEnable watch mode to rebuild on file changes.Default:
falseCustomize watch mode behavior. See Watch Options below.
Name of the configuration, used when loading multiple configurations.
Limit the number of parallel processed modules.Default:
100Capture timing information for each module.Default:
falseWatch Options
Delay rebuilds after the first change (in milliseconds).Default:
200Enable polling for file changes. Can specify interval in milliseconds.
Files or directories to exclude from watching.
Multiple Configurations
You can export an array of configurations to run multiple builds:webpack.config.js
Configuration as a Function
Export a function to dynamically generate configuration:webpack.config.js
Environment Variables
Access environment variables in your configuration:webpack.config.js