Skip to content
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

Purge does not purge ALL unused classes #2341

Closed
nartc opened this issue Sep 7, 2020 · 3 comments
Closed

Purge does not purge ALL unused classes #2341

nartc opened this issue Sep 7, 2020 · 3 comments

Comments

@nartc
Copy link

nartc commented Sep 7, 2020

Describe the problem:

After setting up a new project (Create React App) with TailwindCSS with Purge enabled, running tailwind build ... does not purge ALL unused classes (basically none should be used since it's a brand new CRA application). Config file is as follow:

module.exports = {
  prefix: '',
  future: {
    removeDeprecatedGapUtilities: true,
    purgeLayersByDefault: true
  },
  purge: {
    enabled: true,
    content: ['**/*.jsx', '**/*.js']
  },
  theme: {}
}

Produced CSS after tailwind build is at follow (truncated):

...
.border-collapse {
  border-collapse: collapse;
}

.border-separate {
  border-collapse: separate;
}

.rounded {
  border-radius: 0.25rem;
}
...
@-webkit-keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@-webkit-keyframes ping {
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

@keyframes ping {
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}
...

None of the classes in the output css is used. The provided reproduction below is a Create React App but the same thing occurs for an Angular application setup.

Link to a minimal reproduction:

https://github.com/nartc/react-tailwind-purge-reproduce
Steps:

  1. Clone
  2. Install
  3. Run npm run build:tw
  4. Check tailwind.output.css file
@nartc
Copy link
Author

nartc commented Sep 7, 2020

I adjusted the purge.content config a little bit to target the src directory: ['./src/**/*.jsx', './src/**/*.js'] and the output css is looking better. However, there's still .table class being included in the output css even though it's unused:

image

@JNavith
Copy link
Contributor

JNavith commented Sep 7, 2020

However, there's still .table class being included in the output css even though it's unused:

HTML elements are preserved by default, and since .table resembles table, it's been left in: #2283

@adamwathan
Copy link
Member

adamwathan commented Sep 7, 2020

Yep @JakeNavith is right. If you want to purge everything, disable preserveHtmlElements. Careful though, now you'll lose important styles like html and body unless you also include ./public/index.html in your content array.

To remove the keyframes, you'll want to use PurgeCSS's keyframes option:
image

In Tailwind that looks like this:

module.exports = {
  future: {
    removeDeprecatedGapUtilities: true,
    purgeLayersByDefault: true
  },
  purge: {
    enabled: true,
    content: ['public/index.html', 'src/**/*.jsx', 'src/**/*.js'],
    options: {
      keyframes: true,
    },
  },
  theme: {}
}

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

No branches or pull requests

3 participants