Note that if a specified property name contains a .
dot, it must be escaped with a literal backslash, eg.'concat.dist/built\\.js'
. If an array of parts is specified, Grunt will handle the escaping internally with the grunt.config.escape
method.
grunt.config
从项目的 Grunt 配置中获取或者设置一个值。这个方法作为其他方法的别名;如果传递两个参数,grunt.config.set
被调用,另一方面grunt.config.get
也被调用。Get or set a value from the project's grunt configuration. This method serves as an alias to other methods; if two arguments are passed, grunt.config.set
is called, otherwise grunt.config.get
is called.
grunt.config([prop [, value]])
grunt.config.get
Get a value from the project's Grunt configuration. If prop
is specified, that property's value is returned, ornull
if that property is not defined. If prop
isn't specified, a copy of the entire config object is returned. Templates strings will be recursively processed using the grunt.config.process
method.
grunt.config.get([prop])
grunt.config.process
Process a value, recursively expanding <% %>
templates (via the grunt.template.process
method) in the context of the Grunt config, as they are encountered. this method is called automatically bygrunt.config.get
but not by grunt.config.getRaw
.
grunt.config.process(value)
If any retrieved value is entirely a single '<%= foo %>'
or '<%= foo.bar %>'
template string, and the specified foo
or foo.bar
property is a non-string (and not null
or undefined
) value, it will be expanded to the actual value. That, combined with grunt's task system automatically flattening arrays, can be extremely useful.
grunt.config.getRaw
Get a raw value from the project's Grunt configuration, without processing <% %>
template strings. Ifprop
is specified, that property's value is returned, or null
if that property is not defined. If prop
isn't specified, a copy of the entire config object is returned.
grunt.config.getRaw([prop])
grunt.config.set
给当前项目的 Grunt 配置中的某个属性设置一个值。
grunt.config.set(prop, value)
注意,任何 <% %>
模板字符串只会在取到配置数据后才被处理。
grunt.config.escape
忽略给定的propString
中的.
点号。这应该用于包含点号的属性名。Escape .
dots in the givenpropString
. This should be used for property names that contain dots.
grunt.config.escape(propString)
grunt.config.merge
Added in 0.4.5
Recursively merges properties of the specified configObject
into the current project configuration.
grunt.config.merge(configObject)
You can use this method to append configuration options, targets, etc., to already defined tasks, for example:
grunt.config.merge({
watch: {
files: ["path/to/files"],
tasks: ["task"]
}
});
Requiring Config Data
注意,下面列出的方法都可以在task内部通过 this
对象访问,访问形式为 this.requiresConfig
。
grunt.config.requires
如果需要的配置属性有一个或多个不存在、值为null
或 undefined
,当前task将失败。此方法可以指定一个或多个字符串、配置属性数组作为参数。
grunt.config.requires(prop [, prop [, ...]])
此方法在task内部以 this.requiresConfig
形式调用。
标签:Grunt
相关阅读 >>
更多相关阅读请进入《Grunt》频道 >>
Vue.js 设计与实现 基于Vue.js 3 深入解析Vue.js 设计细节
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者