UNPKG

gatsby-plugin-purgecss

Version:

Gatsby plugin for purgecss. Removes unused css/sass/less/stylus from files and modules. Supports Tailwindcss, Bootstrap, Bulma etc.

47 lines (46 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stats = void 0; const utils_1 = require("./utils"); const PRECISION = 2; const KiB = 1024; const HUNDRED = 100; class Stats { constructor() { this.totalCssSize = 0; this.purgedCssSize = 0; } addSize(css) { this.totalCssSize = this.totalCssSize + Buffer.byteLength(css, 'utf8'); } addRemovedSize(css) { this.purgedCssSize = this.purgedCssSize + Buffer.byteLength(css, 'utf8'); } toKB(value) { return (value / KiB).toFixed(PRECISION); } get sizeDifference() { return this.toKB(this.totalCssSize - this.purgedCssSize); } get newSize() { return this.toKB(this.purgedCssSize); } get oldSize() { return this.toKB(this.totalCssSize); } get percentChange() { if (this.totalCssSize <= 0) { return '0.00'; } return (((this.totalCssSize - this.purgedCssSize) / this.totalCssSize) * HUNDRED).toFixed(PRECISION); } printStats() { console.log(utils_1.color.FgGreen, `\ngatsby-plugin-purgecss:`); console.log(utils_1.color.FgCyan, `Previous CSS Size: ${this.oldSize} KB`); console.log(utils_1.color.FgCyan, `New CSS Size: ${this.newSize} KB (-${this.percentChange}%)`); console.log(utils_1.color.FgYellow, `Removed ~${this.sizeDifference} KB of CSS`); console.log(utils_1.color.Reset); } } exports.stats = new Stats();