简体   繁体   English

Grunt:模板化后,目标文件与源文件同名

[英]Grunt: Destination File Same Name as Source File After Templating

I'm trying to template all of the files in a directory and put the result in bin/admin directory such that the destination file has the same name as the source file. 我正在尝试对目录中的所有文件进行模板化,然后将结果放入bin/admin目录中,以便目标文件与源文件具有相同的名称。 However, it seems like the dest in data is the name of file and cannot be specified as a destination directory. 但是, datadest似乎是文件名,无法将其指定为目标目录。

module.exports = function(grunt) {
  grunt.initConfig({
    'template': {
      'process-html-template': {
        'options': {
          'data': {
            'api_url': 'My blog post'
          }
        },
        'files': {
          'bin/admin/': ['src/admin/*'] // <-- Here
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-template');
  grunt.registerTask('default', ['template']);
}

What can I do to template all of the files in src/ and put them in a destination folder with the same name as the source? 如何对src/所有文件进行模板化并将它们放置在与源文件同名的目标文件夹中? I tried to use bin/admin/* as the destination, but that just create a file with the filename * in bin/admin . 我试图使用bin/admin/*作为目的地,但这只是在bin/admin使用文件名*创建一个文件。 I want to avoid listing all of the files in the source directory manually. 我想避免手动列出源目录中的所有文件。

I figured it out. 我想到了。 It's an object with a src and dest attribute. 这是一个具有src和dest属性的对象。

module.exports = function(grunt) {
  grunt.initConfig({
    'template': {
      'process-html-template': {
        'options': {
          'data': {
            'api_url': 'My blog post'
          }
        },
        'files': [
          {
            expand:true,
            src: 'src/admin/*',
            dest: 'bin/admin/'
          }
        ]
      }
    }
  });

  grunt.loadNpmTasks('grunt-template');
  grunt.registerTask('default', ['template']);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM