【发布时间】:2015-05-09 22:08:55
【问题描述】:
我的 Gruntfile 中有一些用于 dist 文件夹的模板变量。我还想在 if else 语句中使用它们来调整一些任务的配置。
这里是我的 Gruntfile 的简短版本:
module.exports = function(grunt) {
grunt.initConfig({
// Variables
path: {
develop: 'dev/',
output: 'output/'
},
// Clean empty task
cleanempty: {
output: {
src: '<%= path.output %>**/*'
}
},
// Sync
sync: {
output: (function(){
console.log(grunt.config('path.output')); // Returns undefined
if(grunt.config('path.output') === 'output/') {
return {
// Config A
}
} else {
return {
// Config B
}
}
}())
}
不幸的是,我无法让它工作。 grunt.config('path.output') 返回未定义。 如何读取 Grunt 模板变量?更好的解决方案的提示,我也喜欢听。
【问题讨论】:
标签: javascript variables if-statement gruntjs