django-crispy-forms / crispy-tailwind

A Tailwind template pack for django-crispy-forms
MIT License
331 stars 56 forks source link

Workflow/Configuration for purge #103

Open chriswedgwood opened 2 years ago

chriswedgwood commented 2 years ago

Hi thanks for the project

I have an issue where I am using the purge option for my templates

module.exports = {
  purge: {

   content: ['./**/templates/**/*.html'],
   safelist: ['underline','cursor-pointer','grid-cols-3','gap-1','grid-cols-2'],

},

The css for the templates is not being applied when I deploy to prod If I am using the crispy template pack fields do I just need to add a path to my content that will be for the path to the templates in site packages?

smithdc1 commented 2 years ago

Hi @chriswedgwood hope you are well. Love your work on Django snippets. ♥️

Umm.. so... There's a purge option? 🕵️

I'm really happy to investigate but I've not come across this, I'm still learning lots about Django!

Maybe it is not possible but is there a small test project you could share that shows this issue?

Take care.

carltongibson commented 2 years ago

My initial thought is that maybe we could generate a safelist for the template pack. (These are the classes in use.)

chriswedgwood commented 2 years ago

Yes I did think about adding to the safelist. It wouldnt be that hard to generate it but it may make the config quite bloated.

Let me play around some more and I'll come back here with my findings/example.

carltongibson commented 2 years ago

Can we get the output from the search from tailwind/purge I wonder?

chriswedgwood commented 2 years ago

Okay this worked for me:

module.exports = {
  purge: {

   content: ['./**/templates/**/*.html','../envs/**/*.html'],
   safelist: ['underline','cursor-pointer','grid-cols-3','gap-1','grid-cols-2'],

}

In production my site-packages is under ../envs/.

The safelist is still required for class definitions defined in form Layouts e.g.

self.helper.label_class = (
            "font-noe text-sm font-normal leading-11 tracking-tight text-skin mt-6"
        )

Perhaps there is something we can do there to generate the safelist for those cases? What would be required dor this, a management command?

I'll add a documentation PR for this 👍

michael-yin commented 2 years ago

@chriswedgwood

I have added a documentation PR to talk about this problem, I think it might be better than safelist

Could you please check it?

Thx.