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.
Overview
file-loader resolves imports/requires of files into URLs and emits the files into the output directory. It was commonly used for handling images, fonts, and other file assets.
Migration to Asset Modules
Webpack 5 introduced Asset Modules as a built-in replacement forfile-loader, url-loader, and raw-loader.
Installation (Legacy)
Only install if you’re maintaining a legacy webpack 4 project. For webpack 5, use Asset Modules.
Basic Usage (Legacy)
Options (Legacy)
name
Configure the output filename:
[name]- File basename[ext]- File extension[path]- File path[hash]- Content hash[contenthash]- Content hash[folder]- Folder name
outputPath
Specify output directory:
publicPath
Customize public path:
context
Set context for [path]:
Common Patterns (Legacy)
Images
Fonts
Documents
Complete Migration Guide
Images
Fonts
Custom Output Path
Asset Modules Advantages
- Built-in - No external loader required
- Better Performance - Native webpack implementation
- Simpler Configuration - Less boilerplate
- Type Safety - Better TypeScript support
- Unified API - Consistent with webpack 5 features
Asset Module Types
Webpack 5 provides four asset module types:asset/resource
Replaces file-loader - emits file and returns URL:
asset/inline
Replaces url-loader - inlines asset as data URI:
asset/source
Replaces raw-loader - exports source code:
asset
Automatic choice between resource and inline:
Complete Migration Example
Key Differences
| Feature | file-loader | Asset Modules |
|---|---|---|
| Installation | Required | Built-in |
| Extension | Uses [ext] | Uses [ext] with dot |
| Configuration | options object | generator object |
| Performance | Good | Better |
| Maintenance | Deprecated | Active |
In Asset Modules,
[ext] includes the leading dot, so use [name][ext] instead of [name].[ext].