使用grunt-replace(或其他替代方法)我需要读取外部JSON文件并使用它来匹配密钥并替换为值。
示例,这有效:
replace: {
dist: {
options: {
patterns: [
{
json: {
"hello": "goodbye",
}
}
]
},
files: [
{expand: true, flatten: true, src: ['index.html'], dest: 'production/'}
]
}
},
然而,我需要它做一些事情:
assets: '<%= grunt.file.read("temp/assets.json") %>',
replace: {
dist: {
options: {
patterns: [
{
json: {
include: '<%= assets %>'
}
}
]
},
files: [
{expand: true, flatten: true, src: ['index.html'], dest: 'production/'}
]
}
},
答案 0 :(得分:0)
使用grunt.file.readJSON()
(参考:Grunt docs)
assets: grunt.file.readJSON('temp/assets.json');
replace: {
dist: {
options: {
patterns: [
{
json: {
include: '<%= assets %>'
}
}
]
},
files: [
{expand: true, flatten: true, src: ['index.html'], dest: 'production/'}
]
}
}