Registry / devops / minimizer-webpack-plugin

minimizer-webpack-plugin

JSON →
library5.6.1jsnpmunverified

Official webpack plugin for minifying JavaScript, CSS, HTML, and JSON assets. Current stable version: 5.6.1. Release cadence: major versions align with webpack major releases. Key differentiators: integrates natively with webpack 5, supports multiple third-party minimizers (terser, esbuild, swc, cssnano, csso, etc.) via optional peer dependencies. Ships TypeScript types. Default minimizer is terser for JS, cssnano for CSS, html-minifier-terser for HTML.

npm install minimizer-webpack-plugin
INSTALL
IMPORT
SIG · MINIMIZER-WEBPACK-
M
minimizer-webpack-plugin
devopsjavascriptv5.6.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

MinimizerPlugin
import MinimizerPlugin from 'minimizer-webpack-plugin'
const { MinimizerPlugin } = require('minimizer-webpack-plugin')
Default export is the plugin class. Named export also available for TypeScript type imports.
terserMinify
import MinimizerPlugin from 'minimizer-webpack-plugin'; MinimizerPlugin.terserMinify
import { terserMinify } from 'minimizer-webpack-plugin'
Minifier functions are static properties on the class, not named exports.
swcMinify
import MinimizerPlugin from 'minimizer-webpack-plugin'; MinimizerPlugin.swcMinify
Requires @swc/core installed.

Shows basic usage with two MinimizerPlugin instances: one for JS using terser, one for CSS using cssnano.

// webpack.config.js const MinimizerPlugin = require('minimizer-webpack-plugin'); module.exports = { // ... other webpack config optimization: { minimize: true, minimizer: [ new MinimizerPlugin({ test: /\.js$/i, minify: MinimizerPlugin.terserMinify }), new MinimizerPlugin({ test: /\.css$/i, minify: MinimizerPlugin.cssnanoMinify }) ] } };
Debug
Known issues
deprecatedThe built-in webpack 5 JS minimizer is now provided by default; you only need this plugin to customize minimizer options or use non-default minimizers.
fix
Only add MinimizerPlugin to config if you need custom minifier options.
affects: >=5.0.0
breakingVersion 5.x requires webpack 5.x. No support for webpack 4.
fix
Upgrade webpack to 5.x or pin minimizer-webpack-plugin to version 3.x.
affects: >=5.0.0
gotchatest option must match file types; by default only JS is targeted. If you want to minify CSS/HTML/JSON, you must specify test regexes.
fix
Add test: /\.css$/i for CSS, etc.
affects: >=5.0.0
gotchaesbuildMinify does not support extractComments; legal comments are always preserved.
fix
Use terserMinify if you need extractComments.
affects: >=5.0.0
breakingIn version 5, the minify option now expects a function from the static properties, not a string name.
fix
Use MinimizerPlugin.terserMinify instead of 'terser'.
affects: >=5.0.0
Errors
Common errors & fixes
Error: Minifier not found. Did you install the required dependency?
Using a minifier without installing its optional peer dependency.
fix
Install the required package, e.g. npm install --save-dev @swc/core for swcMinify.
TypeError: MinimizerPlugin is not a constructor
Importing as named export instead of default export.
fix
Use import MinimizerPlugin from 'minimizer-webpack-plugin'.
Configuration error: Please provide a valid 'minify' option
No minify option provided or invalid value.
fix
Set minify: MinimizerPlugin.terserMinify (or other static property).
Upgrade
Version history
5.6.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency: webpack 5.x required
uglify-jsoptionaloptional: needed only if using uglify-js minifier
@swc/coreoptionaloptional: needed only if using swc minifier
esbuildoptionaloptional: needed only if using esbuild minifier
cssnanooptionaloptional: needed only if using cssnano CSS minifier
postcssoptionalrequired by cssnano
@swc/htmloptionaloptional: needed only if using swc HTML minifier
@minify-html/nodeoptionaloptional: needed only if using minify-html HTML minifier
cssooptionaloptional: needed only if using csso CSS minifier
clean-cssoptionaloptional: needed only if using clean-css CSS minifier
lightningcssoptionaloptional: needed only if using lightningcss CSS minifier
@swc/cssoptionaloptional: needed only if using swc CSS minifier
html-minifier-terseroptionaloptional: needed only if using html-minifier-terser HTML minifier
Agent activity
2 hits · last 30 days
node
2
Resources