Skip to content

Instantly share code, notes, and snippets.

@mandrasch
Last active October 21, 2024 08:10
Show Gist options
  • Save mandrasch/ceb29fbde54d85fba4eff9e8680a284b to your computer and use it in GitHub Desktop.
Save mandrasch/ceb29fbde54d85fba4eff9e8680a284b to your computer and use it in GitHub Desktop.
Eleventy: Minify CSS and overwrite file (without inline integration)
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/
@mandrasch
Copy link
Author

@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.

@Nooshu
Copy link

Nooshu commented Oct 21, 2024

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