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

[JIT] Add support for "raw" purge content #4094

Closed
cossssmin opened this issue Apr 16, 2021 · 6 comments · Fixed by #4272
Closed

[JIT] Add support for "raw" purge content #4094

cossssmin opened this issue Apr 16, 2021 · 6 comments · Fixed by #4272

Comments

@cossssmin
Copy link
Contributor

What version of Tailwind CSS are you using?

v2.1.1

What build tool (or framework if it abstracts the build tool) are you using?

Maizzle v3.3.1

What version of Node.js are you using?

v14.15.1

What browser are you using?

Chrome

What operating system are you using?

Windows 10

Reproduction repository

https://github.com/maizzle/maizzle

Describe your issue

Configuring the purge option in your build chain instead of tailwind.config.js results in:

TypeError: expected path to be a string

Sounds like it expects it to be in the tailwind.config.js file.

What I'm doing is definining a base config in the file where I compile Tailwind, like this:

const coreConfig = {
  purge: {
    enabled: true,
    content: [
      'src/**/*.*',
    ],
  },
}

I then merge that with the config read from my tailwind.config.js and use it to compile Tailwind with PostCSS:

// merge() is from lodash
// `tailwindConfigObject` is the contents of `tailwind.config.js`

return postcss([
  tailwindcss(merge(coreConfig, tailwindConfigObject)),
])
  .process(css, {from: undefined})
  .then(result => result.css)

The resulting config is correct, and it works fine without JIT.

When I add mode: 'jit' in tailwind.config.js, it throws the error. As soon as I also add purge: ['src/**/*.*'] in tailwind.config.js, JIT works as expected.

@cossssmin cossssmin changed the title [JIT] TypeError when configuring purge outside tailwind.config.js [JIT] TypeError when using an object to configure purge Apr 16, 2021
@cossssmin
Copy link
Contributor Author

Just tried to use an object config right in tailwind.config.js for purge:

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

... and the same error is thrown. I suppose object syntax just isn't supported yet here, that also being one of the reasons purgecss options like safelist aren't supported?

Apologies if this has been covered somewhere, I couldn't find any issue/docs about it except the safelist thing.

@bradlc
Copy link
Contributor

bradlc commented May 7, 2021

I suppose object syntax just isn't supported yet here

Providing an object with a content property is supported, and your example should work fine. Is there any chance you could provide a minimal reproduction? I can't see a purge config anywhere in the maizzle repo. Thanks!

@cossssmin
Copy link
Contributor Author

cossssmin commented May 7, 2021

The purge config is in the framework repo - my bad!

https://github.com/maizzle/framework/blob/0dabece8b036739a0bdd8ed83c31cf8b452a3e1f/src/generators/tailwindcss.js#L22-L29

I just merge whatever you have in tailwind.config.js on top of that.

So just adding mode: 'jit' in tailwind.config.js, without including a purge key with simplified array syntax (thus relying on the object syntax defined in the framework linked above), will hang 🤔

@cossssmin
Copy link
Contributor Author

Created a repo that reproduces the issue, I've added instructions in the readme:

https://github.com/maizzle/jit-object-config

@bradlc
Copy link
Contributor

bradlc commented May 7, 2021

Thanks! It's because you are using "raw" content, which isn't currently supported by JIT mode. We will probably add support for this at some point for consistency with PurgeCSS, but for now that's why it isn't working, sorry about that!

@cossssmin
Copy link
Contributor Author

Ah, OK. Yeah I need raw when rendering templates programmatically so that Tailwind can purge based on the HTML string that I want to compile, since there are no file paths in that context.

Feel free to close the issue if you prefer, and thanks for looking into it! :)

@bradlc bradlc changed the title [JIT] TypeError when using an object to configure purge [JIT] Add support for "raw" purge content May 7, 2021
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 a pull request may close this issue.

2 participants