I am writing a build system using Grunt for a Javascript library (Widget) that will concatenate, minimize, and package files for distribution.
At the concatenation stage, I wanted to insert the current date into one of the JS files with the grunt-contrib-concat process parameter, where it says
Type: Boolean Object Default: false
Treat source files as templates before concatenation.
- false - Processing will fail.
- true - Process source files using the grunt.template.process parameters.
- options object - process source files using grunt.template.process using the specified parameters.
- function (src, filepath) - process the source files using the specified function, called once for each file. The return value will be used as source code.
(The default processing parameters are explained in grunt.template.process)
The concatenated part from Gruntfile.js:
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' } },
I installed the following line: Utility.js:
viewer.build_date = '<% grunt.template.today("yyyy-mm-dd") %>';
I expected the string to be replaced by the current date, but after concatenation it was empty.
viewer.build_date = '';
Is used
grunt version 0.4.1.
source share