1.0.3 • Published 6 years ago

gatsby-plugin-size-analyzer v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

gatsby-plugin-size-analyzer

Extension of webpack-bundle-size-analyzer by Robert Knight for Gatsby

Installation

yarn add gatsby-plugin-size-analyzer

How to use

  1. Include the plugin in your gatsby-config.js file.
  2. gatsby build to find "size-analyzer.txt" inside the project folder.
// in gatsby-config.js
plugins: [
  `gatsby-plugin-size-analyzer`
];

Options

Decide the name and location of your reports folder like so:

// in gatsby-config.js
plugins: [
  {
    resolve: `gatsby-plugin-size-analyzer`,
    options: {
      path: ['myreports/gatsby']
    },
  },
];

⚠️ The folder named "gatsby" needs to exist before you build your project!

Important Note About Minified Code

If you minify/compress your code using the approach recommended in the Webpack documentation, which is to use the UglifyJS plugin, be aware that this tool will report the sizes of modules before they are minified. This is because the statistics generated by webpack --json do not take account of plugins that operate on the bundle as a whole.

Knowing the sizes of dependencies before they are minified can still be useful to get an idea of how much different dependencies are responsible for size of your minified bundle, but be aware that it can be misleading. This is because some libraries compress better than others.

If instead you minify modules in your bundle individually using a loader (eg. the UglifyJS loader), the stats output by webpack --json will show minified sizes. If you want to get a better idea of the sizes of different dependencies after they are minified, you can temporarily remove the UglifyJS plugin and replace it with the UglifyJS loader instead before running webpack --json | webpack-bundle-size-analyzer.

The reason that using a plugin, rather than a loader, is the recommended approach in Webpack is that compression is better if applied to the whole bundle rather than to individual source files one at a time.

– taken from the readme of webpack-bundle-size-analyzer