Skip to content

Latest commit

 

History

History
100 lines (84 loc) · 3.05 KB

README.md

File metadata and controls

100 lines (84 loc) · 3.05 KB

generate-json-webpack-plugin

Webpack plugin to generate a JSON file

NPM Download NPM Webpack Build Test

Getting Started

To begin, you'll need to install generate-json-webpack-plugin:

$ npm install @pp-spaces/generate-json-webpack-plugin --save-dev

Then add the plugin to your webpack config. For example:

webpack.config.js

const GenerateJsonPlugin = require('@pp-spaces/generate-json-webpack-plugin');

module.exports = {
  plugins: [new GenerateJsonPlugin({
      filename: 'manifest.json',
      value: {
        short_name: 'Weather',
        name: 'Weather: Do I need an umbrella?',
        description: 'Weather forecast information',
        icons: [
            {
                src: "/images/icons-192.png",
                type: "image/png",
                sizes: "192x192"
            },
            {
                src: "/images/icons-512.png",
                type: "image/png",
                sizes: "512x512"
            }
        ],
        start_url: "/?source=pwa",
        background_color: "#3367D6",
        display: "standalone",
        scope: "/",
        theme_color: "#3367D6"
      }
  })],
};

That will generate a file that looks like this:

manifest.json

{
  "short_name": "Weather",
  "name": "Weather: Do I need an umbrella?",
  "description": "Weather forecast information",
  "icons": [
    {
      "src": "/images/icons-192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "/images/icons-512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],
  "start_url": "/?source=pwa",
  "background_color": "#3367D6",
  "display": "standalone",
  "scope": "/",
  "theme_color": "#3367D6"
}

Options

Name Type Default Description
filename string manifest.json Output file name
source string [Optional] Path to an existing JS/JSON file to extend
value object {} Object to output or the properties you wish to modify
space number [Optional] Insert white space into the output JSON string for readability purposes

See tests/webpack.config.js for more.

License

MIT