This method works for Blazor Server and Blazor WebAssembly with hot reload, style isolation and tailwind jit compilation.
For this method you need added to path Tailwind CSS CLI binary. Read more about Standalone CLI.
Just create a StaticAssets folder in the root of your project with next structure.
StaticAssets
├──styles.css
├──tailwind.config.js
└──TailwindCli.targetsImport TailwindCli.targets into your .csproj file.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<Import Project="StaticAssets\TailwindCli.targets" />
</Project>Change your Pages/_Layout.cshtml file if you are using Blazor Server
or wwwroot/index.html file if you are using Blazor WebAssembly.
Add css link
<link href="css/styles.css" rel="stylesheet" />Run this command in the terminal (change {ProjectDirectory} to project directory). Actualy you can see the text of this command after calling dotnet build, dotnet run or dotnet watch.
cd {ProjectDirectory}/StaticAssets/ && tailwindcss -i styles.css -o {ProjectDirectory}/wwwroot/css/styles.css -wIf you are using github workflows with your project then you need to add additional step.
...
- name: Setup Tailwind CSS
run: |
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64
chmod +x tailwindcss-linux-x64
sudo mv tailwindcss-linux-x64 /usr/bin/tailwindcss
...Just create a StaticAssets folder in the root of your project with next structure.
StaticAssets
├──package.json
├──styles.css
├──tailwind.config.js
└──TailwindNpm.targetsImport TailwindNpm.targets into your .csproj file.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<Import Project="StaticAssets\TailwindNpm.targets" />
</Project>Change your Pages/_Layout.cshtml file if you are using Blazor Server
or wwwroot/index.html file if you are using Blazor WebAssembly.
Add css link
<link href="css/styles.css" rel="stylesheet" />Run this command in the terminal (change {ProjectDirectory} to project directory). Actualy you can see the text of this command after calling dotnet build, dotnet run or dotnet watch.
cd {ProjectDirectory}/StaticAssets/ && npx --no-install tailwindcss -i styles.css -o {ProjectDirectory}/wwwroot/css/styles.css -w