Documentation Index
Fetch the complete documentation index at: https://docs.webpack.js.org/llms.txt
Use this file to discover all available pages before exploring further.
Output Configuration
The output configuration tells webpack how to write the compiled files to disk. While you can have multiple entry points, only one output configuration is specified.Basic Usage
At a minimum, webpack requires you to specify the output filename:bundle.js file into the dist directory.
Output Path
Theoutput.path property specifies the output directory as an absolute path:
The path must be an absolute path. Use
path.resolve() or path.join() with __dirname to ensure cross-platform compatibility.Filename Patterns
Webpack provides several substitutions for dynamic filenames:Template Strings
Available Substitutions
| Template | Description |
|---|---|
[name] | Entry point name |
[id] | Chunk id |
[contenthash] | Hash of the content (recommended for caching) |
[chunkhash] | Hash of the chunk content |
[fullhash] | Hash of the full compilation |
[hash] | Deprecated alias for [fullhash] |
Hash Length
Control hash length with a colon:Multiple Entry Points
For multiple entry points, use substitutions to create unique filenames:dist/app.bundle.jsdist/admin.bundle.js
Public Path
ThepublicPath specifies the public URL address of output files when referenced in a browser:
CDN Configuration
Automatic Public Path
Setting
publicPath: 'auto' automatically determines the public path from the document’s <script> tag or import.meta.url.Advanced Options
Asset Modules
WebAssembly
Source Maps
Library Output
For creating libraries, configure the library export:Library Types
- UMD
- CommonJS
- ESM
Chunk Loading
Control how chunks are loaded:Clean Output Directory
Compiler Output Path
Webpack’sCompiler manages the output path internally:
Hash Functions
Best Practices
- Use content hashes - For long-term caching:
[name].[contenthash].js - Set publicPath correctly - Especially when deploying to CDN
- Clean on build - Enable
clean: trueto remove old files - Unique chunk names - Use
[id]or[name]to prevent conflicts - Absolute paths - Always use absolute paths for
output.path
Common Patterns
Production Build
Development Build
Related Concepts
- Entry Points - Configure entry points
- Mode - Set development or production mode
- Targets - Configure output for different environments