简体   繁体   English

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

[英]grunt-contrib-concat: how to use option “process”

I am writing build system using Grunt for a Javascript library (Widget) that would concatenate, minify and package the files for distribution. 我正在使用Grunt为Javascript库(Widget)编写构建系统,该库将连接,缩小和打包文件以进行分发。

In the concatenation step I wanted to insert current date into one of the JS files with process option of grunt-contrib-concat , where it is stated: 在连接步骤中,我想将当前日期插入到一个JS文件中,其中包含grunt-contrib-concat的进程选项,其中声明:

Type: Boolean Object Default: false 类型:Boolean对象默认值:false

Process source files as templates before concatenating. 在连接之前将源文件作为模板处理。

  • false - No processing will occur. false - 不会进行任何处理。
  • true - Process source files using grunt.template.process defaults. true - 使用grunt.template.process默认处理源文件。
  • options object - Process source files using grunt.template.process, using the specified options. options对象 - 使用指定选项使用grunt.template.process处理源文件。
  • function(src, filepath) - Process source files using the given function, called once for each file. function(src,filepath) - 使用给定函数处理源文件,为每个文件调用一次。 The returned value will be used as source code. 返回的值将用作源代码。

(Default processing options are explained in the grunt.template.process documentation) (默认处理选项在grunt.template.process文档中说明)

Concat part from Gruntfile.js: 来自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'
        }
    },

I put the following line the Utility.js: 我将以下行放在Utility.js中:

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

I expected that the string would get replaced by current date but it was empty after concatenation. 我预计字符串将被当前日期替换,但在连接后它是空的。

viewer.build_date = '';

grunt version 0.4.1 is used. 使用grunt版本0.4.1。

我想,你在下面给出的咕噜标志之前错过了'='。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM