A
A
Altereyo2020-11-09 18:30:28
JSON
Altereyo, 2020-11-09 18:30:28

Webpack - how to include json files in dist folder?

I searched on different sources about the json-loader, but from the Webpack 2 version, the loader should automatically work. With the npm run build command (building the project in dist), I managed to put information from json files into dist/main.js if I do import "./path/.json" in my src/index.js , but on the page the data from json is still not output.

How can I build the project in such a way that either data from json nested in dist/main.js is displayed on the page, or that webpack collects a separate db folder in dist and puts all json files there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-11-11
@Aetae

Webpack builds the application. If you import something, it is also collected. In particular, json is in the form of ready-made objects inside js files. If you need to include external json files after the build, you need to include them manually as usual: for example, using fetch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question