Registry / devops / json-minimizer-webpack-plugin

json-minimizer-webpack-plugin

JSON →
library5.0.1jsnpmunverified

A Webpack plugin that minifies JSON assets using JSON.stringify(). Version 5.0.1 (stable). Maintained by the webpack-contrib team with regular updates; breaking changes follow major Node.js and Webpack version bumps. Differentiators: lightweight alternative to heavier minifiers, integrates seamlessly with Webpack's optimization minimizer array, supports include/exclude patterns and custom JSON.stringify options (space/replacer). Ships TypeScript definitions. Requires Node.js >= 18.12.0 and webpack >= 5.1.0.

npm install json-minimizer-webpack-plugin
INSTALL
IMPORT
SIG · JSON-MINIMIZER-WEB
J
json-minimizer-webpack-plugin
devopsjavascriptv5.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JsonMinimizerPlugin
import JsonMinimizerPlugin from 'json-minimizer-webpack-plugin'
const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin')
Default export; CommonJS require works but TypeScript may prefer import. Plugin is the default export.
JsonMinimizerPlugin (type)
import type { JsonMinimizerPluginOptions } from 'json-minimizer-webpack-plugin'
const { JsonMinimizerPluginOptions } = require('json-minimizer-webpack-plugin')
Type export available for options. Only for TypeScript projects.
constructor options
new JsonMinimizerPlugin({ test: /\.json$/i, include: [...], exclude: [...], minimizerOptions: { space: 0 } })
new JsonMinimizerPlugin() // no options
All options optional; default test matches any .json file.

Shows the minimal configuration: install plugin, add to optimization.minimizer, and copy JSON files with minification.

const path = require('path'); const CopyPlugin = require('copy-webpack-plugin'); const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin'); module.exports = { mode: 'production', entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.json$/i, type: 'asset/resource' } ] }, plugins: [ new CopyPlugin({ patterns: [{ from: './src/*.json', to: '[name][ext]' }] }) ], optimization: { minimize: true, minimizer: [ `...`, new JsonMinimizerPlugin({ test: /\.json$/i, minimizerOptions: { space: 0 } }) ] } };
Debug
Known issues
breakingNode.js version < 18.12.0 is not supported
fix
Upgrade Node.js to >= 18.12.0
affects: >=5.0.0
breakingMinimum webpack version changed to 5.1.0
fix
Update webpack to >= 5.1.0
affects: >=2.0.0
breakingTypeScript type exports changed: removed CJS wrapper and namespace exports
fix
Switch to default import for the plugin class; use type imports for options
affects: >=3.3.0 <=4.0.0
gotchaPlugin only minifies JSON that passes through Webpack as assets (not import/require of .json files which are inlined)
fix
Use type: 'asset/resource' in module rules or copy-plugin to treat JSON as separate files
affects: all
gotchaThe plugin uses JSON.stringify which may produce output that is not strictly valid JSON if replacer is incorrectly typed
fix
Ensure replacer is null, a function, or an array of strings/numbers
affects: all
Errors
Common errors & fixes
Error: '...' is not a valid minimizer. Use '...' to extend default minimizers.
Forgetting to include the spread operator when adding custom minimizers alongside defaults
fix
Add `'...'` as an entry in the minimizer array before your custom plugin
TypeError: Cannot read properties of undefined (reading 'test')
Plugin instantiated without `new` keyword or imported incorrectly
fix
Use `new JsonMinimizerPlugin({...})` and ensure default import
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency: plugin runs inside Webpack compilation
Agent activity
10 hits · last 30 days
node
10
Resources
json-minimizer-webpack-plugin — npm install json-minimizer-webpack-plugin · libregistry