Currently, in the documentation, it says that when using purge option in tailwind.config.js, CSS will be purged when NODE_ENV is production. I am wondering is it possible to define a custom environment variable for purge to be executed? I can do it if I manually set up purgecss. Just wondering is there an option when using it within tailwindcss. Thx.
Did you try https://tailwindcss.com/docs/controlling-file-size/#enabling-manually ?
You can do that by doing it manually in the tailwind config file, like this:
module.exports = {
purge: {
enabled: false,
content: ['./resources/**/*.blade.php'], // Add you files in this array instead of the purge array.
},
change false to true when you are ready to make a purge. Keep it false during heavy development since purging takes significant time during compilation.
You can refrence to the link @estevanmaito mentioned to learn more about it and more customization to it.
@ahmadabuaysheh @estevanmaito Thanks. I can do this but I believe I will lose the ability to enable purge automatically depending on the environment variable. I tried this,
purge: {
enabled: ((MY_ENV_VAR === 'production') ? true : false),
content: ...
}
This gives MY_ENV_VAR not defined error which I believe is because environment variable is not exposed to tailwind.config.js
Instead of doing MY_ENV_VAR === 'prodcution', process.env.MY_ENV_VAR === 'production' will work.
Most helpful comment
Instead of doing
MY_ENV_VAR === 'prodcution',process.env.MY_ENV_VAR === 'production'will work.