From 121e4d8e247818009d240f8db765fac971571649 Mon Sep 17 00:00:00 2001 From: samuel-p Date: Mon, 14 Jun 2021 23:22:40 +0200 Subject: [PATCH] added more compression tools --- .compress-all.js | 32 ++++++++++++++++++++++++++++++++ package.json | 8 ++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .compress-all.js diff --git a/.compress-all.js b/.compress-all.js new file mode 100644 index 0000000..dcbce1e --- /dev/null +++ b/.compress-all.js @@ -0,0 +1,32 @@ +const glob = require("glob"); +const minify = require('@node-minify/core'); +const htmlMinifier = require('@node-minify/html-minifier'); +const crass = require('@node-minify/crass'); + +console.log('compress all html and css files'); + +glob("dist/**/*.html", function (er, files) { + files.forEach(file => { + console.log(file); + minify({ + compressor: htmlMinifier, + input: file, + output: file, + options: { + collapseWhitespace: true, + conservativeCollapse: true + }, + }); + }) +}); + +glob("dist/**/*.css", function (er, files) { + files.forEach(file => { + console.log(file); + minify({ + compressor: crass, + input: file, + output: file + }); + }) +}); diff --git a/package.json b/package.json index 95a3c13..c472b19 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,11 @@ "description": "website for sp-codes.de", "scripts": { "compile-sass": "node-sass --output-style compressed --importer=node_modules/node-sass-tilde-importer src/scss/main.scss -o dist/css/", - "p-minify-css": "purifycss dist/css/main.css dist/**/*.html dist/**/**/*.html dist/**/**/**/*.html -i -m -o dist/css/main.css", "minify-css": "uncss -n -H dist/ -o dist/css/main.css dist/**/*.html dist/**/**/*.html dist/**/**/**/*.html", "watch:eleventy": "eleventy --serve", "watch:sass": "npm-run-all compile-sass minify-css -- --watch", "start": "npm-run-all compile-sass minify-css --parallel watch:*", - "build": "npm run compile-sass && eleventy && npm run move-index && npm run minify-css", + "build": "npm run compile-sass && eleventy && npm run move-index && npm run minify-css && node .compress-all.js", "move-index": "cpx dist/de/index.html dist/" }, "author": "samuel-p", @@ -23,7 +22,12 @@ "devDependencies": { "@11ty/eleventy": "^1.0.0-canary.33", "@11ty/eleventy-navigation": "^0.2.0", + "@node-minify/core": "^6.2.0", + "@node-minify/crass": "^6.2.0", + "@node-minify/html-minifier": "^6.2.0", "cpx": "^1.5.0", + "glob": "^7.1.7", + "minify": "^7.0.2", "node-sass": "^6.0.0", "node-sass-tilde-importer": "^1.0.2", "npm-run-all": "^4.1.5",