使用grunt.js生成dynamic文件名

是否有可能在内置的grunt任务(例如concatmin )之外生成dynamic文件名? 我尝试使用像<config:concat.dist.dest><%= dirs.dest %>之类的内容,如文档中所述。 但是这不会被解释/编译,只是写出string。

更新:这就是我基于jakub.g的答案尝试。 我的grunt.js看起来像这样:

 // ... grunt file contents jquery: { exclude: [], version: '1.8.3', dest: '../dist/js/jquery-' + grunt.task.directive('<config:jquery.version>') + '.js', minify: false }, // ... even more grunt file contents 

grunt.task.directive('<config:jquery.version>')返回null 。 所以文件名被命名为jquery-null.js

然后我尝试grunt.template.process('<%= grunt.jquery.version %>')grunt.config.process('<%= grunt.jquery.version %>') ,但没有一个工作。

这在内置任务中隐藏在Grunt魔术的隐藏之下,实际上没有足够清晰的logging。

你需要使用像grunt.task.directive(dest)来评估<config:..>类的东西。 在一个自定义的任务。

对于<%= foo %> ,看看Grunt模板 。

此外,像***这样的通配符,默认情况下也不会扩展,如果您想在自定义任务中使用它们,可以使用grunt.file.expandFiles()