Skip to content

Commit 295fea9

Browse files
Merge pull request #315 from jwthomson/recipe-add-tailwind
Update "add-tailwind" recipe for SAFE v5
2 parents 799e57a + bca5fbd commit 295fea9

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

docs/recipes/ui/add-tailwind.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# How do I add Tailwind to a SAFE project?
2+
3+
[Tailwind](https://tailwindcss.com/) is a utility-first CSS framework which can be composed to build any design, directly in your markup.
4+
5+
As of SAFE version 5 (released in December 2023) it is included in the template by default so it can be used straight away.
6+
7+
If you are are using the minimal template or if you are upgrading from an old version of SAFE, continue reading for installation instructions.
8+
9+
1. [Add a stylesheet](https://safe-stack.github.io/docs/recipes/ui/add-style/) to the project
10+
11+
1. Install the required npm packages
12+
```shell
13+
npm install -D tailwindcss postcss autoprefixer
14+
```
15+
1. Initialise a `tailwind.config.js`
16+
```shell
17+
npx tailwindcss init
18+
```
19+
1. Amend the `tailwind.config.js` as follows
20+
```javascript
21+
/** @type {import('tailwindcss').Config} */
22+
module.exports = {
23+
mode: "jit",
24+
content: [
25+
"./index.html",
26+
"./**/*.{fs,js,ts,jsx,tsx}",
27+
],
28+
theme: {
29+
extend: {},
30+
},
31+
plugins: [],
32+
}
33+
```
34+
35+
1. Create a `postcss.config.js` with the following
36+
```javascript
37+
module.exports = {
38+
plugins: {
39+
tailwindcss: {},
40+
autoprefixer: {},
41+
}
42+
}
43+
```
44+
45+
1. Add the Tailwind layers to your stylesheet
46+
```css
47+
@tailwind base;
48+
@tailwind components;
49+
@tailwind utilities;
50+
```
51+
52+
1. In the `src/Client` folder find the code in `Index.fs` to show the list of todos and add a Tailwind text colour class(text-red-200)
53+
```fsharp
54+
for todo in model.Todos do
55+
Html.li [
56+
prop.classes [ "text-red-200" ]
57+
prop.text todo.Description
58+
]
59+
```
60+
61+
You should see some nice red "to-do"s proving that Tailwind is now in your project.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ nav:
7373
- Remove FAKE: "recipes/build/remove-fake.md"
7474
- Package my SAFE app for deployment: "recipes/build/bundle-app.md"
7575
- UI:
76+
- Add Tailwind support: "recipes/ui/add-tailwind.md"
7677
- Add daisyUI support: "recipes/ui/add-daisyui.md"
7778
- Add Feliz support: "recipes/ui/add-feliz.md"
7879
- Add FontAwesome support: "recipes/ui/add-fontawesome.md"

0 commit comments

Comments
 (0)