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