diff --git a/.eleventy.js b/.eleventy.js index 7e00e33..090e089 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,6 +1,33 @@ +const CleanCSS = require("clean-css"); +// const is_production = typeof process.env.NODE_ENV === "string" && process.env.NODE_ENV === "production"; +const is_production = true; + +function do_minifycss(source, output_path) { + if(!output_path.endsWith(".css") || !is_production) return source; + + const result = new CleanCSS({ + level: 2 + }).minify(source).styles.trim(); + console.log(`MINIFY ${output_path}`, source.length, `→`, result.length, `(${((1 - (result.length / source.length)) * 100).toFixed(2)}% reduction)`); + return result; +} + module.exports = function (eleventyConfig) { // eleventyConfig.addPlugin(EleventyHtmlBasePlugin); + eleventyConfig.addFilter("cssmin", function (code) { + return new CleanCSS({}).minify(code).styles; + }); + + eleventyConfig.addTransform("cssmin", do_minifycss); + + eleventyConfig.addTransform("log", async function (content) { + console.log(this.page.inputPath); + console.log(this.page.outputPath); + + return content; // no changes made. + }); + eleventyConfig.setNunjucksEnvironmentOptions({ // throwOnUndefined: true, trimBlocks: true diff --git a/package-lock.json b/package-lock.json index 3fabd9d..9685538 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "devDependencies": { "@11ty/eleventy": "^2.0.1", + "clean-css": "^5.3.3", "sass": "^1.69.4" } }, @@ -539,6 +540,18 @@ "fsevents": "~2.3.2" } }, + "node_modules/clean-css": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-5.3.3.tgz", + "integrity": "sha512-D5J+kHaVb/wKSFcyyV75uCn8fiY4sV38XJoe4CUyGQ+mOU/fMVYUdH1hJC+CJQ5uY3EnW27SbJYS4X8BiLrAFg==", + "dev": true, + "dependencies": { + "source-map": "~0.6.0" + }, + "engines": { + "node": ">= 10.0" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -583,9 +596,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "dependencies": { "path-key": "^3.1.0", diff --git a/package.json b/package.json index 1ca5063..ef89d82 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "private": true, "devDependencies": { "@11ty/eleventy": "^2.0.1", + "clean-css": "^5.3.3", "sass": "^1.69.4" } } diff --git a/source/templates/demo/eleventyComputed.js b/source/templates/demo/eleventyComputed.js new file mode 100644 index 0000000..cf59717 --- /dev/null +++ b/source/templates/demo/eleventyComputed.js @@ -0,0 +1,5 @@ +module.exports = { + eleventyComputed: { + path: demoMode ? "/" : "/demo/" + } +}; \ No newline at end of file