[英]How do I parse '<%= =>' in grunt?
A lot of grunt plugins allow for this syntax when telling it to include files: 当告诉它包括文件时,很多咕unt的插件都允许这种语法:
['<%= src_dir %>/common/**/*.js', '<%= src_dir %>/app/**/*.js']
or 要么
['<%= test_files.js %>']
Is there any way I can call into some library that will parse these and give me an array of the actual output? 有什么方法可以调用一些库来解析这些库并为我提供实际输出的数组? Or is this built directly into grunt?
还是直接内置于咕unt声中? I am not sure what terms to google to even make this show up.
我不确定要用Google的什么字词才能显示出来。
Thanks 谢谢
You are either looking for grunt.config.get
, grunt.config.process
or grunt.template.process
, depending on where you are getting the values from and how you want to process them. 您正在寻找
grunt.config.get
, grunt.config.process
或grunt.template.process
,具体取决于您从何处获取值以及如何处理它们。
grunt.config.get
grunt.config.get
Get a value from the project's Grunt configuration.
从项目的Grunt配置中获取值。 If
prop
is specified, that property's value is returned, ornull
if that property is not defined.如果指定了
prop
,则返回该属性的值;如果未定义该属性,则返回null
。 Ifprop
isn't specified, a copy of the entire config object is returned.如果未指定
prop
,则返回整个配置对象的副本。 Templates strings will be recursively processed using thegrunt.config.process
method.模板字符串将使用
grunt.config.process
方法进行递归处理。grunt.config.get([prop])
grunt.config.process
grunt.config.process
Process a value, recursively expanding
<% %>
templates (via thegrunt.template.process
method) in the context of the Grunt config, as they are encountered.处理一个值,在遇到Grunt配置时,递归扩展
<% %>
模板(通过grunt.template.process
方法)。 this method is called automatically bygrunt.config.get
but not bygrunt.config.getRaw
.此方法由
grunt.config.get
自动调用,但不会由grunt.config.getRaw
。grunt.config.process(value)
[...]
[...]
grunt.template.process
grunt.template.process
Process a Lo-Dash template string.
处理Lo-Dash模板字符串。 The
template
argument will be processed recursively until there are no more templates to process.template
参数将递归处理,直到没有更多模板可处理为止。The default data object is the entire config object, but if
options.data
is set, that object will be used instead.默认的数据对象是整个配置对象,但是如果设置了
options.data
,则将使用该对象。 The default template delimiters are<% %>
but ifoptions.delimiters
is set to a custom delimiter name (set withgrunt.template.addDelimiters
), those template delimiters will be used instead.默认模板定界符为
<% %>
但是如果options.delimiters
设置为自定义定界符名称(使用grunt.template.addDelimiters
设置),则将使用这些模板定界符。grunt.template.process(template [, options])
Inside templates, the grunt object is exposed so that you can do things like
<%= grunt.template.today('yyyy') %>
.在模板内部,grunt对象是公开的,因此您可以执行
<%= grunt.template.today('yyyy') %>
。 Note that if the data object already has agrunt
property, the grunt API will not be accessible in templates.请注意,如果数据对象已经具有
grunt
属性,则在模板中将无法访问grunt API。In this example, the
baz
property is processed recursively until there are no more<% %>
templates to process.在此示例中,递归处理
baz
属性,直到没有更多要处理的<% %>
模板为止。var obj = { foo: 'c', bar: 'b<%= foo %>d', baz: 'a<%= bar %>e' }; grunt.template.process('<%= baz %>', {data: obj}) // 'abcde'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.