A webpack loader that transforms a JSON object with a user-defined function
- Add to dev dependencies:
npm i -D json-transform-loader
- Configure:
// webpack.config.js
module: {
rules: [
{
test: /\.json$/,
use: [
{
loader: 'json-transform-loader',
options: {
transformFn: jsonObject => {
// Do something with the json object, e.g.:
const transformed = { ...jsonObject, answer: 42 };
return transformed;
}
}
}
]
}
]
}