Have ideas to improve npm?Join in the discussion! »

    gulp-terser
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/gulp-terser package

    2.0.1 • Public • Published

    gulp-terser

    Gulp plugin, compressed es6+ code.

    Install

    $ npm install gulp-terser --save-dev
    

    or

    $ yarn add gulp-terser --dev
    

    How to use

    const gulp = require('gulp');
    const terser = require('gulp-terser');
    
    function es(){
      return gulp.src('./src/index.js')
        .pipe(terser())
        .pipe(gulp.dest('./build'));
    }
    
    exports.default = es;

    Options

    Terser configuration can be viewed https://github.com/terser-js/terser#minify-options.

    const gulp = require('gulp');
    const terser = require('gulp-terser');
    
    function es(){
      return gulp.src('./src/index.js')
        .pipe(terser({
          keep_fnames: true,
          mangle: false
        }))
        .pipe(gulp.dest('./build'));
    }
    
    exports.default = es;

    Use a 3rd-party version of minifier

    const gulp = require('gulp');
    const terser = require('terser');
    const gulpTerser = require('gulp-terser');
    
    function es(){
      return gulp.src('./src/index.js')
        .pipe(gulpTerser({}, terser.minify))
        .pipe(gulp.dest('./build'));
    }
    
    exports.default = es;

    Use sourcemaps

    You can use sourcemaps like this:

    const gulp = require('gulp');
    const sourcemaps = require('gulp-sourcemaps');
    const terser = require('gulp-terser');
    
    function es(){
      return gulp.src('./src/**/*.js')
        .pipe(sourcemaps.init())
        .pipe(terser())
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./build'));
    }
    
    exports.default = es;

    Install

    npm i gulp-terser

    DownloadsWeekly Downloads

    47,005

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    7.17 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar