Tri Nguyen
Tri Nguyen

Intro

In this post I would like to document how I integrate Tailwind CSS with Blazor project.

Steps

npm init

This creates a new package.json file.

NPM init
npm install tailwindcss postcss autoprefixer postcss-cli
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}
npx tailwindcss init
@tailwind base;
@tailwind components;
@tailwind utilities;
{
  "name": "hintdesk.clipboard.web",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "buildcss": "postcss wwwroot/css/app.css -o wwwroot/css/app.min.css",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "autoprefixer": "^10.4.2",
    "postcss": "^8.4.8",
    "postcss-cli": "^9.1.0",
    "tailwindcss": "^3.0.23"
  }
}
npm run buildcss
app.min.css
module.exports = {
  content: [
    './**/*.html',
    './**/*.razor'
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
npm run buildcss
Post-build event
<link href="css/app.min.css" rel="stylesheet" />

Comments

If you have any question, you can start a new discussion.