All Projects → tesar-tech → BlazorAndTailwind

tesar-tech / BlazorAndTailwind

Licence: other
Tips and notes about Blazor and Tailwind

Programming Languages

HTML
75241 projects
CSS
56736 projects
C#
18002 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to BlazorAndTailwind

blazor-tailwindcss-template
This template demostrates the integration of tailwindcss with blazor and covers important features like hot-reload and css isolation
Stars: ✭ 38 (+40.74%)
Mutual labels:  tailwindcss, blazor
TailBlazor
Blazor & Tailwind JIT on Azure Static Web Apps
Stars: ✭ 24 (-11.11%)
Mutual labels:  tailwindcss, blazor
helpafamily
Impactful ways to help families in need through donated meals, hygiene kits, and more. By Margarita Humanitarian Foundation.
Stars: ✭ 41 (+51.85%)
Mutual labels:  tailwindcss
sage-vue-tailwind
Sage 10 with laravel mix, tailwindcss and vuejs https://roots.io/sage/
Stars: ✭ 38 (+40.74%)
Mutual labels:  tailwindcss
wrapped
GitHub Wrapped, inspired by Spotify Wrapped
Stars: ✭ 159 (+488.89%)
Mutual labels:  tailwindcss
next-pwa-template
Next.js progressive web app template
Stars: ✭ 266 (+885.19%)
Mutual labels:  tailwindcss
petal components
Phoenix Live View Components
Stars: ✭ 138 (+411.11%)
Mutual labels:  tailwindcss
nextal
Starter template for NextJs with TypeScript. Supports Tailwind with CSS-Modules. Jest and @react/testing-library configured and ready to go. Also ESLint, Prettier, Husky, Commit-lint and Atomic Design for components.
Stars: ✭ 88 (+225.93%)
Mutual labels:  tailwindcss
FableStarter
An Elmish F# Fable template that uses Tailwind for styling and the Parcel bundler
Stars: ✭ 13 (-51.85%)
Mutual labels:  tailwindcss
tailpress
A Tailwind CSS enabled Underscores theme
Stars: ✭ 60 (+122.22%)
Mutual labels:  tailwindcss
vitawind
Install and Setting Tailwindcss automatically for Vite
Stars: ✭ 46 (+70.37%)
Mutual labels:  tailwindcss
sapper-postcss-template
A template that includes Sapper for Svelte and PostCSS preprocessing with Tailwind CSS
Stars: ✭ 84 (+211.11%)
Mutual labels:  tailwindcss
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (+262.96%)
Mutual labels:  blazor
vue-3-stackter
A Vue3 starter project setup with Vite, Vue-meta, Router, Vuex, Eslint, Prettier, Tailwind CSS, and some custom preferences. Also, there is a TypeScript branch of this same setup.
Stars: ✭ 93 (+244.44%)
Mutual labels:  tailwindcss
jefftriplett.github.io
📝 My blog which is held together by duct tape and bailer twine
Stars: ✭ 14 (-48.15%)
Mutual labels:  tailwindcss
markushatvan.com
Personal website and blog written from scratch with SvelteKit and TailwindCSS.
Stars: ✭ 82 (+203.7%)
Mutual labels:  tailwindcss
rails-starter-template
Opinionated Rails starter template using esbuild, tailwindcss, postgresql and hotwired.
Stars: ✭ 21 (-22.22%)
Mutual labels:  tailwindcss
vue-apicloud-cli
基于vue的APICloud脚手架
Stars: ✭ 44 (+62.96%)
Mutual labels:  tailwindcss
aymaneMx.com
🎨 my personal website, built with Nuxt.js & TailwindCSS and Vue-Notion.
Stars: ✭ 26 (-3.7%)
Mutual labels:  tailwindcss
nextly-template
Nextly Landing Page Template built with Next.js & TailwindCSS
Stars: ✭ 48 (+77.78%)
Mutual labels:  tailwindcss

Blazor and Tailwind CSS

Blazor is great and Tailwind CSS makes styling bearable.

In version 3 of Tailwind CSS, the setting for Blazor app got much easier, because a brand new standalone tailwind CLI has been released. No need for npm to be installed.

These notes may be useful for anyone who would like to test the Blazor&Tailwind connection.

(Add your own experience in the list below (or an issue))

