question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use @apply within the project's native CSS code.

See original GitHub issue

At present, the apply function is only useable within javascript.

It would be great to be able to use it as a css directive @apply so that we can get access and apply all Tailwind classes within any CSS file, <style> tag of an HTML file or Svelte component, etc…

Ideas for enabling this might be to do it with a vite or postcss plugin.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
sastancommented, Jan 12, 2022

What I hope to achieve is integration with existing tooling (postcss, vite, webpack, …) that would allow full static extraction without any config. Basically what you two (@danielweck and @rschristian) are already doing.

In my opinion, twind should be able to process existing CSS with support apply, theme, and screen.

@twind {
  h1 {
    @apply text(center 2xl);
  }
}

For svelte:

<style lang="twind">
h1 {
	@apply text(center 2xl);
}
</style>
2reactions
danielweckcommented, Jan 25, 2022

For your other suggestion — using twind within <style> — that is still on the table and a TODO for me.

@sastan will no doubt introduce a clean “native” Twind API to handle the <style> use case, but in the meantime this can easily be achieved in userland with Twind v1 (Work In Progress “next” version https://github.com/tw-in-js/twind/tree/next )

document.querySelectorAll('style[type~="twind/css"]').forEach((e) => {
    tw(css(e.textContent));
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solving the React Error: Not Picking Up CSS Style | Pluralsight
In this guide, you will learn about the errors that can occur while importing a CSS file into your React file.
Read more >
Using CSS Modules in React Native - LogRocket Blog
CSS Modules enable you to use locally scoped styles in your React Native app, which makes your code significantly cleaner and more readable....
Read more >
Tailwind CSS classes is not working in my project?
This error is due to tailwind not finding any classes to scan in what it 'thinks' is your HTML code directories.
Read more >
Handling common HTML and CSS problems - MDN Web Docs
With the scene set, we'll now look specifically at the common ... This includes linting code, handling CSS prefixes, using browser dev tools ......
Read more >
Using with Preprocessors - Tailwind CSS
The place you are most likely to run into this situation is in your main CSS file that includes your @tailwind declarations. Won't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found