Tailwindcss: Set custom environment variable for using purge option

Created on 21 May 2020  路  4Comments  路  Source: tailwindlabs/tailwindcss

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.

Most helpful comment

Instead of doing MY_ENV_VAR === 'prodcution', process.env.MY_ENV_VAR === 'production' will work.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chintanbanugaria picture chintanbanugaria  路  3Comments

jvanbaarsen picture jvanbaarsen  路  3Comments

divdax picture divdax  路  3Comments

ouun picture ouun  路  3Comments

lamberttraccard picture lamberttraccard  路  3Comments