Tailwind, how to build css file with all supported classes - css

I'm using dynamicaly generated classnames in React/Tailwind. I know that it doesn't supported. So I need to generate a css file including all Tailwind functionality. How can I achive it?

My advice would be to refactor the code so you support the "tailwind way" because loading the entire library will possibly hurt your performance ,if you are not going to do that you can add all the classes you do not want purged to the safelist in your tailwind.config.js
Here is a link to official doc
https://tailwindcss.com/docs/content-configuration#safelisting-classes

Related

How to use Sass in blazor?

I found MS DOC about Css in razor. But it isn't work with Scss file.
I resolve this problem by creating two files: css and scss. And use sass --watch. But I need write this every time, when creating new component.
Unfortunately SASS is not supported for CSS Isolation feature of Blazor. At least, not at this moment.
In our project, we use CSS Isolation for the CSS component isolation feature, but we use SASS files to manage our theme, for style we want accros the application.
That being said, if you really need some SASS for an unique component, you totally can, by adding for example a wrapper with a specified id, and use this id in your scss file, with a dedicated name for it, for example MyComponent.scss.
In addition, I've found this article, but I preferred to not use it because it is a bit heavy to setup, but up to you: https://joren-thijs.medium.com/how-to-add-scss-support-to-blazor-cd2a62995441
You can use AspNetCore.SassCompiler which supports both normal and isolated scss. I believe it has a watch mode when using Blazor Server, WASM is not supported yet.
It can also do minification with source mapping.

Can Prettier be limited to one plugin and a set of files only?

We are using Tailwind in our projects and we want to use its official plugin for Prettier to sort our CSS classes.
However, Prettier is very annoying for us for other file types and other languages.
We only want to use it to sort our Tailwind CSS classes and nothing more.
Can we config it for this purpose?

VSCode - Go to definition of external CSS class

I'm trying to navigate to the definition of external classes using VSCode, notably Bootstrap. Read on for more details.
I can use extensions like CSS Peek and CSS Navigation to navigate to internal classes inside my project just fine.
I can also see what external classes exist thanks to extensions like SCSS Everywhere.
However, I cannot navigate to those external classes. This is what I'd like to solve.
The use cases are:
to easily and quickly know what classes do without looking up documentation
avoid conflicts and side-effects by knowing what you are applying
to extend bootstrap classes using sass with #extends
Thanks

Is it possible to extract and bundle only necessary css classes in a web application

I think this should be possible, though dont know, I use tools like 'gulp' and 'webpack' to bundle asset files but is there any tool that extracts the necessary css classes, only that are being used, from the css files and pack them.
What you are looking for is called tree shaking, and usually it's already done in the build process with webpack,
You can install this plugin for css specific tree shaking or you can look for more info here about how it works with javascript (something similar happens in css)
In Gulp there is package called Uncss
https://github.com/ben-eb/gulp-uncss
and also an addon that is available for firefox
https://addons.mozilla.org/en-US/firefox/addon/dust-me-selectors/
which will help you in removed unused css
Take a look into tree shaking, there are several that are for specific css.

Using Less with Web Components

As stated by Rob Dodson, style tags are now unavoidable with Web Components. I am trying to find a way to use LESS with this new tecnhology without having to paste the compiled CSS in my HTML document everytime I change something in the LESS file . Is there anyway to achieve that?
I am using Polymer.
Thanks!
Laurent
You can make the client compile the LESS to CSS , you should definitely take a look at this :
http://lesscss.org/#client-side-usage
It is advised to compile it yourself to css in a production environment though !
Doing this client-side hardly seems like the corrent solution, especially at scale. For instance, do you really want 1000 web components in your app all including LessCSS and compiling on the client side?
Just compile server-side and include the compiled version in your html import. Apps like DocPad, make this a lot easier. For instance:
src/documents/components/my-component/my-component.css.less is your source file, and is compiled to out/components/my-component/my-component.css, which is accessible at /compoennt/my-component/my-component.css.
We use this workflow to also make use of javascript pre-processors like coffeescript, as well as post-processors like css auto prefixer, and bundlers like Browserify. See: https://stackoverflow.com/a/23050527/130638 for more info.
Simply compile your less and embed the generated CSS file via good old link tag.
I don't think that rob wanted to say that using style tags is the only way to go. You can still link to external stylesheets as you always did.
Why don´t you compile on server side using php compiler? Have a look here - http://leafo.net/lessphp/ -
To let you know, i´m using this compiler on my projects, on the server side without any kind of problems!!!!!!! :) IMO, it´s better to have the compilation work on the server side. I´m not totally 100% sure, but i think IE8 don´t recognize text/less
The way I have done this before is have individual .less or .scss file for each component and have it compile into the individual .css file which is then called into the respective component file. and finally vulcanize everything into a single file.
Incase you want to use a single CSS file, then use //deep// combinator or ::shadow pseudo elements in the CSS.
If you able to create the custom elements without using ShadowDOM then you can simply have all your less merge into a single CSS.
Honestly speaking I was unable to create a wc without shadowDOM in polymer. There is a long conversation on github on enabling / disabling and hacking a way to create a wc without shadowDOM here https://github.com/Polymer/polymer/issues/222
One solution would be to have the preprocessor translate .less files into .css and then linking them inside Polymer components, like explained in the official documentation: https://www.polymer-project.org/1.0/docs/devguide/styling#external-stylesheets
Unfortunately this is deprecated. So the other way to go could be to have another step that wraps the preprocessor-generated css files with a dom-module: this way you can follow the Polymer way including the style module inside your components, or using the css file compiled from less if you do things outside Polymer components.
I'm using Gulp for my build process and I found this module very useful:
https://github.com/MaKleSoft/gulp-style-modules
It creates, for every .less file I have in my sources, an .html file with a dom-module wrapped around it, ready to be included in the components' styles.

Resources