json-key-reducer-loader

0.1.0 • Public • Published

json-key-reducer-loader

A Webpack loader that receives a JSON object and returns only the keys specified in the whitelist. The original use case comes from using truffle-soliidty-loader, that returns a json object. Not all keys are necessary for production, hence this module was created to remove unnecessary keys.

Installation

$ npm install --save-dev json-key-reducer-loader

Add the appropriate config to your loaders section of your Webpack 4 config and specify the whitelisted keys to return. It must be after the json-loader because webpack processes loaders right to left.

[
  {
    loader: 'json-loader'
  },
  {
    loader: 'json-key-reducer-loader',
    options: {
      whitelist: ['abi', 'compiler', 'network', 'schemaVersion', 'updatedAt']
    }
  }
]

Example

A full example that process solidity files.

{
  module: {
    rules: [
      {
        test: /\.sol/,
        use: [
          {
            loader: 'json-loader'
          },
          {
            loader: 'json-key-reducer-loader',
            options: {
              whitelist: ['abi', 'compiler', 'network', 'schemaVersion', 'updatedAt']
            }
          },
          {
            loader: 'truffle-solidity-loader',
            options: {
              network: 'ganache',
            }
          }
        ]
      }
    ]
  }
}

Loader options

  • whitelist: Keys to return

Readme

Keywords

none

Package Sidebar

Install

npm i json-key-reducer-loader

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

3.58 kB

Total Files

5

Last publish

Collaborators

  • sogoiii