Skip to content

Fix purgeEnabled evaluating to true when config.purge.enabled is false #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2020
Merged

Fix purgeEnabled evaluating to true when config.purge.enabled is false #1673

merged 3 commits into from
Apr 30, 2020

Conversation

lihbr
Copy link
Contributor

@lihbr lihbr commented Apr 30, 2020

Hi!

This is a quick bugfix regarding the new config.purge options, basically the following:

const purgeEnabled =
  _.get(config, 'purge.enabled', false) === true ||
  (config.purge !== undefined && process.env.NODE_ENV === 'production')

Evaluate to true even when the purge option is explicitely disabled in the config like that:

module.exports = {
  purge: {
    enabled: false
  }
  /* ... */
}

The first test evaluates to false so only the value of the or condition is taken into account but this one evaluate to true when in production regardless of the config.purge.enabled value, this pull request fix that.

To give more context over how I came across that I was annoyed by my build spamming Skipping purge because no template paths provided... because my config.purge was undefined and fallbacking to Tailwind default config value (an empty array), so I decided to explicitly disable the purge option the way above but then my build started failing. So I dug a bit and found that. I would like to also propose to change Tailwind default purge config to the one above in order to omit the warning when no purge config is set by default, but that's open to discussion.

Cheers~!

@adamwathan adamwathan merged commit 67ec21e into tailwindlabs:master Apr 30, 2020
@adamwathan
Copy link
Member

Thanks good catch! I'll get another patch release out this afternoon.

Tough call on the default, I had intended for undefined to be "just disable it" but of course when adding the default value to the config I messed that up.

I do want some way to encourage people in the console to purge their styles though, because it's basically a required step at this point if you want a sensible output size 🤔 Wonder what the best approach actually is given the accidental behavior you noticed here. Maybe it's just as simple as allowing people to add purge: false to silence the warning so it's a little more terse than what you had to do at least.

@jhauraw
Copy link

jhauraw commented Apr 30, 2020

@adamwathan I just wanted to add some more context to consider. If you do your own purging in postcss.config.js and have tailwind.config.js with 1.3v style (meaning no reference to the purge variable), during build Tailwind prints a warning that is confusing which makes one think PostCSS PurgeCSS is not working.

Tailwind warning: "Skipping purge because no template paths provided..."

So I would think making the Tailwind default disabled if the purge option is missing or not set. So Tailwind never makes it past line 22 in purgeUnusedStyles.js in that case.

Also, setting purge: { enabled: false } in tailwind.config.js breaks PostCSS PurgeCSS, currently. But again, if Tailwind's default is off, user's who do their own purge don't have to update their config just to turn off Tailwind's purge. So purge is opt-in.

@lihbr
Copy link
Contributor Author

lihbr commented Apr 30, 2020

@jhauraw when this PR will be out setting config.purge.enabled to false won't cause the issue anymore (that's the one I was having)

@adamwathan as for the default discussion given current state of Tailwind I totally agree that using it without Purgecss (Tailwind built-in or third party) makes almost no sense so I think that the warning is great to have by default after all, what I suggest which is non-breaking:

  • Setting default config config.purge to undefined

Then on build:

  • If config.purge is undefined:
    Disable built-in Purgecss and warn the user that config.purge is undefined and that they should either configure config.purge (with link to the doc perhaps?) or disable it with either config.purge = false or config.purge.enabled = false if they already have a third party Purgecss / don't care to get rid of the warning.

  • If config.purge content array is empty:
    Disable built-int Purgecss and keep the current warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants