Skip to content

angeldev96/tailwind-aspdotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotnet + tailwind

Steps to add Tailwind in ASP.NET 6 MVC Project:

Requirements:

  • NodeJS
  • .NET 6
  • Terminal Emulator (Works with Powershell in Windows and bash or zsh in Linux)

Step 1:

Create the project in Visual Studio or the dotnet CLI

Step 2:

Start a node project

npm init -y

Step 3:

Add Tailwind

npm install -D tailwindcss

Step 4:

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"
  }

Step 5:

Init the tailwind config file

npx tailwindcss init

Step 6:

Add modules to tailwind.config.json, this is for tailwind to style razor pages:

module.exports = {
    content: [
       './Pages/**/*.cshtml',
       './Views/**/*.cshtml'
],
    theme: {
        extend: {},
    },
    plugins: [],
}

Step 7:

Add input css to site.css in wwwroot/css

@tailwind base;
@tailwind components;
@tailwind utilities;

Step 8:

Add itemgroups 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>

Step 9:

Include the path to the CSS file in the _Layout.cshtml file (Or the other views you need to style with tailwind)

<link rel="stylesheet" href="~/css/styles.css" asp-append-version="true" />

About

Adding Tailwind in ASP.NET 6 MVC

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy