javascript - grunt-html-build - 部分内的过程变量?

标签 javascript gruntjs grunt-html-build

我正在尝试使用模板构建一个页面,我在其中设置了一些参数。 在主模板中,这很完美:

<!-- build:process -->
    <%= variable %>
<!-- /build -->

正确替换为:

Value

为了只写一次标题,我将它放在一个单独的文件中并将其作为部分包含在内,效果很好。

<!--  build:section header -->
<!-- /build -->

但标题部分中的变量未被处理,部分模板按原样包含在内:

<!-- build:process -->
    <%= variable %>
<!-- /build -->

我在这里做错了什么? 我是否需要配置一些东西以便这些部分也得到处理?

谢谢

最佳答案

它看起来像是 grunt-html-build 模块中的错误。

我可以提出的唯一快速体面的解决方案是将 header 单独处理到临时文件:

var grunt = require('grunt')
grunt.loadNpmTasks('grunt-html-build')

grunt.initConfig({
    htmlbuild: {
        header: {
            src: 'head.html',
            dest: 'temp/head.html', // << write processed header to temp file
            options: {
                data: {
                    variable: "Value"
                }
            }
        },
        dist: {
            src: 'body.html',
            dest: 'build/',
            options: {
                sections: {
                    header: 'temp/head.html' // << read processed header
                }
            }
        }
    }
});

关于javascript - grunt-html-build - 部分内的过程变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38850095/

相关文章:

javascript - Stripe + Parse - 无法弄清楚 Javascript promise

gruntjs - 在 grunt (yeoman) 中禁用 livereload

javascript - Yeoman/Grunt 不编译 Compass

javascript - 使用 Yeoman 的生成器 webapp 配置 grunt-uncss

javascript - 咕噜JS : passing parameter to grunt-html-build

javascript - jquery 显示和隐藏 mouseout() 问题

未找到 Javascript 文件

javascript - Dayspan JS 让事件每隔一天发生一次