如何在grunt中分析“<%= =>”?
告诉它包含文件时,很多grunt插件允许这个语法:
['<%= src_dir %>/common/**/*.js', '<%= src_dir %>/app/**/*.js']
要么
['<%= test_files.js %>']
有什么办法,我可以调用一些库,将parsing这些给我一个实际的输出数组? 或者这是直接build立在咕噜声? 我不知道什么条件谷歌甚至使这个显示。
谢谢
您正在寻找grunt.config.get
, grunt.config.process
或grunt.template.process
,这取决于您从哪里获取值以及如何处理它们。
grunt.config.get
从项目的Gruntconfiguration中获取一个值。 如果指定了
prop
,则返回该属性的值;如果该属性未定义,则返回null
。 如果没有指定prop
,则返回整个configuration对象的副本。 模板string将使用grunt.config.process
方法recursion处理。grunt.config.get([prop])
grunt.config.process
处理一个值,在Gruntconfiguration的上下文中recursion地扩展
<% %>
模板(通过grunt.template.process
方法),就像遇到它们一样。 这个方法是由grunt.config.get
自动调用,而不是由grunt.config.getRaw
。grunt.config.process(value)
[…]
grunt.template.process
处理Lo-Dash模板string。
template
参数将被recursion处理,直到没有更多的模板要处理。默认的数据对象是整个configuration对象,但是如果设置了
options.data
,则会使用该对象。 默认的模板分隔符是<% %>
但是如果将options.delimiters
设置为自定义分隔符名称(使用grunt.template.addDelimiters
设置),则将使用这些模板分隔符。grunt.template.process(template [, options])
在模板里,grunt对象被公开,所以你可以做一些事情,比如
<%= grunt.template.today('yyyy') %>
。 请注意,如果数据对象已经具有grunt
属性,则grunt API将无法在模板中访问。在这个例子中,
baz
属性被recursion地处理,直到没有更多的<% %>
模板被处理。var obj = { foo: 'c', bar: 'b<%= foo %>d', baz: 'a<%= bar %>e' }; grunt.template.process('<%= baz %>', {data: obj}) // 'abcde'