Webpack Chunks to JSON Plugin
chunks-2-json-webpack-plugin is a utility plugin specifically designed for Webpack 4, which outputs a JSON manifest of your project's build artifacts. Its core purpose is to provide an external system with a predictable map of generated chunk filenames, particularly when these names include content hashes for caching. This addresses common scenarios where a deployment environment needs to dynamically reference or inject build assets without direct knowledge of Webpack's output naming conventions. The current stable version is 1.0.4, though the project appears to be in maintenance mode given its specific tie to Webpack 4. It differentiates itself by offering a simple, dependency-free solution for Webpack 4, producing a configurable JSON structure that details file types (e.g., `js`, `css`, `js.map`) grouped by chunk names, facilitating easier integration with external rendering systems.
Warnings
- breaking In version 1.0.0, the internal data structure for chunk sources changed. They are now treated as an array rather than a string. This breaks compatibility with configurations or consumers expecting the older string format.
- gotcha This plugin is specifically built for Webpack 4. It is not compatible with Webpack 5 or later versions due to significant changes in Webpack's internal architecture and plugin API.
- gotcha The `publicPath` option for the plugin should almost always match the `output.publicPath` setting in your main Webpack configuration to ensure correct paths are generated in the manifest.
Install
-
npm install chunks-2-json-webpack-plugin -
yarn add chunks-2-json-webpack-plugin -
pnpm add chunks-2-json-webpack-plugin
Imports
- Chunks2JsonPlugin
import { Chunks2JsonPlugin } from 'chunks-2-json-webpack-plugin';const Chunks2JsonPlugin = require('chunks-2-json-webpack-plugin');
Quickstart
const Chunks2JsonPlugin = require('chunks-2-json-webpack-plugin');
const path = require('path');
const publicPath = '/app/';
module.exports = {
entry: './src/index.js',
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, 'dist'),
publicPath
},
plugins: [
new Chunks2JsonPlugin({ outputDir: 'dist/', publicPath })
]
};