gruntjsgrunt-contrib-uglify

grunt-contrib-uglify keeps removing console.log


I'm new to Grunt, trying to get grunt-contrib-uglify to work and it appears to be working well, however it keeps removing, console.log('hello world') every time it runs.

I see a lot of mentions on how to get Uglify to remove console.log but nothing on actually keeping, which I assumed was the default.

Here's my uglify task:

uglify:{
    options: {
        compress: {
            unused: false,
            drop_console: false
        }
    },
    my_target: {
        files: {
            '_/js/script.js' : ['_/components/js/*.js']
        } //files
    } //my_target
}, //uglify

Here's my JavaScript file:

function test(){
    return 'hello there again once more';
    console.log('test');
}

It's keeping the return line, but not console.log.


Solution

  • function test(){
        return 'hello there again once more';
        console.log('test'); <- this is at wrong place
    }
    

    it should be before return

    function test(){
        console.log('test'); <- this SHOULD WORK
        return 'hello there again once more';
    
    }