zgreen / postcss-critical-css

PostCSS plugin to define and output critical CSS using custom atRules, and/or custom CSS properties. Critical CSS may be output to one or more files, as defined within the plugin options or within the CSS.
MIT License
86 stars 11 forks source link

Add support for multiple file processing #18

Closed jkphl closed 7 years ago

jkphl commented 7 years ago

At the moment, when run through Gulp with multiple streams the critical.css gets overwritten for each single input file, effectively resulting in a CSS containing only the critical rules for the last processed input file. Adding the "a" flag to the fs.writeFile() call appends to the critical.css instead of overwriting it repeatedly.

I'm sorry for not adding a proper test. I don't know the libs you're using for testing and I'm also not sure how easy it is to simulate the multiple-files-in-a-row situation without Gulp. Possibly it would be better to delete / overwrite the critical.css for the first input file and append to it for all the following ones. No idea of how to achieve this though ... As I need a quick fix I'm fine with cleaning up the remainders myself before each run.

lmartins commented 2 years ago

I see that this has been merged. My setup is a little different, as I'm using Webpack's posscss-loader instead of Gulp. With this setup having multiple entry points trying to write to the same critical css file still overrides each time, persisting only the last write. Any way around this?