I have many JavaScript modules that all of them export data and some other different functions. I want to merge all of these files into one file. Here are a few of them:
File1.js
export default {
data() {
return {
f1: 'something 1'
}
},
foo() {
// do something 1
}
}
File2.js
export default {
data() {
return {
f2: 'something 2'
}
},
bar() {
// do something 2
}
}
File3.js
export default {
data() {
return {
f3: 'something 3'
}
},
zoo() {
// do something 3
}
}
The expected result is like this:
Result.js
export default {
data() {
return {
f1: 'something 1',
f2: 'something 2',
f3: 'something 3'
}
},
foo() {
// do something 1
},
bar() {
// do something 2
},
zoo() {
// do something 3
}
}
I have seen a few articles that it could be more reliable if AST techniques are used. Here is a nice article: Manipulating AST with JavaScript
How can I do that with Babel?