2014-02-28 155 views
1

我有以下咕噜任务(简体):延迟计算咕噜任务选项

rev: { 
    files: { 
     src: ['dist/**/*.{js,css}'] 
    } 
}, 

processhtml: { 
    dev: { 
     options: { 
      data: { 
       appJs: grunt.file.expand('dist/**/*.js') 
      } 
     }, 
     files: { 
      'dist/index.html': 'app/index.html' 
     } 
    } 
} 

grunt-rev任务首先运行,这需要定期JS,并预置的哈希码的文件名。然后运行grunt-processhtml任务,对于这种情况我想获取由grunt-rev生成的所有JS文件名,并将它们作为自定义数据传递。

这段代码的问题是,它似乎在首次执行gruntfile不是processhtml任务运行时急切地执行grunt.file.expand方法,并且,所以这意味着我得到的文件不同的列表,从grunt.file.expand比我预期,因为它不考虑grunt-rev任务的结果。

当任务实际运行时,是否有办法强制延迟评估值?

+0

可能会有帮助:http://stackoverflow.com/questions/15735485/how-to-make-grunt-wait-for-a-task-to-finish -before-running-another –

+0

您可能会觉得这很有用:http://stackoverflow.com/questions/28847471/grunt-how-to-build-the-files-object-dynamically/29244332#29244332 – almeidap

回答

5

我会定义一个自定义任务,它会(当被调用时)为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"); 
}); 
+0

我认为任务名称必须如“processhtml:dev”,而不是点符号。 –