在Grunt(Yeoman)中禁用缩小

时间:2015-11-15 20:25:52

标签: javascript gruntjs minify grunt-contrib-uglify

我最近开始通过Yeoman使用GruntJS,我喜欢Javascript缩小的想法,但它在开发过程中遇到了困难。我试图在Gruntfile中以不同的组合禁用uglify,usemin等,但是一切似乎都依赖于另一件事并打破了这个过程。有没有简单的方法来禁用缩小?我正在使用Yeoman提供的最新版本的Grunt,我发现旧的解决方案具有与Yeoman不同的Gruntfile设置。

这是我的Gruntfile:

// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
  options: {
    dest: '<%= config.dist %>'
  },
  html: '<%= config.app %>/index.html'
},

http://hastebin.com/gicabukojo.js

2 个答案:

答案 0 :(得分:2)

我需要调整usemin flow:选项:

根据yeoman grunt usemin's fine manual,默认flow:

{ steps: { js: ['concat', 'uglify'], css: ['concat', 'cssmin'] }, post: {} }

以下是gist of how I modified我的yo webapp Gruntfile.js从流中移除uglify

答案 1 :(得分:1)

此评论块位于您的Gruntfile中:

function Keep-Pinging
{
    param([string]$Hostname)

    ping.exe -t $Hostname |ForEach-Object {
        $Color = if($_ -like "Request timed out*") {
            "Red"
        } elseif($_ -like "Reply from*") {
            "Green"
        } else {
            "Gray"
        }
        Write-Host $_ -ForegroundColor $Color
    }
}

基于此,从index.html文件中删除// By default, your `index.html`'s <!-- Usemin block --> will take care // of minification. These next options are pre-configured if you do not // wish to use the Usemin blocks. 会阻止<!-- Usemin block --> grunt任务缩小您的javascript。

此外,您可以编辑useminPrepare任务,通过将uglify添加到文件扩展名来创建新文件以覆盖您的开发文件:

.min