Gulp plugin, compressed es6+ code.
$ npm install gulp-terser --save-dev
or
$ yarn add gulp-terser --dev
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;
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;
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;
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;