phoenixframework / tailwind

An installer for tailwind
MIT License
467 stars 61 forks source link

Potential Solution for handling Dynamic Classes in for purging? #68

Closed atonse closed 1 year ago

atonse commented 1 year ago

Problem

This is more a question, but we can implement this as a PR if there is an appetite for it.

Our home-grown CMS has a lot of blocks that have tailwind classes in them, and the content for these blocks is all in the database. But when doing analysis to purge classes, since those classes are only defined in content in the database, these CSS classes still get purged.

Our solution has to been to dump out to a git-ignored /priv/static/prerendered/blocks.html file that just concatenates all those blocks' contents, and adding that html file to the tailwind PurgeCSS content path.

However, this doesn't feel elegant. We have to remember to run the module that generates the additional dynamic content and dumps it in a file.

Proposal

What if we had a config option that allows for us to define MFAs for various events (main one being "before purge") where we could either generate this file and return {:files, [list_of_generated_files]}, or "string content" that is used in the purge analysis?

something like:

config :tailwind, :events,
  before_purge: {MyModuleThatGeneratesTheStaticFile}

Thoughts? We can't be the only ones facing this :-) I didn't necessarily look at the tailwind side for a solution because we would like to ideally run elixir code to be able to generate that additional content.

josevalim commented 1 year ago

We don't plan to add functionality on top of tailwind at the moment. My suggestion is to wrap the watcher function (the one that calls install_and_run) and the mix.exs assets.deploy to generate your content before calling tailwind. :)