问题描述
我正在编写一个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>"
});
1楼
Xavier Priour
1
已采纳
2015-08-02 19:59:32
在调用任务之前 ,Grunt会在其配置中使用<% %>
分隔符自动扩展模板,请参阅 。
因此,如果您想按原样获取模板字符串,一种解决方案是在配置字符串中然后在grunt.template.process
调用中使用自定义分隔符(例如[%
或{%
)(请参阅和 )