【发布时间】:2013-05-21 06:30:58
【问题描述】:
我正在使用 Grunt 为一个 Javascript 库 (Widget) 编写构建系统,该库将连接、缩小和打包文件以进行分发。
在连接步骤中,我想将当前日期插入其中一个带有grunt-contrib-concat 进程选项的 JS 文件,其中说明:
类型:布尔对象默认值:false
在连接之前将源文件作为模板处理。
- false - 不会进行任何处理。
- true - 使用 grunt.template.process 默认值处理源文件。
- options 对象 - 使用 grunt.template.process 处理源文件,使用指定的选项。
- function(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") %>';
我希望字符串会被当前日期替换,但连接后它是空的。
viewer.build_date = '';
使用 grunt 0.4.1 版本。
【问题讨论】:
标签: javascript node.js gruntjs