ag-grid is proud to partner with webpack

json5-loader

[![npm][npm]][npm-url] [![node][node]][node-url] [![deps][deps]][deps-url] [![tests][tests]][tests-url] [![cover][cover]][cover-url] [![chat][chat]][chat-url] [![size][size]][size-url]

A webpack loader for parsing json5 files into JavaScript objects.

Getting Started

To begin, you'll need to install json5-loader:

$ npm install json5-loader --save-dev

You can use the loader either:

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

Suppose we have the following json5 file:

file.json5

// file.json5
{
  env: 'production',
  passwordStrength: 'strong',
}

Usage with preconfigured rule

webpack.config.js

// webpack.config.js
module.exports = {
  entry: './index.js',
  output: {
    /* ... */
  },
  module: {
    rules: [
      {
        // make all files ending in .json5 use the `json5-loader`
        test: /\.json5$/,
        use: 'json5-loader',
        type: 'javascript/auto'
      },
    ],
  },
};
// 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.

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT