Webpack Manifest Plugin
raw JSON → 6.0.1 verified Sat Apr 25 auth: no javascript
A Webpack plugin that generates a JSON manifest file mapping source filenames to their corresponding built output filenames, useful for server-side rendering or cache busting. Current stable version is 6.0.1, which is ESM-only and requires Node.js 20.19.0+ and Webpack 5.75.0+. Maintained by shellscape. Releases follow semantic versioning with major breaking changes in v6 (ESM switch, Node 20+), v5 (drop webpack v4), v4 (TypeScript types added). Primarily differentiates from similar plugins by its simplicity and configurability (filter, map, generate options). Peer dependency on webpack ^5.75.0.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/webpack-manifest-plugin/dist/index.js from /path/to/project/webpack.config.js not supported. ↓
cause Using require() with an ESM-only package (v6+).
fix
Change config to ESM: rename file to .mjs and use import, or use dynamic import().
error TypeError: file.isInitial is not a function ↓
cause Using the 'filter' option and referencing 'isInitial' incorrectly (it's a boolean property, not a method).
fix
Use file.isInitial directly: filter: (file) => file.isInitial
error Module parse failed: Unexpected token with webpack 4 ↓
cause Using webpack-manifest-plugin v5+ with webpack v4.
fix
Upgrade to webpack v5 or use webpack-manifest-plugin v4.x.
Warnings
breaking v6.0.0 dropped CommonJS support; only ESM is supported. ↓
fix Convert project to ESM or continue using v5.x if CJS is required.
breaking v6.0.0 requires Node.js >=20.19.0. ↓
fix Upgrade Node.js to 20.19.0 or later, or pin to v5.x.
breaking v5.0.0 dropped support for webpack v4. ↓
fix Upgrade to webpack v5 or use v4.x of this plugin.
deprecated Option 'useLegacyEmit' was removed in v5 without replacement. ↓
fix Remove 'useLegacyEmit' from options; use 'assetHookStage' instead.
gotcha If using the 'filter' option, ensure it returns Boolean. Incorrect return values (e.g. undefined) cause unexpected behavior. ↓
fix Always explicitly return true/false from the filter function.
gotcha The 'generate' option replaces the entire manifest object. If 'generate' is provided, 'filter', 'map', and other options are ignored for that function's logic. ↓
fix Use 'generate' only when you need full control; otherwise use 'filter'/'map'.
Install
npm install webpack-manifest-plugin yarn add webpack-manifest-plugin pnpm add webpack-manifest-plugin Imports
- WebpackManifestPlugin wrong
const WebpackManifestPlugin = require('webpack-manifest-plugin')correctimport { WebpackManifestPlugin } from 'webpack-manifest-plugin' - type FileDescriptor wrong
import { FileDescriptor } from 'webpack-manifest-plugin'correctimport type { FileDescriptor } from 'webpack-manifest-plugin' - default import wrong
import WebpackManifestPlugin from 'webpack-manifest-plugin'correctimport { WebpackManifestPlugin } from 'webpack-manifest-plugin'
Quickstart
// webpack.config.mjs
import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
export default {
entry: './src/index.js',
output: {
filename: '[name].[contenthash:8].js',
path: new URL('./dist', import.meta.url).pathname,
},
plugins: [
new WebpackManifestPlugin({
fileName: 'asset-manifest.json',
basePath: '/app/',
publicPath: '/app/',
filter: (file) => file.isInitial,
map: (file) => ({ ...file, path: file.path.replace(/^\.\//, '') }),
}),
],
mode: 'production',
};