javascript - Grunt -contrib-concat : how to use option "process"

标签 javascript node.js gruntjs

我正在使用 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/

相关文章:

deployment - 部署/构建/制作网络应用程序的基础知识是什么?

node.js - 构建 Knockout.js 时出现 fatal error

javascript - Grunt 文件输出静态资源指向指定的 URL

shell - 在 Grunt 上压缩为 tar.gz

javascript - 运行nodejs/expressjs中的多个函数

node.js - 如何将我的 Node winston JSON 输出更改为单行

javascript - 捕获所有 l 字母并排除单词

Javascript Div的宽度根据屏幕宽度

javascript - slim 的过渡 : How to Make Incoming "in" Dynamic Svelte Component transition Wait for Outgoing "out" Svelte Component to Finish

javascript - 微前端 - 方法