This is an adaptation of my answer to my own similar question.
You can copy JSON files through the file loader by adding the following code to your Webpack configuration:
module: { rules: [
There are two nuances here: 1) the file loader will only copy files that are imported / required somewhere in your code, and 2) the file loader emits the path to where the file was downloaded, and not the contents of the file itself.
So, to copy the JSON file, you first need to import it, for example:
const configFile = require('../config.json');
Since the file loader emits the path to the file where the loader was, configFile is set to "/config.json" .
Now the contents of the JSON file can be downloaded as you like, e.g. jsonfile
jsonfile.readFile(configFile, function(err, obj) { console.log(obj); });
or Angular HTTP package
http.get(configFile).map(res => res.json()).catch((error: any): any => {
alan
source share