我正在使用 Grunt 编写构建系统用于连接、缩小和打包文件以供分发的 Javascript 库(Widget)。
在串联步骤中,我想将当前日期插入到一个 JS 文件中,进程选项为 grunt-contrib-concat ,其中指出:
Type: Boolean Object Default: false
Process source files as templates before concatenating.
- false - No processing will occur.
- true - Process source files using grunt.template.process defaults.
- options object - Process source files using grunt.template.process, using the specified options.
- function(src, filepath) - Process source files using the given function, called once for each file. The returned value will be used as source code.
(Default processing options are explained in the grunt.template.process documentation)
来自 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。
最佳答案
我认为,您在 grunt 符号之前缺少“=”,如下所示。
<%= grunt.template.today("yyyy-mm-dd") %>
关于javascript - Grunt -contrib-concat : how to use option "process",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16663539/