First of all you need to install json-loader:
npm i json-loader --save-dev
Then, there are two ways how you can use it:
-
In order to avoid adding
json-loaderin eachimportyou can add towebpack.configthis line:loaders: [ { test: /\.json$/, loader: 'json-loader' }, // other loaders ]Then import
jsonfiles like thisimport suburbs from '../suburbs.json'; -
Use
json-loaderdirectly in yourimport, as in your example:import suburbs from 'json!../suburbs.json';
Note:
In webpack 2.* instead of keyword loaders need to use rules.,
also webpack 2.* uses json-loader by default
*.json files are now supported without the json-loader. You may still use it. It’s not a breaking change.
v2.1.0-beta.28