【问题标题】:Grunt: Destination File Same Name as Source File After TemplatingGrunt:模板化后目标文件与源文件同名
【发布时间】:2014-10-03 23:22:14
【问题描述】:

我正在尝试对一个目录中的所有文件进行模板化,并将结果放在bin/admin 目录中,以便目标文件与源文件具有相同的名称。但是,data 中的dest 似乎是文件名,不能指定为目标目录。

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']);
}

我可以做些什么来模板化src/ 中的所有文件并将它们放在与源同名的目标文件夹中?我尝试使用bin/admin/* 作为目标,但这只是在bin/admin 中创建一个文件名为* 的文件。我想避免手动列出源目录中的所有文件。

【问题讨论】:

    标签: javascript gruntjs npm


    【解决方案1】:

    我想通了。它是一个具有 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']);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多