2017-03-09 56 views
1

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

我看到很多提及如何让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

回答

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'; 

} 
+1

哇之前,感谢指出了这一点。完全错过了。现在正在工作。 – Richard

+0

太棒了!很高兴帮助,如果有帮助请接受答案。干杯 – Danish

1

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

console.log声明是之后return声明,所以永远不会执行。该功能已停止在该点。尝试将console.log移至return声明之前。