You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `tailwind.config` file and `config` options are subject to the [merging strategy](#merging-strategy).
39
+
::callout{color="blue"icon="i-ph-info-duotone"}
40
+
The provided configurations will be merged using [defu's array function merger](https://github.com/nuxt-contrib/defu#array-function-merger).
40
41
::
41
42
42
43
### `tailwind.config`
43
44
44
-
If a `tailwind.config` file is present, it will be imported and used to overwrite the default configuration. All of the following file extensions will work by default: `.js`, `.cjs`, `.mjs`, and `.ts`. When not using the `.cjs` file extension, you need to use ESM syntax (see #549).
45
-
46
-
You can configure the path with the [configPath option](/getting-started/configuration#configpath).
45
+
If a `tailwind.config` file is present, it will be imported and used to overwrite the default configuration. All of the following file extensions will work by default: `.js`, `.cjs`, `.mjs`, and `.ts`. You can configure the path with the [`configPath` option](/getting-started/configuration#configpath).
47
46
48
47
::callout{color="blue"icon="i-ph-info-duotone"}
49
-
This config has the highest priority to overwrite the defaults and [tailwindcss.config](#config-option).
48
+
This config has the highest priority to overwrite the defaults and [`config` option](#config-option).
50
49
::
51
50
52
51
::code-group
52
+
53
53
```js [tailwind.config.js]
54
54
importcolorsfrom'tailwindcss/colors'
55
55
@@ -101,21 +101,25 @@ Learn more about the [Tailwind config](https://tailwindcss.com/docs/configuratio
101
101
102
102
You can also use your `nuxt.config` file to set your Tailwind config with the `tailwindcss.config` property:
// exclude test files if you keep them together with source
217
-
contentDefaults.filter(
218
-
c => c.endsWith('/**/*.{vue,js,ts}')
219
-
).map(
220
-
c => c.replace('/**/*.{vue,js,ts}', '/**/!(*.{test,spec,story}).{vue,js,ts}')
221
-
),
222
-
]
223
-
}
224
-
}
225
-
226
-
export default config
227
-
```
228
-
229
-
::callout{color="blue"icon="i-ph-info-duotone"}
230
-
This merging strategy of with a function only applies to `plugins` and `content` since the default value is defined as an `Array`.
231
-
::
232
-
233
-
### Safelisting classes
234
-
235
-
If you need to safelist classes and avoid the content purging system, you need to specify the `safelist` option:
236
-
237
-
```js{}[tailwind.config.js]
238
-
module.exports = {
239
-
// Safelisting some classes to avoid content purge
240
-
safelist: [
241
-
'safelisted',
242
-
{
243
-
pattern: /bg-(red|green|blue)-(100|200|300)/,
244
-
},
245
-
]
246
-
}
247
-
```
248
-
249
170
## Referencing in the application
250
171
251
172
It can often be useful to reference Tailwind configuration values at runtime, e.g. to access some of your theme values when dynamically applying inline styles in a component.
252
173
253
174
If you need resolved Tailwind config at runtime, you can enable the [exposeConfig](/getting-started/configuration#exposeconfig) option:
254
175
255
-
```js{}[nuxt.config]
256
-
export default {
176
+
```ts [nuxt.config]
177
+
exportdefaultdefineNuxtConfig({
178
+
// ...
257
179
tailwindcss: {
258
180
exposeConfig: true
259
181
}
260
-
}
182
+
})
261
183
```
262
184
263
185
Then, import where needed from `#tailwind-config`:
@@ -272,15 +194,16 @@ import { theme } from '#tailwind-config'
272
194
273
195
Please be aware this adds `~19.5KB` (`~3.5KB`) to the client bundle size. If you want to only import _really_ specific parts of your tailwind config, you can enable imports for each property in the config:
274
196
275
-
```js{}[nuxt.config]
276
-
export default {
197
+
```ts [nuxt.config]
198
+
exportdefaultdefineNuxtConfig({
199
+
// ...
277
200
tailwindcss: {
278
201
exposeConfig: {
279
202
level: 4,
280
203
alias: '#twcss'// if you want to change alias
281
204
}
282
205
}
283
-
}
206
+
})
284
207
```
285
208
286
209
```js
@@ -297,3 +220,29 @@ It is unlikely for `level` to ever be over 4 - the usual depth of a Tailwind con
297
220
::callout{color="blue"icon="i-ph-info-duotone"}
298
221
Named exports for properties below [root options](https://tailwindcss.com/docs/configuration#configuration-options) are prefixed with `_` (`_colors`, `_900`, `_2xl`) to ensure safe variable names. You can use default imports to provide any identifier or rename named imports using `as`. Properties with unsafe variable names (`spacing['1.5']`, `height['1/2']`, `keyframes.ping['75%, 100%']`) do not get exported individually.
299
222
::
223
+
224
+
## Tailwind CSS version
225
+
226
+
If you wish to use another version of Tailwind CSS (i.e., different from the one that would be installed with this module), you can simply do so using your package manager like so:
Be careful while downgrading Tailwind CSS as the module may also have changes compatible to specific minor versions! In such cases, be sure to go through the [release changelogs](https://github.com/nuxt-modules/tailwindcss/releases).
description: Authoring a module that builds on top of this module
4
+
---
5
+
6
+
If you wish to author a Nuxt module that extends and builds on top of `@nuxtjs/tailwindcss`, like providing custom configuration, hooks, etc., you can find the recommended way in this example.
Copy file name to clipboardExpand all lines: docs/content/3.examples/2.dark-mode.md
-1
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
---
2
2
title: Dark Mode
3
3
description: Example of enabling dark mode with the module.
4
-
toc: false
5
4
---
6
5
7
6
This is an example using the [Tailwind Dark Mode](https://tailwindcss.com/docs/dark-mode) with the help of [`@nuxtjs/color-mode`](https://github.com/nuxt-modules/color-mode) module.
0 commit comments