grunt-concat分隔符选项?

时间:2013-04-01 19:12:03

标签: javascript configuration build concatenation gruntjs

如何在此场景中指定分隔符:
我用这种方式用grunt-concat连接我的文件:

concat: {
  options: {
    banner: '<%= banner %>',
    separator: ""
  },
  dist: {
    files:{
      '<%= distdir %>/public/scripts/ieditor.js': [
        'public/scripts/ieditor/vars.js',
        'public/scripts/ieditor/controllers/*.js',
        'public/scripts/ieditor/directives/*.js',
        'public/scripts/ieditor/app.js',
        'public/scripts/ieditor/services/*.js',
        'public/scripts/ieditor/filters/*.js'
      ],
      '<%= distdir %>/public/scripts/dashboard.js': [
        'public/scripts/dashboard/vars.js',
        'public/scripts/dashboard/controllers/*.js',
        'public/scripts/dashboard/directives/*.js',
        'public/scripts/dashboard/app.js',
        'public/scripts/dashboard/services/*.js',
        'public/scripts/dashboard/filters/*.js'
      ]
    }
  }
}

我想要的是在连接CSS文件时将最终结果映射到原始文件,如罗盘 例如:

//####public/scripts/ieditor/vars.js###############
content of public/scripts/ieditor/vars.js
//####public/scripts/ieditor/controllers/a.js######
content of public/scripts/ieditor/controllers/a.js
//####public/scripts/ieditor/controllers/b.js######
content of public/scripts/ieditor/controllers/b.js
.....

那么关于当前连接文件的名称是什么,所以我可以在选项区域做这样的事情:

  options: {
    banner: '<%= banner %>',
    separator: "<%= current_file_name %>"
  },

提前致谢。

1 个答案:

答案 0 :(得分:20)

process option, specified as a function,是你的朋友:

concat: {
  options: {
    process: function(src, filepath) {
      return '//####' + filepath + '\n' + src;
    }
  }
},
...