2014-02-18 29 views
2

我正在使用Grunt和组装来建立我的HTML网页的静态网站,我想缩小我的HTML。咕噜声/汇编 - 输出html缩小

所以,我会假设组装运行句柄模板对数据集的插件将有一个缩小选项。

汇编文档中没有提及它; http://assemble.io/docs/Options.html#configuration-options

但有一个提到,暗示在句柄,帮手,缩小文档; https://www.npmjs.org/package/handlebars-helper-minify#-assemble-task-options - 但这没有效果。

我不能在互联网上找到任何东西,当然这是一种较为常见的请求......

grunt.initConfig({ 
    assemble: { 
       options: { 
        assets: '../source', 
        data: ['package.json','data/*.{json,yml}'], 
        partials: 'templates/modules/*.hbs', 
        ext: '.html', 
        helpers: 'templates/helpers/*.js', 
        layout: 'templates/layout/master.hbs', 
        removeHbsWhitespace: true, 
        minify: { 
         removeAttributeQuotes: true, 
         collapseWhitespace: true 
        } 
       }, 
       dev: { 
        options: { 
         production: false 
        }, 
        files: [{ 
         expand: true, 
         cwd: 'templates/pages', 
         src: ['*.hbs'], 
         dest: '../source' 
        }] 
       } 
    } 
}); 

回答

2

你需要明确注册{{缩小}}帮手在Gruntfile

helpers: ['handlebars-helper-minify', 'templates/helpers/*.js'] 

或者,请尝试在项目的package.json中将handlebars-helper-minify模块添加到devDependencieskeywords

{ 
    "devDependencies": { 
    "handlebars-helper-minify": "~0.1.1" 
    }, 
    "keywords": [ 
    "handlebars-helper-minify" 
    ] 
} 

在你master.hbs布局,{{minify}}包装它,例如:

{{#minify}} 
    {{> header }} 
    {{> body }} 
    {{> footer }} 
{{/minify}} 
2

退房grunt-prettify通过组装的作者之一。除了该项目的README使用它的一个例子是here在此Gruntfile:

/** 
* Beautify generated HTML to make diffs easier 
*/ 
prettify: { 
    tests: { 
     options: {ocd: true}, 
     files: [ 
      {expand: true, cwd: 'test/actual', src: ['**/*.html'], dest: 'test/actual/', ext: '.html'} 
     ] 
    } 
}, 

好运