我正在使用Grunt为 Javascript 库 (Widget) 编写构建系统,该库将连接、缩小和打包文件以进行分发。
在连接步骤中,我想将当前日期插入到具有grunt-contrib-concat进程选项的 JS 文件之一中,其中说明:
类型:布尔对象默认值:false
在连接之前将源文件作为模板处理。
- false - 不会进行任何处理。
 - true - 使用 grunt.template.process 默认值处理源文件。
 - 选项对象 - 使用 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。