Quickly get a live set up using TailwindCSS and .NET web projects in Visual Studio 2022
$ dotnet add package TailwindLiveMake sure you have git bash, npm, and node installed on your local machine. Hot reload also needs to be enabled in VS2022. Works with RazorPages and Blazor Server .NET 8
Make sure Hot Reload on File Save is checked!

To help refreshing, also install the following extension for autosaving AutoSaveFile. 3 seconds for the save setting seems to work great.
For IntelliSense use the following extension Tailwind CSS VS2022 Editor Support.
Install TailwindCSS:
package.json file:npm init -y
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
tailwind.config.js and postcss.config.js files.Configure TailwindCSS:
Edit the tailwind.config.js file:
module.exports = {
content: ["./**/*.{html,cshtml,razor,js}"],
theme: {
extend: {},
},
plugins: [],
}
Create a css folder in the wwwroot directory.
Inside the css folder, create a tailwind.css file and replace with the following content:
@tailwind base;
@tailwind components;
@tailwind utilities;
Inside the css folder, create a app-tailwind.css blank file.
Add these scripts to your package.json to build and watch TailwindCSS
"scripts": {
"build:css": "tailwindcss build -i ./wwwroot/css/tailwind.css -o ./wwwroot/css/app-tailwind.css",
"watch:css": "tailwindcss -i ./wwwroot/css/tailwind.css -o ./wwwroot/css/app-tailwind.css --watch"
},
Install TailwindLive from nuget.
<div class="mb-2 text-xl font-bold text-cyan-300 dark:text-light-100">This is Tailwind CSS</div>
For Razor Pages add the following in the head element /Pages/Shared/Layout.cshtml
<link href="~/css/app-tailwind.css" rel="stylesheet" />
For Blazor add the following in the head element /Components/App.razor
<link href="/css/app-tailwind.css" rel="stylesheet" />
Then add the following to your Program.cs
if (app.Environment.IsDevelopment())
{
app.UseGitBashMiddleware(new MiddlewareOptions
{
GitBashExe = "c:\\path\\to\\git-bash.exe",
WorkingDirectory = Environment.CurrentDirectory,
NpmBuildArguments = "-c \"npm run build:css\"", //Change these if you named your scripts differently
NpmWatchArguments = "-c \"npm run watch:css\""
});
}