$ npm install --save-dev json5-loader
You can use the loader either
json5-loader
in the module.loaders
object of the webpack configuration, orjson5!
prefix to the require statement.Suppose we have the following json5
file
// appData.json5 { env: 'production', passwordStregth: 'strong' }
// webpack.config.js module.exports = { entry: './index.js', output: { /* ... */ }, module: { loaders: [ { // make all files ending in .json5 use the `json5-loader` test: /\.json5$/, loader: 'json5-loader' } ] } }
// index.js var appConfig = require('./appData.json5') // or, in ES6 // import appConfig from './appData.json5' console.log(appConfig.env) // 'production'
var appConfig = require("json5-loader!./appData.json5") // returns the content as json parsed object console.log(appConfig.env) // 'production'
Don't forget to polyfill require if you want to use it in Node.js. See the webpack documentation.
MIT
© 2012–2016 Tobias Koppers
Licensed under the Creative Commons Attribution License 4.0.
https://webpack.js.org/loaders/json5-loader/