Skip to content

Commit ccbd473

Browse files
authoredMar 8, 2023
docs: update config hook
1 parent ee1bd7f commit ccbd473

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed
 

‎docs/content/2.tailwind/1.config.md

+18-20
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
This module comes with a default Tailwind configuration file to provide the best possible user experience.
44

5-
---
6-
75
## Default configuration
86

9-
```js{}[tailwind.config.js]
7+
```js [tailwind.config.js]
108
{
119
theme: {},
1210
plugins: [],
@@ -35,9 +33,7 @@ You can extend the default configuration:
3533
- with the `tailwindcss:config` Nuxt hook
3634

3735
::alert{type="warning"}
38-
3936
The `tailwind.config` file and `config` options are subject to the [merging strategy](#merging-strategy).
40-
4137
::
4238

4339
### `tailwind.config`
@@ -67,7 +63,7 @@ export default {
6763
}
6864
```
6965

70-
```ts{}[tailwind.config.ts]
66+
```ts [tailwind.config.ts]
7167
import type { Config } from 'tailwindcss'
7268
import defaultTheme from 'tailwindcss/defaultTheme'
7369

@@ -82,7 +78,7 @@ export default <Partial<Config>>{
8278
}
8379
```
8480

85-
```js{}[tailwind.config.cjs]
81+
```js [tailwind.config.cjs]
8682
const defaultTheme = require('tailwindcss/defaultTheme')
8783

8884
module.exports = {
@@ -118,36 +114,38 @@ export default {
118114
```
119115

120116
::alert{type="info"}
121-
122117
This config has less priority over the [tailwind.config.js](#tailwindconfigjs) file.
123-
124118
::
125119

126120
### `tailwindcss:config` hook
127121

128122
::alert{type="warning"}
129-
130123
This is an advanced usage section and intended primarily for Nuxt modules authors.
131-
132124
::
133125

134126
You can use a [Nuxt hook](https://nuxtjs.org/guides/directory-structure/modules#run-tasks-on-specific-hooks) to extend the Tailwind configuration:
135127

136-
```js
137-
// ~/modules/nuxt-tailwind-typo/index.js
128+
```ts
129+
// ~/modules/nuxt-tailwind-typo/index.ts
130+
import { defineNuxtModule } from '@nuxt/kit'
138131
import tailwindTypography from '@tailwindcss/typography'
139132

140-
export default function () {
141-
this.nuxt.hook('tailwindcss:config', function (tailwindConfig) {
142-
tailwindConfig.plugins.push(tailwindTypography)
143-
})
144-
}
133+
export default defineNuxtModule({
134+
meta: {
135+
name: 'nuxt-tailwind-typo'
136+
},
137+
setup (options, nuxt) {
138+
nuxt.hook('tailwindcss:config', function (tailwindConfig) {
139+
tailwindConfig.plugins.push(tailwindTypography)
140+
})
141+
}
142+
})
145143
```
146144

147-
::alert{type="info"}
145+
Learn more about [Nuxt modules](https://nuxt.com/docs/guide/directory-structure/modules).
148146

147+
::alert{type="info"}
149148
This hook can be asynchronous (using `async/await`) and is called after merging the configurations and right before calling the PostCSS Tailwind plugin.
150-
151149
::
152150

153151
### Merging strategy

0 commit comments

Comments
 (0)
Please sign in to comment.