generate-json-webpack-plugin
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript maintenance
Webpack plugin (v2.0.0) that generates a custom JSON asset in webpack's output directory. Requires webpack 5 (dropped webpack 4 support in v2.0.0). Use it to create JSON files from JavaScript objects during the webpack build process. Supports custom JSON.stringify replacer and space parameters for formatting. Simpler than using webpack's built-in assets approach or write-file-webpack-plugin for JSON output. Niche but focused; no active recent development (last release 2022), but stable for webpack 5 users.
Common errors
error TypeError: First argument must be a string ↓
cause Filename passed as object instead of string.
fix
Ensure first argument is a string: new GenerateJsonPlugin('file.json', { ... })
error Cannot find module 'generate-json-webpack-plugin' ↓
cause Package not installed or missing from dependencies.
fix
Run 'npm install generate-json-webpack-plugin --save-dev'.
Warnings
breaking v2.0.0 drops webpack 4 support. Only webpack 5 is supported. ↓
fix Upgrade to webpack 5 or pin to v1.x if using webpack 4.
deprecated Plugin is no longer actively maintained. Last release was 2 years ago. ↓
fix Consider using webpack's built-in asset modules or a custom plugin.
Install
npm install generate-json-webpack-plugin yarn add generate-json-webpack-plugin pnpm add generate-json-webpack-plugin Imports
- GenerateJsonWebpackPlugin wrong
import GenerateJsonPlugin from 'generate-json-webpack-plugin';correctconst GenerateJsonPlugin = require('generate-json-webpack-plugin'); - GenerateJsonWebpackPlugin wrong
new GenerateJsonPlugin({ key: 'value' })correctnew GenerateJsonPlugin('file.json', { key: 'value' }) - GenerateJsonWebpackPlugin wrong
new GenerateJsonPlugin('file.json', { key: 'value' }, 'space')correctnew GenerateJsonPlugin('file.json', { key: 'value' }, replacer, space)
Quickstart
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const path = require('path');
module.exports = {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
plugins: [
new GenerateJsonPlugin('manifest.json', {
version: '1.0.0',
description: 'Generated with generate-json-webpack-plugin',
}),
],
};