feat: Minify css
- Add dependency clean-css - Add do_minifycss function as filter to eleventy - Add workaround for demo mode with computed data file
This commit is contained in:
parent
024540e389
commit
d7ce139ab7
4 changed files with 49 additions and 3 deletions
27
.eleventy.js
27
.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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue