【发布时间】:2016-10-06 10:03:47
【问题描述】:
我有多个 JSON 文件,每个文件位于不同的路径中。 现在我正在尝试使用 "grunt-concat-json" 连接所有文件。
源 JSON 文件如下所示:
ExampleA.json
[ {
"configPath": "Example A"
} ]
ExampleB.json
[ {
"configPath": "Example B"
} ]
如何配置我的 GRUNT 任务以获得以下结果 JSON 文件:
[
{
"configPath": "Example A"
},
{
"configPath": "Example B"
} ]
我已经尝试过这个配置:
concat: {
json:
{
src: [
'pathA/ExampleA.json',
'pathB/ExampleB.json
],
dest: 'pathX/Merged.json',
options: {
separator: ','
}
}
},
使用此设置,我得到以下结果:
[
{
"configPath": "Example A"
}
],
[
{
"configPath": "Example B"
}
]
但我的结果 JSON 应该只有一个数组,我可以在我的代码中循环遍历,例如
configPaths.forEach(configPath) { ... }
【问题讨论】:
-
为此编写一个自定义的 grunt 任务应该不会太难。检查gruntjs.com/creating-tasks
标签: javascript json gruntjs grunt-contrib-concat