Welcome to mirror list, hosted at ThFree Co, Russian Federation.

minify.js - github.com/GDGToulouse/devfest-theme-hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af306daeefde4368594990ee1d73f6d72049c0b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const {readFileSync, writeFileSync} = require('fs');
const {sync: glob} = require('glob');
const {minify} = require('html-minifier');


glob(`public/**/*.html`)
    .forEach(file => {
        const html = readFileSync(file, 'utf8');
        const minified = minify(html, {});
        const gain = html.length - minified.length;
        if (gain > 0) {
            const percent = (gain / html.length) * 100;
            console.info(file, 'gain', percent.toFixed(2), '%');
            writeFileSync(file, minified, {flag: 'w'});
        }
    });