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

Support tailwindlabs/tailwindcss-jit #422

Closed
holgerw opened this issue Mar 16, 2021 · 8 comments · Fixed by #432
Closed

Support tailwindlabs/tailwindcss-jit #422

holgerw opened this issue Mar 16, 2021 · 8 comments · Fixed by #432
Labels
feature request New feature or request

Comments

@holgerw
Copy link

holgerw commented Mar 16, 2021

Is it planned to generate minimal css with the new tailwindlabs/tailwindcss-jit instead of purging from the traditional huge set of Tailwind classes?

In my use case the files generated by Maizzle become templates consumed by another templating system (.eex / Elixir). As those .eex templates should be up to date during development on each edit, I do a maizzle build production of all templates on each save. For this use case it would be relevant to improve the build times with tailwindlabs/tailwindcss-jit.

I would be happy to contribute with a PR if you have a hint where to start.

@cossssmin
Copy link
Member

We'll definitely add it as some point, JIT looks great and I can see many other benefits of using it in Maizzle.

However, it's still experimental so we'll need to wait for a (more) stable version, or until it gets into Tailwind core. Even then, it'll very likely be an option that your need to turn on in Maizzle, mainly because of the fact that you lose the ability to rapidly prototype in the browser (since you no longer have all classes generated).

@cossssmin cossssmin added the feature request New feature or request label Mar 17, 2021
@jbtheard
Copy link

jbtheard commented Apr 6, 2021

JIT has just been added to Tailwind 2.1. I have used JIT on a react project and confirm the engine is fast enough to still prototype almost instantly.

@cossssmin
Copy link
Member

Yes we'll definitely add support for it, just need a bit more time to make sure we don't break anything and that it works as expected.

@cossssmin
Copy link
Member

Played a bit with this today and there's good news and bad news.

Good news is you can simply enable it yourself if using Tailwind CSS v2.1.0 or above:

module.exports = {
  mode: 'jit',
  purge: [
    'src/**/*.*',
  ],
}

Bad news is that core plugins are not disabled anymore. This is a showstopper for HTML email, because you'll get color classes with opacity variables like this:

.text-red-400 {
  --tw-text-opacity: 1;
  color: rgba(248, 113, 113, var(--tw-text-opacity));
}

CSS variables have poor support in email, so this means your CSS colors will not work in some of the most important email clients, like Gmail, Outlook, or Yahoo!

I've opened tailwindlabs/tailwindcss#4071, let's wait and see what the team says.

@cossssmin
Copy link
Member

cossssmin commented Apr 14, 2021

A workaround for using JIT while developing locally, but falling back to AOT when building for production, would be to enable JIT based on NODE_ENV:

module.exports = {
  mode: process.env.NODE_ENV === 'local' ? 'jit' : 'aot',
  purge: [
    'src/**/*.*',
  ],
}

However this won't work right away, because we're not setting process.env.NODE_ENV in the to-disk generator correctly. Will take care of that right now and publish a patch.

@cossssmin
Copy link
Member

Released v3.3.1 so you can now use the workaround explained above.

@cossssmin
Copy link
Member

Using Tailwind's own purging has now been implemented in #432, and we'll soon publish a new release.

Remember, to use JIT you will (currently) need to:

  1. enable it only for maizzle serve or maizzle build (and not for any other environment, because of [JIT] Disabling opacity core plugins doesn't change output of color plugins tailwindlabs/tailwindcss#4071)
  2. also specify the purge option in your tailwind.config.js, in simplified array syntax (it throws an error and Maizzle build hangs if you omit it or set it to an object, see [JIT] Add support for "raw" purge content tailwindlabs/tailwindcss#4094)

Example:

module.exports = {
  mode: process.env.NODE_ENV === 'local' ? 'jit' : 'aot', // all `maizzle build` commands that specify an environment name will use 'aot'
  purge: [
    'src/**/*.*',
  ],
  // ...
}

@cossssmin
Copy link
Member

cossssmin commented Apr 17, 2021

Another way of using JIT only when developing locally is to specify a custom Tailwind config object for your production builds:

// tailwind.config.js

module.exports = {
  mode: 'jit',
  purge: [
    'src/**/*.*',
  ],
  // ...
}
// config.production.js

const omit = require('lodash/omit')

// Remove 'mode' and 'purge' keys from Tailwind config in production
const twconfig = omit(require('./tailwind.config'), ['mode', 'purge'])

module.exports = {
  build: {
    tailwind: {
      config: twconfig,
    },
  // ...
}

This way you rely on your Maizzle config files instead of the NODE_ENV, if that matters.

Using this myself in a project with >50 emails where for some reason having purge: ['src/**/*.*'] in tailwind.config.js slows down the build incredibly. Removing the purge key brings things back to normal by defaulting to Maizzle's purge settings:

purge: {
enabled: maizzleConfig.env !== 'local',
content: [
'src/**/*.*',
{raw: html}
],
options: get(maizzleConfig, 'purgeCSS', {})
},

Note: as mentioned in my previous comment, we currently can't use object syntax for purge if using mode: 'jit'.

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

Successfully merging a pull request may close this issue.

3 participants