Last active
October 21, 2024 08:10
-
-
Save mandrasch/ceb29fbde54d85fba4eff9e8680a284b to your computer and use it in GitHub Desktop.
Eleventy: Minify CSS and overwrite file (without inline integration)
This file contains hidden or 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/ |
No problem @mandrasch! I believe it will take a while for the community to migrate all resources across to v3! It may be that AI could help you with this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Nooshu Cool, thanks very much for adding this information!
Thought about upgrading https://github.com/mandrasch/11ty-plain-bootstrap5 to v3 (and Vite) as well, but don't know If I'll find the time.