Minify javascript by UglifyJs2 with command line options for gulp.
npm i -g uglify-js
npm i --save-dev gulp-uglify-cli
var uglify = require('gulp-uglify-cli')
gulp.task('minifyjs', function(){
return gulp.src('index.js')
.pipe(uglify())
.pipe(gulp.dest('dist'))
})You can use all command line options in UglifyJs2.
-
String command line option
uglify('-c -m --screw-ie8') -
Array command line option
uglify(['-c', '-m', '--screw-ie8']) -
Hash option
uglify({preCommand: 'license.js', command: '-c -m --screw-ie8'})By setting
outputoption, you can output file directly.uglify({command: '-c', output: '/home/test/output.js'})By setting
uglifyjsoption, you can use custom uglifyjs path.uglify({command: '-c', uglifyjs: '/home/node_modules/.bin/uglifyjs'})If you have an error 'Permission Denied' in 'gulp-uglify-cli', please try to use
tmpoption which is accessible file path.uglify({command: '-c', tmp: '/tmp/_tmp.js'})