Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate or import multiple json files in one, with webpack?

Tags:

json

webpack

I have multiple json files, and want to transform they to one simple json file and use json-loader to require it, like this:

import dictionary from './distFile.json';

Example:
file1.json
{a:"b"}
file2.json
{b:"a"}
distFile.json should be:
{a:"b",b:"a"}

How can I do that?

Or there is anyway to do something like that:
import dictionary from ['./file1.json','./file2.json']; ??

like image 982
thur Avatar asked Oct 29 '25 14:10

thur


1 Answers

Make a third file that you require both files in.

combined.js

import file1 from './file1.json';
import file2 from './file2.json';
export default { ...file1, ...file2 };

Then just import that file:

import combinedJson from './combined.js'
like image 53
Andy Ray Avatar answered Oct 31 '25 05:10

Andy Ray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!