json-flat-pack-loader
v0.0.1
Published
A json loader that flattens along the way.
Downloads
2
Readme
JSON Flat Pack Loader
This webpack loader flattens out JSON into '.' delimited key value pairs before it is written to a file. This is useful for when you would like to store structured data but a library requires flattend key value pairs such as react-intl.
Before
{
"buttons": {
"sign-in": "Sign In",
"go-back": "Go Back"
},
"errors": {
"account-not-found": "no account was not found matching the email and password provided"
}
}
After
{
"buttons.sign-in": "Sign In",
"buttons.go-back": "Go Back",
"errors.account-not-found": "no account was not found matching the email and password provided"
}
Install
npm install --save-dev json-flat-pack-loader
Usage
Use the loader either via your webpack config, CLI or inline.
Webpack config
webpack.config.js
module.exports = {
module: {
rules: [
{ test: /\.json$/, use: 'json-flat-pack-loader' }
]
}
};
In your application
import json from './file.json'
CLI
webpack --module-bind 'json=json-flat-pack-loader'
In your application
import json from 'file.json';
Inline
In your application
import json from 'json-flat-pack-loader!./file.json';