Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp Uglify Options not applying

Hi I am making a theme for the company i work at and the JS segments will not build properly in uglify. I am trying to use uglify to simply concatenate my files, which works but they output minified and mangled with no comments and i cannot figure out why, below is my gulp task which runs correctly but doesnt output with the options provided

gulp.task('js', function() {
return gulp.src('./src/js/*.js')
    .pipe(uglify({
        options: {
            mangle: false,
            beautify: true,
            comments: true
        }
    }))
    .pipe(rename('cf247bootstrapTheme.js'))
    .pipe(gulp.dest('./dist/js'));
});

Any ideas why this is happening?

Thanks,

Kieran

like image 584
Kieranmv95 Avatar asked May 31 '16 10:05

Kieranmv95


2 Answers

Probably options are not passed as expected.

Try this for uglify pipe:

.pipe(uglify({
    mangle: false,
    output: {
        beautify: true,
        comments: true
    }
})
like image 114
Zudwa Avatar answered Nov 10 '22 15:11

Zudwa


The options are available in the UglifyJS readme.

Example config to match what's in the question (+console):

.pipe(uglify({
    // https://github.com/mishoo/UglifyJS#mangle-options
    mangle: {
        toplevel: false
    },
    // https://github.com/mishoo/UglifyJS#compress-options
    compress: {
        drop_console: false
    },
    // https://github.com/mishoo/UglifyJS#output-options
    output: {
        beautify: true,
        comments: true,
        preamble: "/* Licensing info */"
    }
}))

For a production build you might want to consider using:

.pipe(uglify({
    // https://github.com/mishoo/UglifyJS#mangle-options
    mangle: {
        toplevel: true
    },
    // https://github.com/mishoo/UglifyJS#compress-options
    compress: {
        drop_console: true
    },
    // https://github.com/mishoo/UglifyJS#output-options
    output: {
        beautify: false,
        comments: false,
        preamble: "/* Licensing info */"
    }
}))
like image 27
slajma Avatar answered Nov 10 '22 14:11

slajma