Skip to content

Commit 8e339d1

Browse files
docs: tailwind 4 notes to readme (#198)
1 parent 54f6e62 commit 8e339d1

File tree

1 file changed

+62
-12
lines changed

1 file changed

+62
-12
lines changed

README.md

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @nativescript/tailwind
22

3-
> **Warning**: :warning: `@nativescript/[email protected]` is required for colors to work properly You may see wrong colors on older core versions, because Tailwind CSS v3 uses the RGB/A color notation, which has been implemented for 8.2.0 and prior versions don't support it.
3+
> **Warning**: :warning: For **Tailwind CSS v3**, `@nativescript/[email protected]` is required for colors to work properly. You may see wrong colors on older core versions, because Tailwind CSS v3 uses the RGB/A color notation, which has been implemented for 8.2.0. **Tailwind CSS v4** uses Lightning CSS which handles this automatically.
44
55
Makes using [Tailwind CSS](https://tailwindcss.com/) in NativeScript a whole lot easier!
66

@@ -15,21 +15,55 @@ Makes using [Tailwind CSS](https://tailwindcss.com/) in NativeScript a whole lot
1515

1616
## Usage
1717

18-
> **Note:** This guide assumes you are using `@nativescript/[email protected]` as some configuration is done automatically. If you have not upgraded yet, please read the docs below for usage with older `@nativescript/webpack` versions.
18+
> **Note:** This guide assumes you are using `@nativescript/[email protected]` or higher. If you have not upgraded yet, please read the docs below for usage with older `@nativescript/webpack` versions (applicable to Tailwind CSS v3).
1919
20-
Install `@nativescript/tailwind` and `tailwindcss`
20+
### Tailwind CSS v4
21+
22+
If you need to use Tailwind CSS v4, follow these steps. Tailwind CSS v4 [support](https://github.com/NativeScript/tailwind/pull/194) simplifies the setup significantly over v3.
23+
24+
**Install dependencies:**
25+
26+
```cli
27+
npm install --save @nativescript/tailwind tailwindcss
28+
```
29+
30+
**Import Tailwind:** Add the following to your `app.css` or `app.scss`:
31+
32+
```css
33+
@import 'tailwindcss';
34+
```
35+
36+
#### Upgrading from Tailwind CSS 3
37+
38+
**Update dependencies:**
39+
40+
```cli
41+
npm install --save tailwindcss@latest
42+
```
43+
44+
Open your `app.css` or `app.scss` and replace any existing Tailwind imports with:
45+
46+
```css
47+
@import 'tailwindcss';
48+
```
49+
50+
### Tailwind CSS v3
51+
52+
If you need to use Tailwind CSS v3, follow these steps:
53+
54+
**Install dependencies:**
2155

2256
```cli
2357
npm install --save @nativescript/tailwind tailwindcss
2458
```
2559

26-
Generate a `tailwind.config.js` with
60+
**Generate `tailwind.config.js`:**
2761

2862
```cli
2963
npx tailwindcss init
3064
```
3165

32-
When the [NativeScript CLI](https://github.com/NativeScript/nativescript-cli) creates a new project, it may put code into a `src` folder instead of the `app` referenced below. Adjust `content`, `darkMode`, `corePlugins` plus any other settings you need. Here are the values we recommend. If you're struggling to get Tailwind working for the first time, check the `content` setting.
66+
**Configure `tailwind.config.js`:** When the [NativeScript CLI](https://github.com/NativeScript/nativescript-cli) creates a new project, it may put code into a `src` folder instead of the `app` referenced below. Adjust `content`, `darkMode`, `corePlugins` plus any other settings you need. Here are the values we recommend. **If you're struggling to get Tailwind working for the first time, check the `content` setting.**
3367

3468
```js
3569
// tailwind.config.js
@@ -66,7 +100,7 @@ module.exports = {
66100
}
67101
```
68102

69-
Change your `app.css` or `app.scss` to include the tailwind utilities
103+
**Include Tailwind directives:** Change your `app.css` or `app.scss` to include the tailwind directives:
70104

71105
```css
72106
@tailwind base;
@@ -78,30 +112,46 @@ Start using tailwind in your app.
78112

79113
### Using a custom PostCSS config
80114

81-
In case you need to customize the postcss configuration, you can create a `postcss.config.js` (other formats are supported, see https://github.com/webpack-contrib/postcss-loader#config-files) file and add any customizations, for example:
115+
Manual PostCSS configuration is typically **not required** for **Tailwind CSS v4**. `@nativescript/tailwind` handles the necessary setup automatically.
116+
117+
However, if you need to add *other* PostCSS plugins alongside Tailwind v4, create a `postcss.config.js` (or other supported formats, see https://github.com/webpack-contrib/postcss-loader#config-files) and include `@nativescript/tailwind`:
118+
119+
```js
120+
// postcss.config.js (Example for v4 with other plugins)
121+
122+
module.exports = {
123+
plugins: [
124+
"@nativescript/tailwind", // Handles Tailwind v4 setup
125+
// Add other PostCSS plugins here
126+
"@csstools/postcss-is-pseudo-class"
127+
],
128+
};
129+
```
130+
131+
For **Tailwind CSS v3**, if you need to customize the postcss configuration (e.g., use a custom `tailwind.config.custom.js`), you can create a `postcss.config.js` file.
82132

83133
```js
84-
// postcss.config.js
134+
// postcss.config.js (Example for v3 customization)
85135

86136
module.exports = {
87137
plugins: [
88138
["tailwindcss", { config: "./tailwind.config.custom.js" }],
89139
"@nativescript/tailwind",
90-
"@csstools/postcss-is-pseudo-class"
140+
// Add other PostCSS plugins here
141+
"@csstools/postcss-is-pseudo-class"
91142
],
92143
};
93144
```
94145

95-
> **Note:** if you want to apply customizations to `tailwindcss` or `@nativescript/tailwind`, you will need to disable autoloading:
146+
> **Note (Tailwind CSS v3):** If you want to apply customizations to `tailwindcss` or `@nativescript/tailwind` in v3 using a custom PostCSS config, you will need to disable autoloading:
96147
>
97148
> ```cli
98149
> ns config set tailwind.autoload false
99150
> ```
100-
> This is required only if you make changes to either of the 2 plugins - because by default `postcss-loader` processes the config file first, and then the `postcssOptions` passed to it. With autoloading enabled, any customizations will be overwritten due to the loading order. Setting `tailwind.autoload` to `false` just disables the internal loading of these plugins, and requires you to manually add them to your postcss config in the above order.
101151
102152
## Usage with older @nativescript/webpack versions
103153
104-
This usage is considered legacy and will not be supported - however we are documenting it here in case your project is still using older `@nativescript/webpack`.
154+
This usage is considered legacy and will not be supported - however we are documenting it here in case your project is still using older `@nativescript/webpack`. **This applies to Tailwind CSS v3 setups.**
105155
106156
<details>
107157

0 commit comments

Comments
 (0)