grunt-contrib-uglify不断删除console.log

时间:2017-03-09 22:39:46

标签: gruntjs grunt-contrib-uglify

我是Grunt的新手,试图让grunt-contrib-uglify正常工作,但它似乎运行良好,但每次运行时都会一直移除console.log('hello world')

我看到很多关于如何让Uglify删除console.log但没有提及实际保留的内容,我认为这是默认设置。

这是我的uglify任务:

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

这是我的JavaScript文件:

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

保持return行,但不是console.log

2 个答案:

答案 0 :(得分:1)

你确定它实际上是删除它吗?只是你没有在控制台中看到日志吗?

console.log语句在 return语句之后是,因此永远不会被执行。该功能已停止。尝试将console.log移至return语句之前。

答案 1 :(得分:1)

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

应该在返回之前

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

}