Skip to content

Instantly share code, notes, and snippets.

@liamfiddler
Last active August 29, 2023 23:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save liamfiddler/f7d0ef9184770750578260978534e7e2 to your computer and use it in GitHub Desktop.
Save liamfiddler/f7d0ef9184770750578260978534e7e2 to your computer and use it in GitHub Desktop.
SCSS + PostCSS pipeline for 11ty
// sass dependencies: `npm i -D sass`
const util = require('util');
const sass = require('sass');
const renderSass = util.promisify(sass.render);
// postcss dependencies: `npm i -D autoprefixer postcss precss`
const autoprefixer = require('autoprefixer');
const postcss = require('postcss');
const precss = require('precss');
const postcssProcessor = postcss([precss, autoprefixer]);
// file paths
const inputFile = '_includes/main.scss';
const outputFile = 'style.css';
module.exports = class {
data() {
return {
permalink: outputFile,
eleventyExcludeFromCollections: true,
};
}
async render() {
const { css } = await renderSass({
file: inputFile,
});
return await postcssProcessor.process(css, {
from: inputFile,
to: outputFile,
});
}
};
@fourjuaneight
Copy link

Nice! Works great on my end. Though I wonder why PostCSS isn't picking the local postcss.config.js.

@fourjuaneight
Copy link

This is working out nicely. Removing a lot of npm scripts with this!
https://gist.github.com/fourjuaneight/5c0981aa7b97d55fe159db55a822cf07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment