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

时间:2016-01-06 12:50:34

标签: gruntjs

在配置我的任务时,我想使用当前文件名,任务在任务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']
    }
  }
}

1 个答案:

答案 0 :(得分:1)

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

您可以分叉/复制 grunt-swig-compile 来源,只需在<%= file_name %>中添加path.basename(filepath)替换您的模式(例如options['wrap-start']) }。

相关问题