grunt-contrib-concat:如何使用选项“process”

我正在编写构build系统使用Grunt的Javascript库(Widget),将连接,缩小和打包文件分发。

在连接步骤中,我想将当前date插入到其中一个带有grunt-contrib-concat进程选项的JS文件中,在这里声明:

types:布尔对象默认值:false

在连接之前将源文件处理为模板。

  • 错误 – 不会进行处理。
  • 真 – 使用grunt.template.process默认处理源文件。
  • options对象 – 使用grunt.template.process处理源文件,使用指定的选项。
  • 函数(src,filepath) – 使用给定函数处理源文件,为每个文件调用一次。 返回的值将被用作源代码。

(默认处理选项在grunt.template.process文档中进行了说明)

来自Gruntfile.js的Concat部分:

concat: { options: { stripBanners: { block: true }, process: true, separator: '\n /* ----- */ \n', banner: '<%= meta.banner %>' }, dist: { src: ['src/Utility.js', 'src/MainClass.js', 'src/ViewClass.js', 'src/exif.js'], dest: 'build/Viewer.js' } }, 

我把下面的行放在Utility.js中:

 viewer.build_date = '<% grunt.template.today("yyyy-mm-dd") %>'; 

我期望这个string会被当前date取代,但是在连接之后它是空的。

 viewer.build_date = ''; 

使用grunt版本0.4.1。

我想,你在下面给出的咕噜声之前缺less'='。

 <%= grunt.template.today("yyyy-mm-dd") %>