Grunt: get current file name in task configuration

When setting up my task, I want to use the current file name in which the task works as a template variable in the object options. For example, in options['wrap-start']here:

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']
    }
  }
}
+4
source share
1 answer

According to grunt-swig-compile sources , there is no such function. options['wrap-start']combined with the result as is.

You can razvetkit / copy sources grunt-swig-compile and just add the replacement of your template (for example <%= file_name %>) using path.basename(filepath)in options['wrap-start'].

(Although the question is ancient, I hope the answer can be useful to someone)

0
source

Source: https://habr.com/ru/post/1623089/


All Articles