Babel Minify Webpack Plugin
raw JSON → 0.3.1 verified Sat Apr 25 auth: no javascript maintenance
A webpack plugin that uses babel-minify (formerly babili) to minify JavaScript bundles. Current stable version is 0.3.1, released March 2018. Last release was a bugfix for webpack 4 tapable deprecation warnings. The plugin operates on entire chunks rather than individual files, enabling optimizations not possible with loader-based minification. However, it is slower than using babel-loader with the minify preset. The package has narrow engine requirements (Node 4.3–5.0 or >=5.10) and is essentially in maintenance mode, with no releases since 2018 and webpack 5 not officially supported. Alternatives include terser-webpack-plugin and babel-loader with preset-minify.
Common errors
error Error: Cannot find module 'babel-minify-webpack-plugin' ↓
cause Package not installed or incorrectly named.
fix
Run
npm install babel-minify-webpack-plugin --save-dev and use correct import. error TypeError: MinifyPlugin is not a constructor ↓
cause Using ES6 import when the package does not have a default ESM export.
fix
Use
const MinifyPlugin = require('babel-minify-webpack-plugin'); instead of import MinifyPlugin from '...'. error Error: Plugin invalid: A non-default property of a plugin was used ↓
cause Incorrect usage in webpack configuration (e.g., not instantiating the plugin).
fix
Ensure the plugin is instantiated with
new MinifyPlugin(...) inside the plugins array. Warnings
breaking API changed from `new BabiliPlugin(options)` to `new BabiliPlugin(babiliOptions, overrides)` in v0.0.9. ↓
fix Update constructor to `new BabiliPlugin(babiliOptions, overrides)` or use v0.3.1 (named babel-minify-webpack-plugin) with `new MinifyPlugin(minifyOpts, pluginOpts)`.
deprecated Renamed from babili-webpack-plugin to babel-minify-webpack-plugin in v0.2.0. Old package is deprecated. ↓
fix Install babel-minify-webpack-plugin instead of babili-webpack-plugin.
gotcha Node engine requirement: ">= 4.3 < 5.0.0 || >= 5.10". Node 5.0.0–5.9.x is not supported. ↓
fix Use Node >= 4.3 < 5.0 or >= 5.10 (e.g., Node 6+).
gotcha Webpack 5 is not officially supported. The last release targets webpack 2, 3, and 4. ↓
fix Use terser-webpack-plugin for webpack 5, or test with this plugin but expect issues.
gotcha The plugin operates on the entire chunk, which can be slow for large bundles. Consider using babel-loader with preset-minify for faster builds. ↓
fix Use babel-loader with `presets: ['minify']` and enable `mangle.topLevel` if needed.
Install
npm install babel-minify-webpack-plugin yarn add babel-minify-webpack-plugin pnpm add babel-minify-webpack-plugin Imports
- MinifyPlugin wrong
import MinifyPlugin from 'babel-minify-webpack-plugin';correctconst MinifyPlugin = require('babel-minify-webpack-plugin'); - MinifyPlugin wrong
const Minify = require('babel-minify-webpack-plugin').default;correct// webpack.config.js const MinifyPlugin = require('babel-minify-webpack-plugin'); - MinifyPlugin wrong
plugins: [new MinifyPlugin({ comments: false })]correctplugins: [new MinifyPlugin({ mangle: { topLevel: true } }, { sourceMap: true })]
Quickstart
// webpack.config.js
const path = require('path');
const MinifyPlugin = require('babel-minify-webpack-plugin');
module.exports = {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new MinifyPlugin(
{ mangle: { topLevel: true } },
{ comments: false, sourceMap: false }
)
]
};