Newton's Programmatic Measurements
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

json5-loader

1.0.1 • Public • Published

npm deps test coverage chat

JSON5 Loader

Webpack loader for parsing json5 files into JavaScript objects.

Install

$ npm install --save-dev json5-loader

Usage

You can use the loader either

  • by configuring the json5-loader in the module.loaders object of the webpack configuration, or
  • by directly using the json5! prefix to the require statement.

Suppose we have the following json5 file

// appData.json5
{
  env: 'production',
  passwordStregth: 'strong'
}

Usage with preconfigured loader

// 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'

Usage with require statement loader prefix

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.

Maintainers


Tobias Koppers

PatrickJS

Michael Ferris

Keith McKnight

Radu Brehar

Kent C. Dodds

Steve Lacy

LICENSE

MIT

Keywords

none

install

npm i json5-loader

Downloadsweekly downloads

4,277

version

1.0.1

license

MIT

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability