bglw / jekyll-postcss-v2

MIT License
23 stars 3 forks source link

CSS files are not processed after the whole site is built #2

Open antoinevth opened 2 years ago

antoinevth commented 2 years ago

Hi !

Thank you for this plugin ! I was trying to use it with PurgeCSS. However, PurgeCSS requires the whole site (especially HTML files) to be built before modifying the CSS files. Which is not the case, actually. In fact, in my case I have to build my website a first time to get all the HTML files generated, and then a second time to get correct CSS files based on the generated HTML files.

I've tried to modify the hook in lib/jekyll-postcss-v2/hook.rb :

Jekyll::Hooks.register :site, :post_write do |site|
 site.pages do |page|
    if %r!\.css$! =~ page.url
      engine = PostCssV2::Engine.new(page.site.source)
      engine.process(page)
    end
  end
end

However, in this case, site.pages does not list generated CSS files, but only source SCSS files.

Do you have any lead to solve my issue ?

bglw commented 2 years ago

👋 Hi @antoinevth

Sorry for the delay, this slipped my radar. Have you had any further luck on this?

I do recall using this with PurgeCSS in the past with success, and I don't see conceptually why it wouldn't work — PostCSS here is running after the entire site has been built to disk.

Let me know and I can have a little bit of a further look.

bglw commented 2 years ago

Sorry, accidental close

antoinevth commented 2 years ago

Hi @bglw ! Thanks for your reply. Sorry for the delay.

I do still have this issue. In fact, when I build my site for the first time, my css file is around 11kB and PurgeCSS has removed too many things. When I build it a second time I get a css file of 24kB.

My workaround actually is to build the site two times.

woodcox commented 2 years ago

I have had similar issues where too much css is removed but only when I use jekyll-postcss-v2 in conjunction with the gem jekyll-remote-theme. If I remove the Jekyll-remote-theme purgecss does run last and removes unused css correctly. But when I use Jekyll-remote-theme the purgecss does not run last and removes far too much css. Are you using remote themes? Or could another gem be affecting things?

antoinevth commented 2 years ago

I'm not using remote themes and the only other gem I'm using is jekyll_picture_tag. However, I'm using scss and imports, maybe it's related...

leppert commented 1 year ago

In my case, this issue arose from pointing a postcss plugin (in my case tailwindcss) to the jekyll source files rather than the built _site files. Configuring the plugin to process against the _site files fixed the issue.