@justinribeiro/rollup-plugin-asset-build-size-compare
v1.2.1
Published
Track asset build sizes and compare over time with Rollup.
Readme
rollup-plugin-asset-build-size-compare
Track asset build sizes and compare over time with Rollup. A opinionated and modified version of Wes's rollup-plugin-size, which was the rollup port of Jason's webpack size-plugin
Features
- Allows tracking build asset sizes, in either gzip, brotli, or no compression at all (don't ship your stuff that way!)
- Sets more sane compression defaults based on
- Allows setting custom compression targets to better match your web server compression settings (additional information as to why)
- Writes a file to disk for easy tracking of size over time (e.g., .rollup-plugin-asset-build-size-compare-data-${options.compression}.json)
- Color codes asset file sizes in out (red > 75kB, yellow > 40kB, cyan > 20kB, green < 20kB) to remind you that performance matters (and you should care)
- v1.2.0 Add
hashPatternoption to allow removal of hash from file name for easier compares.
Installation
Install justinribeiro@/rollup-plugin-asset-build-size-compare as a development dependency from NPM:
npm i -D justinribeiro@/rollup-plugin-asset-build-size-compare
# or
yarn add justinribeiro@/rollup-plugin-asset-build-size-compare --devQuick Start
Add the plugin to your rollup configuration:
// rollup.config.js
+ import size from '@justinribeiro/rollup-plugin-asset-build-size-compare';
plugins: [
+ size()
]For first time run, you'll get and initial set of sizes:
For additional runs, you'll get the change in those sizes (or no change in the example case as we did not edit anything):
Options
You can set various options within the plugin.
size({
compression: 'brotli',
compressionLevel: 6,
pattern: '**/*.{mjs,js,jsx,css,html}',
exclude: 'vendor/**',
filename: '.rollup-plugin-asset-build-size-compare-data-brotli.json',
writeFile: true,
columnWidth: 20,
hashPattern: '^(.*)(.{10})(\.[^.]+)$',
});| Option | Description | Default |
| ------------------------ | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| compression | The compression algorithm to run on the build assets. One of 'none', 'gzip', or 'brotli'. | 'gzip' |
| compressionLevel | Compression level to use for gzip (range: 1–9) or brotli (range: 1–11) | 6 |
| pattern | Minimatch pattern to include files from the build assets. | '**/*.{mjs,js,jsx,css,html}' |
| exclude | Minimatch pattern to exclude files from the build assets. | undefined |
| filename | The file name to write asset size data to disk. Supports template string ${options.compression}. | '.rollup-plugin-asset-build-size-compare-data-${options.compression}.json' |
| writeFile | Whether to write the asset size data file to disk. | true |
| columnWidth | The number of characters used for column width in console output. | 20 |
| hashPattern | A three group match pattern (filename, hash, extension) to remove hashes from build files | `` |
