Skip to content

Commit b785c33

Browse files
chore(update-plugins): Sat Apr 19 08:04:36 UTC 2025
1 parent 5856278 commit b785c33

File tree

1 file changed

+62
-13
lines changed

1 file changed

+62
-13
lines changed

content/plugins/tailwindcss.md

+62-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ editUrl: https://github.com/NativeScript/tailwind/tree/main/README.md
1313

1414
:::warning Warning
1515

16-
:warning: `@nativescript/core@8.2.0` 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.
16+
:warning: For **Tailwind CSS v3**, `@nativescript/core@8.2.0` 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.
1717

1818
:::
1919

@@ -32,23 +32,57 @@ Makes using [Tailwind CSS](https://tailwindcss.com/) in NativeScript a whole lot
3232

3333
:::tip Note
3434

35-
This guide assumes you are using `@nativescript/webpack@5.x` as some configuration is done automatically. If you have not upgraded yet, please read the docs below for usage with older `@nativescript/webpack` versions.
35+
This guide assumes you are using `@nativescript/webpack@5.x` 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).
3636

3737
:::
3838

39-
Install `@nativescript/tailwind` and `tailwindcss`
39+
### Tailwind CSS v4
40+
41+
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.
42+
43+
**Install dependencies:**
4044

4145
```cli
4246
npm install --save @nativescript/tailwind tailwindcss
4347
```
4448

45-
Generate a `tailwind.config.js` with
49+
**Import Tailwind:** Add the following to your `app.css` or `app.scss`:
50+
51+
```css
52+
@import 'tailwindcss';
53+
```
54+
55+
#### Upgrading from Tailwind CSS 3
56+
57+
**Update dependencies:**
58+
59+
```cli
60+
npm install --save tailwindcss@latest
61+
```
62+
63+
Open your `app.css` or `app.scss` and replace any existing Tailwind imports with:
64+
65+
```css
66+
@import 'tailwindcss';
67+
```
68+
69+
### Tailwind CSS v3
70+
71+
If you need to use Tailwind CSS v3, follow these steps:
72+
73+
**Install dependencies:**
74+
75+
```cli
76+
npm install --save @nativescript/tailwind tailwindcss
77+
```
78+
79+
**Generate `tailwind.config.js`:**
4680

4781
```cli
4882
npx tailwindcss init
4983
```
5084

51-
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.
85+
**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.**
5286

5387
```js
5488
// tailwind.config.js
@@ -83,7 +117,7 @@ module.exports = {
83117
}
84118
```
85119

86-
Change your `app.css` or `app.scss` to include the tailwind utilities
120+
**Include Tailwind directives:** Change your `app.css` or `app.scss` to include the tailwind directives:
87121

88122
```css
89123
@tailwind base;
@@ -95,35 +129,50 @@ Start using tailwind in your app.
95129

96130
### Using a custom PostCSS config
97131

98-
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:
132+
Manual PostCSS configuration is typically **not required** for **Tailwind CSS v4**. `@nativescript/tailwind` handles the necessary setup automatically.
133+
134+
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`:
135+
136+
```js
137+
// postcss.config.js (Example for v4 with other plugins)
138+
139+
module.exports = {
140+
plugins: [
141+
'@nativescript/tailwind', // Handles Tailwind v4 setup
142+
// Add other PostCSS plugins here
143+
'@csstools/postcss-is-pseudo-class',
144+
],
145+
}
146+
```
147+
148+
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.
99149

100150
```js
101-
// postcss.config.js
151+
// postcss.config.js (Example for v3 customization)
102152

103153
module.exports = {
104154
plugins: [
105155
['tailwindcss', { config: './tailwind.config.custom.js' }],
106156
'@nativescript/tailwind',
157+
// Add other PostCSS plugins here
107158
'@csstools/postcss-is-pseudo-class',
108159
],
109160
}
110161
```
111162

112-
:::tip Note
163+
:::tip Note (Tailwind CSS v3)
113164

114-
if you want to apply customizations to `tailwindcss` or `@nativescript/tailwind`, you will need to disable autoloading:
165+
If you want to apply customizations to `tailwindcss` or `@nativescript/tailwind` in v3 using a custom PostCSS config, you will need to disable autoloading:
115166

116167
```cli
117168
ns config set tailwind.autoload false
118169
```
119170

120-
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.
121-
122171
:::
123172

124173
## Usage with older @nativescript/webpack versions
125174

126-
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`.
175+
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.**
127176

128177
<details>
129178

0 commit comments

Comments
 (0)