Gruntjs改变下划线模板分隔符
我试图生成一个JSP页面,由于JSP使用的模板分隔符与下划线使用的模板分隔符相同。
看文档 – > https://github.com/gruntjs/grunt/wiki/grunt.template#wiki-grunt-template-setDelimiters我可以看到他们有一个function
grunt.template.addDelimiters(name, opener, closer)
两个问题:
- 我在哪里可以调用该function?
- 我可以更改分隔符只为一个
grunt.template.process()
(我有多个,并为其他非.jsp模板,默认的分隔符是好的)?
任何帮助表示赞赏。 谢谢。
从grunt.template.process文档:
默认的模板分隔符是<%%>,但如果options.delimiters设置为自定义分隔符名称,则将使用这些模板分隔符。
这基本上意味着你可以用你之前添加的分隔符的名字来调用grunt.template.process。
例如,如果你想在一个处理步骤中使用方括号作为分隔符,
// first add the new delimiters which you want to use grunt.template.addDelimiters('square-brackets', '[', ']'); // and use it grunt.template.process(template, {delimiters: 'square-brackets'}); // and use it with the default delimiters (named 'config') grunt.template.process(template);
我有完全相同的问题。 JSP使用<%=%>标签replacegrunt也使用的标签。 添加了一行来覆盖“ https://github.com/gruntjs/grunt/blob/master/lib/grunt/template.js ”中应用的默认设置
这对我工作:
// REPLACE the default 'config' delimiters grunt.template.addDelimiters('config', '{%', '%}'); grunt.initConfig( { .... });
分隔符名称“config”必须完全匹配。