generate-json-webpack-plugin
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/generate-json-webpack-plugin package

2.0.0 • Public • Published

generate-json-webpack-plugin

npm version

webpack plugin to generate a custom JSON asset

Installation

npm install generate-json-webpack-plugin

Usage

// webpack.config.js
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
 
module.exports = {
  // ...
  plugins: [
    // ...
    new GenerateJsonPlugin('my-file.json', {
      foo: 'bar',
    }),
  ],
  // ...
};

This will create a file my-file.json in webpack's output directory, with contents:

{ "foo": "bar" }

You may optionally pass 'replacer' and 'space' arguments as the 3rd and 4th arguments, which will be passed to JSON.stringify to customize the JSON output:

new GenerateJsonPlugin(
  'my-file.json',
  { foo: 'bar', one: 'two' },
  (key, value) => {
    if (value === 'bar') {
      return 'baz';
    }
    return value;
  },
  2
);

my-file.json will contain:

{
  "foo": "baz",
  "one": "two"
}

Readme

Keywords

Package Sidebar

Install

npm i generate-json-webpack-plugin

Weekly Downloads

20,374

Version

2.0.0

License

MIT

Unpacked Size

5.43 kB

Total Files

11

Last publish

Collaborators

  • elliottsj