Output webpack stats in Gatsby

Step 1. Install webpack-stats-plugin

npm install --save-dev webpack-stats-plugin

or

yarn add --dev webpack-stats-plugin

Step 2. Configure

// gatsby-node.js
const { StatsWriterPlugin } = require('webpack-stats-plugin');

exports.onCreateWebpackConfig = ({ stage, plugins, actions }) => {
  if (stage === 'build-javascript') {
    actions.setWebpackConfig({
      plugins: [
        new StatsWriterPlugin(
          filename: 'stats.json',
          stats: {
            context: './src', // optional, will improve readability of the paths
            assets: true,
            entrypoints: true,
            chunks: true,
            modules: true
          }
        )
      ]
    });
  }
};



Need help?Contact us via email, Twitter, or Github!