Grunt:在任务配置中获取当前文件名

Grunt: Get current file name in task config

在配置我的任务时,我想使用当前文件名,该任务作为任务 options 对象中的模板变量。例如在 options['wrap-start'] 这里:

swig_compile: {
  temptarget: {
    options: {
      'wrap-start': 'var <%= CURRENT.FILE.NAME %> = function {', //I want the current file name as function name here 
      'wrap-end': '};'
    },
    files: {
      '<%= config.app %>/scripts/tempcompiled.js': ['<%= config.app %>/templates/*.swig']
    }
  }
}

根据grunt-swig-compile sources,没有这样的功能。 options['wrap-start'] 按原样连接到结果。

您可以 fork/copy grunt-swig-compile 来源并简单地用 [=15] 添加替换您的模式(例如 <%= file_name %>) =] 在 options['wrap-start'].