12

如何在这种情况下指定分隔符:
我以这种方式将我的文件与 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 %>"
  },

提前致谢。

4

1 回答 1

20

process指定为 function的选项是您的朋友:

concat: {
  options: {
    process: function(src, filepath) {
      return '//####' + filepath + '\n' + src;
    }
  }
},
...
于 2013-09-12T15:29:59.227 回答