Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

json-minimizer-webpack-plugin

webpack-contrib30.2kMIT5.0.1TypeScript support: included

json minimizer plugin for Webpack

json, webpack, webpack-plugin, minimize, minimizer, minify, minifier, optimize, optimizer

readme

npm node tests cover discussion size

json-minimizer-webpack-plugin

This plugin uses JSON.stringify() to minify your JSON.

Getting Started

To begin, you'll need to install json-minimizer-webpack-plugin:

npm install json-minimizer-webpack-plugin --save-dev

or

yarn add -D json-minimizer-webpack-plugin

or

pnpm add -D json-minimizer-webpack-plugin

Then add the plugin to your webpack configuration. For example:

webpack.config.js

const JsonMinimizerPlugin = require("json-minimizer-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  module: {
    rules: [
      {
        test: /\.json$/i,
        type: "asset/resource",
      },
    ],
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        {
          context: path.resolve(__dirname, "dist"),
          from: "./src/*.json",
        },
      ],
    }),
  ],
  optimization: {
    minimize: true,
    minimizer: [
      // For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
      // `...`
      new JsonMinimizerPlugin(),
    ],
  },
};

And run webpack via your preferred method.

Options

test

Type:

type test = string | RegExp | Array<string | RegExp>;

Default: /\.json(\?.*)?$/i

Test to match files against.

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new JsonMinimizerPlugin({
        test: /\.foo\.json/i,
      }),
    ],
  },
};

include

Type:

type include = string | RegExp | Array<string | RegExp>;

Default: undefined

Files to include.

webpack.config.js

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new JsonMinimizerPlugin({
        include: /\/includes/,
      }),
    ],
  },
};

exclude

Type:

type exclude = string | RegExp | Array<string | RegExp>;

Default: undefined

Files to exclude.

webpack.config.js

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new JsonMinimizerPlugin({
        exclude: /\/excludes/,
      }),
    ],
  },
};

minimizerOptions

Type:

type minimizerOptions = {
  space?: null | string | number;
  replacer?: null | Function | Array<string | number>;
};

Default: { replacer: null, space: null }

JSON.stringify() options.

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new JsonMinimizerPlugin({
        minimizerOptions: {
          space: "\t",
        },
      }),
    ],
  },
};

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

5.0.1 (2025-04-07)

Bug Fixes

5.0.0 (2024-01-15)

⚠ BREAKING CHANGES

  • minimum supported Node.js version is 18.12.0 (53b80b5)

4.0.0 (2022-05-17)

⚠ BREAKING CHANGES

  • minimum supported Node.js version is 14.15.0

3.3.0 (2021-12-16)

Features

  • removed cjs wrapper and generated types in commonjs format (export = and namespaces used in types), now you can directly use exported types (#29) (04140de)

3.2.0 (2021-12-06)

Features

3.1.1 (2021-11-17)

Chore

  • update schema-utils package to 4.0.0 version

3.1.0 (2021-10-04)

Features

3.0.0 (2021-05-18)

⚠ BREAKING CHANGES

  • minimum supported Node.js version is 12.13.0

2.1.0 (2021-01-08)

Features

  • optimize JSON assets added later by plugins (10ebd05)

2.0.0 (2020-11-09)

⚠ BREAKING CHANGES

  • minimum supported webpack version is 5.1.0

1.0.1 (2020-10-07)

Chore

  • update schema-utils

1.0.0 (2020-10-05)

Initial release

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.