Quick guide (windows)

  • Download tailwindcss-windows-x64.exe

  • Rename file to tw (not necessary, but makes life easier)

    • or you can add the location to Path variable in windows (like I did)
  • Open terminal in root of your project and: ./tw.exe init, this creates tailwind.config.js tailwind init

  • Inside the tailwind.config.js file insert this code below. It will watch for all HTML and razor files. Whenever a new tailwind class appears in them, tailwind CLI will re-generate your app.min.css file (more in next step)

    module.exports = {
    content: [
        './**/*.html',
        './**/*.razor',
    ],
    theme: {
    extend: {
        
        },
        },
    plugins: [],
    }
  • add tailwind directives to app.css. (place it after any imports)

    @tailwind base;
    @tailwind components;
    @tailwind utilities;
  • Now run tailwind watch with: ./tw -i .\wwwroot\css\app.css -o .\wwwroot\css\app.min.css --watch tailwind watch This takes your current CSS file (app.css), prepends its content to generated tailwind classes, and outputs app.min.css in the same folder.

  • Now change the path in index.html (or _Host.cshtml for Blazor server) to use app.min.css instead of app.css. It will look like this:

    <link href="css/app.min.css" rel="stylesheet" />
  • Add some tailwind class to test the functionality. This will fill background with green color. On hover, text color will change to amber and will get bigger.

      <h1 class="bg-green-500 hover:text-amber-300 text-lg hover:text-2xl">Hello, world!</h1>

    tailwind watch

Few notes and tips

  • (Let me know yours by creating an issue!)

  • For even quicker setting you can use CDN: <script src="https://cdn.tailwindcss.com"></script>

  • Tailwind playground is a great place to create prototypes. It is fast (you see changes instantly), vscode based and allows you to save your work.

  • tailwind build process is rather quick, but sometimes leaves a mess inside the CSS file. For example, it will keep all the classes that were previously used (but are not used anymore)

    • You can delete the app.min.css file at any time (it will generate it again).
    • You should use minified version in production: ./tw -i input.css -o output.css --minify
  • Tailwind and bootstrap have some clashing CSS classes (px-2 for example). If you need to keep both (I have to, because I am using a component library, which is based on bootstrap) you can use prefix for tailwind classes.

  • There is currently no tailwind package in the chocolatey package manager. You can vote for it here.

  • There is this a good extension for vscode, which brings pleasant experience from tailwind playground to your desktop. Just open root folder of your project (where the tailwind.config.js is).

  • I had a bad experience with dotnet hot reload when CSS files are regenerated. It does weird things, like not updating (even after Ctrl+R), serving older versions, etc.. You can turn off hot reloading with: dotnet watch --project . --no-hot-reload. I am in the progress of finding a better solution. Anybody knows it already?

  • If you want to build your CSS file every time you reload your project you can add the following into your .csproj file. You do have to change the command to set the input and output directories and the executable name and it should work. However it doesn't trigger on hot reloads so you have to reload manually.

    <Target Name="UpdateTailwindCSS" BeforeTargets="Compile">
      <Exec Command="./tailwindcss .\wwwroot\css\app.css -o .\wwwroot\css\app.min.css" ContinueOnError="true">
        <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
      </Exec>
      <Error Condition="'$(ErrorCode)' != '0'" Text="Error building CSS file"/>
    </Target>
  • If you're developing on machines with different OSs, you can add the build script down below into your .csproj file, and have different scripts run based on your operating system. Make sure you modify the paths to actually work. I recommend trying them out in your terminal first. Also make sure you download both the Linux and Windows executable if you're jumping between systems.

    <Target Name="UpdateTailwindCSS" BeforeTargets="Compile">
      <!-- The code below runs only on Linux operating systems -->
      <Exec Command="./tailwindcss -i Styles/app.css -o wwwroot/css/app.css" Condition="$([MSBuild]::IsOSPlatform('Linux'))" ContinueOnError="true">
        <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
      </Exec>
    
      <!-- The code below runs only on Windows operating systems -->
      <Exec Command=".\tailwindcss.exe -i Styles\app.css -o wwwroot\css\app.css" Condition="$([MSBuild]::IsOSPlatform('Windows'))" ContinueOnError="true">
        <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
      </Exec>
    
      <Error Condition="'$(ErrorCode)' != '0'" Text="Error building CSS"/>
    </Target>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].