Registry / devops / gulp-terser

gulp-terser

JSON →
library2.1.0jsnpmunverified

Gulp plugin for minifying ES6+ code using Terser. Version 2.1.0, stable, maintained. Provides a drop-in replacement for gulp-uglify for modern JavaScript. Supports all Terser options, sourcemaps, and custom minifiers. Active development with regular updates. Differentiator: works with ES6+ syntax out of the box, unlike gulp-uglify which requires babel.

npm install gulp-terser
INSTALL
IMPORT
SIG · GULP-TERSER
G
gulp-terser
devopsjavascriptv2.1.0
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.

default
import terser from 'gulp-terser';
const terser = require('gulp-terser');
CommonJS require works in Node.js, but ES import is preferred for modern projects.
default
const terser = require('gulp-terser');
CommonJS usage is valid; no wrong pattern for require.
terser.minify
import terser from 'terser'; const gulpTerser = require('gulp-terser'); gulpTerser({}, terser.minify)
gulpTerser({}, terser)
When using a 3rd-party minifier, pass the minify function explicitly, not the whole module.

Shows basic gulp-terser setup with options to drop console logs during minification.

const gulp = require('gulp'); const terser = require('gulp-terser'); function minify() { return gulp.src('src/*.js') .pipe(terser({ compress: { drop_console: true } })) .pipe(gulp.dest('dist')); } exports.default = minify;
Debug
Known issues
gotchagulp-terser uses terser under the hood; terser options must be passed as an object to gulp-terser, not as separate arguments.
fix
Wrap all options in a single object: terser({ keep_fnames: true }).
affects: >=0.0.0
gotchaWhen using sourcemaps, ensure gulp-sourcemaps is used before and after terser plugin.
fix
Add .pipe(sourcemaps.init()) before .pipe(terser()) and .pipe(sourcemaps.write()) after.
affects: >=0.0.0
breakinggulp-terser v2 dropped support for Node <10. Older Node versions may cause errors.
fix
Upgrade Node to >=10 or use gulp-terser v1.x.
affects: >=2.0.0
gotchaCustom minifier function must be the second argument to gulp-terser; otherwise, it will be treated as options.
fix
Pass empty object for options if not needed: gulpTerser({}, customMinifier).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'gulp-terser'
Package not installed or installed globally instead of locally.
fix
Run npm install --save-dev gulp-terser in your project directory.
TypeError: gulpTerser is not a function
Wrong import: used import instead of require or required wrong module.
fix
Use const terser = require('gulp-terser'); or import terser from 'gulp-terser'; correctly.
Error: terser.minify is not a function
When using 3rd-party minifier, passed the whole module instead of the minify method.
fix
Pass terser.minify as the second argument, not terser itself.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
gulpoptionalpeer dependency for gulp plugin functionality
Agent activity
4 hits · last 30 days
node
4
Resources
gulp-terser — npm install gulp-terser · libregistry