phthhieu / re-tailwind

Brings TailwindCSS https://tailwindcss.com to ReasonML
https://phthhieu.github.io/re-tailwind
MIT License
119 stars 2 forks source link

PurgeCSS not recognizing classes #15

Open Splingush opened 4 years ago

Splingush commented 4 years ago

Hey folks!

When this library is used in combination with purgecss, it does not properly parse the used classes, so they are not added to the bundled css. However, it's rather useful for tailwind, because it reduces the bundling-size by a lot.

Do you have some idea of a common workflow with that?

I've seen that one may manually whitelist classes, or manually remove unused ones, but it's cumbersome.

The ts-package has an automatic approach: https://github.com/dvkndn/typed.tw#compile-time-usage-with-webpack Do you think this would be feasable here as well, maybe even using a ppx?

Best Wishes

phthhieu commented 4 years ago

@Splingush It is definitely the next milestone of this project. The current approach converts 1:1 ReasonML variant option to a string, which makes the elimination of unused classes string doesn't work.

I intend to write a PPX to fix it, basically, it will help zero runtime cost for string concatenation and code elimination.

I'm working on it

em commented 3 years ago

FYI - You could do this by writing a custom purgecss extractor that matches all of your named functions and map them back to the CSS selector.

Then you could expose that to tailwind.config.js something like:

  purge: {
    enabled: true,
    layers: ['utilities'],
    content: [
    './src/**/*.re',
    './src/**/*.res'
    ],
    options: {
      defaultExtractor: require('re-tailwind/Purge.bs').extractor, // returns ["float-right"] when Float(FloatRight) is found in source 
    }
  },
phthhieu commented 3 years ago

@em Nice suggestion, would to help implement it?