当前位置: 代码迷 >> JavaScript >> grunt.registerMultiTask()从字符串中去除变量
  详细解决方案

grunt.registerMultiTask()从字符串中去除变量

热度:143   发布时间:2023-06-05 11:57:08.0

我正在编写一个grunt插件,它必须处理任务中定义的模板。 我的问题是,即使在grunt.template.process()之前,模板中的变量也被剥离了。

该任务的选项如下所示:

wrap: {
    html: {
        footer: '<script>require(["<%= filename %>"])</script>',
        src: ['templates/*.*'],
        dest: 'new_templates'
    }
}

任务本身的简化形式如下所示:

grunt.registerMultiTask('wrap', 'Blah-blah', function() {
    grunt.log.writeln(this.data.footer); // outputs "<script>require([""]); </script>"
});

调用任务之前 ,Grunt会在其配置中使用<% %>分隔符自动扩展模板,请参阅 。

因此,如果您想按原样获取模板字符串,一种解决方案是在配置字符串中然后在grunt.template.process调用中使用自定义分隔符(例如[%{% )(请参阅和 )