gulp-babel-minify
raw JSON → 0.5.2 verified Sat Apr 25 auth: no javascript maintenance
Gulp plugin for babel-minify (formerly Babili), providing a seamless way to minify JavaScript files in a Gulp pipeline. Current stable version is 0.5.2 (2018-09-24), with no updates since then — the project is effectively in maintenance mode. It wraps babel-minify (babel-preset-minify) which uses Babel transforms for dead code elimination, constant folding, mangling, etc. Alternatives like gulp-terser or gulp-uglify are more actively maintained. Requires @babel/core as a peer dependency.
Common errors
error Error: Cannot find module '@babel/core' ↓
cause @babel/core is a peer dependency not automatically installed.
fix
Run: npm install @babel/core --save-dev
error Error: Cannot find module 'babel-preset-minify' ↓
cause babel-preset-minify is a dependency of gulp-babel-minify but may not be installed if npm peer dependency resolution is strict.
fix
Run: npm install babel-preset-minify --save-dev
error TypeError: gulpBabelMinify is not a function ↓
cause Importing using ESM (import minify from 'gulp-babel-minify') in an environment that expects CJS or missing default export.
fix
Use CommonJS require: const minify = require('gulp-babel-minify');
Warnings
deprecated The babel-minify project is no longer actively maintained. Last release 2018. Consider using gulp-terser or gulp-uglify instead. ↓
fix Switch to gulp-terser (npm install gulp-terser).
breaking In version 0.3.0, the mangle option 'blacklist' was renamed to 'exclude'. Old code using 'blacklist' will break. ↓
fix Rename 'blacklist' to 'exclude' in mangle options.
breaking In version 0.4.0, babel-minify switched from Babel 6 to Babel 7. Ensure @babel/core v7+ is installed as peer dependency. ↓
fix Upgrade @babel/core to v7 and update any Babel config (babelrc, presets) accordingly.
gotcha The 'comments' override option last argument is a Function, RegExp, or Boolean. Using some other type may silently fail. ↓
fix Ensure the 'comments' value is a Function, RegExp, or Boolean.
gotcha When using a custom babel or minifyPreset, they must be passed in the second 'overrides' argument, not inside the first options object. ↓
fix Use: minify({}, { babel: customBabel, minifyPreset: customPreset })
Install
npm install gulp-babel-minify yarn add gulp-babel-minify pnpm add gulp-babel-minify Imports
- gulpBabelMinify (default) wrong
import minify from 'gulp-babel-minify';correctconst minify = require('gulp-babel-minify'); - minify function wrong
import { minify } from 'gulp-babel-minify';correctconst minify = require('gulp-babel-minify'); - custom babel/minify preset wrong
const minify = require('gulp-babel-minify'); const options = { babel: customBabel };correctconst minify = require('gulp-babel-minify'); minify({ mangle: { keepClassName: true } }, { babel: customBabel, minifyPreset: customPreset });
Quickstart
const gulp = require('gulp');
const minify = require('gulp-babel-minify');
gulp.task('minify', () =>
gulp.src('./build/app.js')
.pipe(minify({
mangle: {
keepClassName: true
}
}))
.pipe(gulp.dest('./dist'))
);