6

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

Kieranmv95
  • 828
  • 4
  • 14
  • 31

2 Answers2

8

Probably options are not passed as expected.

Try this for uglify pipe:

.pipe(uglify({
    mangle: false,
    output: {
        beautify: true,
        comments: true
    }
})
Zudwa
  • 1,360
  • 10
  • 13
3

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 */"
    }
}))
slajma
  • 1,609
  • 15
  • 17