-
There’s a great example in the docs how to build Sass styles using Eleventy’s own watcher. I tried to recreate it using plain CSS with some PostCSS plugins to combine imports, prefix and minimize it. The full code is available here: pepelsbey/11ty-postcss. const postcss = require('postcss');
const autoprefixer = require('autoprefixer');
const csso = require('postcss-csso');
const pimport = require('postcss-import');
config.addTemplateFormats('css');
config.addExtension('css', {
outputFileExtension: 'css',
compile: async (inputContent, inputPath) => {
let output = await postcss([
pimport,
autoprefixer,
csso
]).process(inputContent, { from: inputPath });
return async () => {
return output.css;
}
}
}); I have the following structure: /* src/styles/index.css */
@import url('blocks/one.css');
@import url('blocks/two.css');
/* src/styles/blocks/one.css */
.one {
color: tomato;
}
/* src/styles/blocks/two.css */
.two {
color: plum;
} And it works totally fine after .one{color:tomato}.two{color:plum} Unfortunately, it doesn’t work the way I expect during development. If I change anything in the blocks, I get the event in the console:
But I don’t get updates in the resulted Any idea how to make it work? It would make a such an elegant CSS build pipeline! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I made it work with help of @monochromer 🥳 config.addExtension('css', {
outputFileExtension: 'css',
compile: async (inputContent, inputPath) => {
if (inputPath !== './src/styles/index.css') {
return;
}
return async () => {
let output = await postcss([
pimport,
autoprefixer,
csso
]).process(inputContent, { from: inputPath });
return output.css;
}
}
}); It was a matter of proper function nesting. Now it also filters out all the paths apart from index.css, just like it supposed to. |
Beta Was this translation helpful? Give feedback.
-
Sharing a more recent option: a plugin now exists! I used @jgarber/eleventy-plugin-postcss with a standard
|
Beta Was this translation helpful? Give feedback.
I made it work with help of @monochromer 🥳
It was a matter of proper function nesting. Now it also filters out all the paths apart from index.css, just like it supposed to.