{"id":20165,"library":"json-minimizer-webpack-plugin","title":"JsonMinimizerPlugin","description":"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.","status":"active","version":"5.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/webpack-contrib/json-minimizer-webpack-plugin","tags":["javascript","json","webpack","webpack-plugin","minimize","minimizer","minify","minifier","optimize","typescript"],"install":[{"cmd":"npm install json-minimizer-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add json-minimizer-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-minimizer-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: plugin runs inside Webpack compilation","package":"webpack","optional":false}],"imports":[{"note":"Default export; CommonJS require works but TypeScript may prefer import. Plugin is the default export.","wrong":"const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin')","symbol":"JsonMinimizerPlugin","correct":"import JsonMinimizerPlugin from 'json-minimizer-webpack-plugin'"},{"note":"Type export available for options. Only for TypeScript projects.","wrong":"const { JsonMinimizerPluginOptions } = require('json-minimizer-webpack-plugin')","symbol":"JsonMinimizerPlugin (type)","correct":"import type { JsonMinimizerPluginOptions } from 'json-minimizer-webpack-plugin'"},{"note":"All options optional; default test matches any .json file.","wrong":"new JsonMinimizerPlugin() // no options","symbol":"constructor options","correct":"new JsonMinimizerPlugin({ test: /\\.json$/i, include: [...], exclude: [...], minimizerOptions: { space: 0 } })"}],"quickstart":{"code":"const path = require('path');\nconst CopyPlugin = require('copy-webpack-plugin');\nconst JsonMinimizerPlugin = require('json-minimizer-webpack-plugin');\n\nmodule.exports = {\n  mode: 'production',\n  entry: './src/index.js',\n  output: { path: path.resolve(__dirname, 'dist') },\n  module: {\n    rules: [\n      { test: /\\.json$/i, type: 'asset/resource' }\n    ]\n  },\n  plugins: [\n    new CopyPlugin({\n      patterns: [{ from: './src/*.json', to: '[name][ext]' }]\n    })\n  ],\n  optimization: {\n    minimize: true,\n    minimizer: [\n      `...`,\n      new JsonMinimizerPlugin({\n        test: /\\.json$/i,\n        minimizerOptions: { space: 0 }\n      })\n    ]\n  }\n};","lang":"javascript","description":"Shows the minimal configuration: install plugin, add to optimization.minimizer, and copy JSON files with minification."},"warnings":[{"fix":"Upgrade Node.js to >= 18.12.0","message":"Node.js version < 18.12.0 is not supported","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Update webpack to >= 5.1.0","message":"Minimum webpack version changed to 5.1.0","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Switch to default import for the plugin class; use type imports for options","message":"TypeScript type exports changed: removed CJS wrapper and namespace exports","severity":"breaking","affected_versions":">=3.3.0 <=4.0.0"},{"fix":"Use type: 'asset/resource' in module rules or copy-plugin to treat JSON as separate files","message":"Plugin only minifies JSON that passes through Webpack as assets (not import/require of .json files which are inlined)","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure replacer is null, a function, or an array of strings/numbers","message":"The plugin uses JSON.stringify which may produce output that is not strictly valid JSON if replacer is incorrectly typed","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add `'...'` as an entry in the minimizer array before your custom plugin","cause":"Forgetting to include the spread operator when adding custom minimizers alongside defaults","error":"Error: '...' is not a valid minimizer. Use '...' to extend default minimizers."},{"fix":"Use `new JsonMinimizerPlugin({...})` and ensure default import","cause":"Plugin instantiated without `new` keyword or imported incorrectly","error":"TypeError: Cannot read properties of undefined (reading 'test')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}