我有以下Grunt任务(简化):
rev: {
files: {
src: ['dist/**/*.{js,css}']
}
},
processhtml: {
dev: {
options: {
data: {
appJs: grunt.file.expand('dist/**/*.js')
}
},
files: {
'dist/index.html': 'app/index.html'
}
}
}
Run Code Online (Sandbox Code Playgroud)
该grunt-rev任务首先运行,它采用常规JS并在文件名前加上哈希码.然后grunt-processhtml运行任务,在这种情况下,我想获取生成的所有JS文件名grunt-rev,并将它们作为自定义数据传递.
这段代码的问题是,grunt.file.expand当gruntfile首次执行时,该方法似乎是急切执行的,而不是在processhtml任务运行时,所以这意味着我得到的文件列表与grunt.file.expand我预期的不同,因为它不需要考虑到grunt-rev任务的结果.
有没有办法在实际运行任务时强制对值进行延迟评估?
我将定义一个自定义任务,该任务将(当被调用时)为processhtml任务设置选项并运行它.
有点像:
grunt.task.registerTask('foo', 'My foo task.', function() {
grunt.config("processhtml.dev", {
options: {
data: {
appJsgrunt: file.expand('dist/**/*.js')
}
}
});
grunt.task.run("processhtml.dev");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
284 次 |
| 最近记录: |