One of the problems I came across recently whilst using Webpack was the fact that once yarn build -p had been run all the assets are given hashed filenames, such as:

data.8687234d3.json

But the JavaScript I had written was looking for and trying to load data from data.json. Webpack takes care of all the typical assets such as the main JavaScript and CSS files, so I needed to amend how I was calling the data.json file so that the Webpack assets file worked.

At the top of the file that was calling data.json I added the following line which imports the JSON into a variable called jsonData. And because the data is now included via the import rule, Webpacks assets file resolved the naming.

import * as jsonData from '../json/data.json'; 

Leave a Reply

Your email address will not be published. Required fields are marked *