Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs 如何使用grunt配置';什么是模板字符串?_Gruntjs - Fatal编程技术网

Gruntjs 如何使用grunt配置';什么是模板字符串?

Gruntjs 如何使用grunt配置';什么是模板字符串?,gruntjs,Gruntjs,我在模块顶部设置模板。在我的GrunFile中导出: // Self calling so we get a value. // Expects only a single schema in the schema folder. grunt.config.set('schemaPath', function() { console.log(grunt.file.expand('schema/*.json')[0]); return grunt.file.expand('sche

我在
模块顶部设置模板。在我的GrunFile中导出

// Self calling so we get a value.
// Expects only a single schema in the schema folder.
grunt.config.set('schemaPath', function() {
    console.log(grunt.file.expand('schema/*.json')[0]);
    return grunt.file.expand('schema/*.json')[0];
}());

console.log(grunt.config.get('schemaPath'));
稍后,在配置命令时,我希望使用如下模板字符串:

stripJsonComments: {
  currentSchema: {
    files: {
      'build/<%= schemaPath %>': '<%= schemaPath %>'
    }
  }
}
stripJsonComments:{
当前模式:{
档案:{
“build/”:“”
}
}
}

但是我遇到了一个错误:
处理模板时出错(无法读取未定义的属性'src')。
在调查之后,似乎模板字符串没有展开,而是被删除。

您不能将模板用作属性名,它们不会得到处理。所以
“build/”:“
不起作用

我建议研究的另一个变体,在其中明确定义
src
dest
属性,然后使用值模板。
如果要查找多个src-dest文件映射,可以使用。它看起来像这样:

module.exports = function(grunt) {

  grunt.initConfig({
    concat: {
      main: {
        files: [
          {src: ['<%= file1 %>', '<%= file2 %>'], dest: '<%= destPath %>'},
        ]
      },
    }    
  });


  grunt.config.set('file1', 'foo.js');
  grunt.config.set('file2', 'bar.js');
  grunt.config.set('destPath', 'dest/baz.js');

  grunt.loadNpmTasks('grunt-contrib-concat');

  grunt.registerTask('default', ['concat']);

};
module.exports=函数(grunt){
grunt.initConfig({
康卡特:{
主要内容:{
档案:[
{src:['',],dest:'},
]
},
}    
});
grunt.config.set('file1','foo.js');
grunt.config.set('file2','bar.js');
grunt.config.set('destPath','dest/baz.js');
grunt.loadNpmTasks(“grunt-contrib-concat”);
registerTask('default',['concat']);
};