Video of the tutorial: https://youtu.be/HndP-Yh8WKc
- NodeJS
- .NET 6
- Terminal Emulator (Works with Powershell in Windows and bash or zsh in Linux)
Create the project in Visual Studio or the dotnet CLI
Start a node project
npm init -y
Add Tailwindscss
npm install -D tailwindcss
Add script to package.json for the css output location
"scripts": {
"css:build": "npx tailwindcss -i ./wwwroot/css/site.css -o ./wwwroot/css/styles.css --minify"
}
Init the tailwind config file
npx tailwindcss init
Add modules to tailwind.config.json, this is for tailwinds to style razor pages:
module.exports = {
content: [
'./Pages/**/*.cshtml',
'./Views/**/*.cshtml'
],
theme: {
extend: {},
},
plugins: [],
}
Add input css to site.css in wwwroot/css
@tailwind base;
@tailwind components;
@tailwind utilities;
Add itemgroups in in the project under the .csproj file, this is for building the css before deploying:
<ItemGroup>
<UpToDateCheckBuilt Include="wwwroot/css/site.css" Set="Css" />
<UpToDateCheckBuilt Include="tailwind.config.js" Set="Css" />
</ItemGroup>
<Target Name="Tailwind" BeforeTargets="Build">
<Exec Command="npm run css:build"/>
</Target>
Include the path to the CSS file in the _Layout.cshtml file (Or the other views you need to style with tailwinds)
<link rel="stylesheet" href="~/css/styles.css" asp-append-version="true" />