简体   繁体   中英

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.

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:

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)

Concat 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 put the following line the 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.template.today("yyyy-mm-dd") %> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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