Last active
September 8, 2022 13:36
-
-
Save mandrasch/ceb29fbde54d85fba4eff9e8680a284b to your computer and use it in GitHub Desktop.
Eleventy: Minify CSS and overwrite file (without inline integration)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (eleventyConfig) { | |
// npm install --save-dev clean-css | |
eleventyConfig.on('afterBuild', () => { | |
const CleanCSS = require("clean-css"); | |
const fs = require('fs'); | |
// Run me after the build ends | |
var inputFile = 'src/assets/css/main.css'; | |
var input = fs.readFileSync(inputFile, 'utf8'); | |
var output = new CleanCSS().minify(input); | |
fs.writeFile('_site/assets/css/main.css', output.styles, function (err) { | |
if (err) return console.log('Error minifying main.css' + err); | |
//success | |
}); | |
}); | |
} | |
// if you want to use inline styles, see: https://www.11ty.dev/docs/quicktips/inline-css/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment