Skip to content

Commit 689b239

Browse files
authored
chore: update docs and add examples test ci (#853)
1 parent 5d5a857 commit 689b239

File tree

12 files changed

+115
-126
lines changed

12 files changed

+115
-126
lines changed

.github/workflows/ci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: ci
22

3+
env:
4+
NODE_OPTIONS: --max_old_space_size=6144
5+
36
on:
47
push:
58
branches:
@@ -24,3 +27,26 @@ jobs:
2427
- run: pnpm build
2528
# - run: pnpm test:types
2629
- run: pnpm dev:build
30+
examples:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/checkout@v4
35+
with:
36+
ref: docs-examples
37+
path: docs-examples
38+
sparse-checkout: |
39+
examples
40+
- run: corepack enable
41+
- uses: actions/setup-node@v4
42+
with:
43+
node-version: 20
44+
cache: "pnpm"
45+
- run: pnpm install && pnpm dev:prepare
46+
- run: pnpm link --global
47+
- run: echo " - \"docs-examples/examples/*\"" >> pnpm-workspace.yaml
48+
- run: echo " - \"!docs-examples/examples/nuxt-layers\"" >> pnpm-workspace.yaml
49+
- run: echo " - \"!docs-examples/examples/nuxtui\"" >> pnpm-workspace.yaml
50+
# - run: pnpm --filter './examples/**' link @nuxtjs/tailwindcss
51+
- run: pnpm install --no-frozen-lockfile
52+
- run: pnpm --filter "./docs-examples/examples/**" build

docs/content/1.getting-started/1.installation.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pnpm i -D @nuxtjs/tailwindcss
3030
2. If not already done, add it to your `modules` section in your `nuxt.config`:
3131

3232
::code-group
33+
3334
```ts [Nuxt 3]
3435
export default defineNuxtConfig({
3536
modules: ['@nuxtjs/tailwindcss']
@@ -41,6 +42,7 @@ export default {
4142
buildModules: ['@nuxtjs/tailwindcss']
4243
}
4344
```
45+
4446
::
4547

4648
::callout{color="green" icon="i-ph-check-circle-duotone"}
@@ -127,8 +129,9 @@ Learn more about overwriting the Tailwind configuration in the [Tailwind Config]
127129

128130
You can customize the module's behavior by using the `tailwindcss` property in `nuxt.config`:
129131

130-
```ts [nuxt.config.ts]
132+
```ts [nuxt.config]
131133
export default defineNuxtConfig({
134+
modules: ['@nuxtjs/tailwindcss'],
132135
tailwindcss: {
133136
// Options
134137
}

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

+68-119
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ description: This module comes with a default Tailwind configuration file to pro
55

66
## Default configuration
77

8-
```js [tailwind.config.js]
9-
export default {
10-
theme: {},
11-
plugins: [],
12-
content: [
13-
`${srcDir}/components/**/*.{vue,js,ts}`,
14-
`${srcDir}/layouts/**/*.vue`,
15-
`${srcDir}/pages/**/*.vue`,
16-
`${srcDir}/composables/**/*.{js,ts}`,
17-
`${srcDir}/plugins/**/*.{js,ts}`,
18-
`${srcDir}/utils/**/*.{js,ts}`,
19-
`${srcDir}/App.{js,ts,vue}`,
20-
`${srcDir}/app.{js,ts,vue}`,
21-
`${srcDir}/Error.{js,ts,vue}`,
22-
`${srcDir}/error.{js,ts,vue}`,
23-
`${srcDir}/app.config.{js,ts}`
24-
]
8+
When you install the module, the default Tailwind configuration for your project would be equivalent to this:
9+
10+
```json [tailwind.config]
11+
{
12+
"theme": { "extend": {} },
13+
"content": [
14+
// all directories and extensions will correspond to your Nuxt config
15+
"{srcDir}/components/**/*.{vue,js,jsx,mjs,ts,tsx}",
16+
"{srcDir}/layouts/**/*.{vue,js,jsx,mjs,ts,tsx}",
17+
"{srcDir}/pages/**/*.{vue,js,jsx,mjs,ts,tsx}",
18+
"{srcDir}/plugins/**/*.{js,ts,mjs}",
19+
"{srcDir}/composables/**/*.{js,ts,mjs}",
20+
"{srcDir}/utils/**/*.{js,ts,mjs}",
21+
"{srcDir}/{A,a}pp.{vue,js,jsx,mjs,ts,tsx}",
22+
"{srcDir}/{E,e}rror.{vue,js,jsx,mjs,ts,tsx}",
23+
"{srcDir}/app.config.{js,ts,mjs}"
24+
],
25+
"plugins": []
2526
}
2627
```
2728

@@ -33,23 +34,22 @@ You can extend the default configuration:
3334

3435
- with a [tailwind.config](#tailwindconfig) file
3536
- using the [config option](#config-option)
36-
- with the `tailwindcss:config` Nuxt hook
37+
- using [hooks](#hooks), such as the `tailwindcss:config`
3738

38-
::callout{color="amber" icon="i-ph-warning-duotone"}
39-
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).
4041
::
4142

4243
### `tailwind.config`
4344

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).
4746

4847
::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).
5049
::
5150

5251
::code-group
52+
5353
```js [tailwind.config.js]
5454
import colors from 'tailwindcss/colors'
5555

@@ -101,21 +101,25 @@ Learn more about the [Tailwind config](https://tailwindcss.com/docs/configuratio
101101

102102
You can also use your `nuxt.config` file to set your Tailwind config with the `tailwindcss.config` property:
103103

104-
```js [nuxt.config]
105-
import tailwindTypography from '@tailwindcss/typography'
104+
```ts [nuxt.config]
105+
import colors from 'tailwindcss/colors'
106106

107-
export default {
107+
export default defineNuxtConfig({
108108
// ...
109109
tailwindcss: {
110110
config: {
111-
plugins: [tailwindTypography]
111+
theme: {
112+
extend: {
113+
colors: { primary: colors.green }
114+
}
115+
}
112116
}
113117
}
114-
}
118+
})
115119
```
116120

117121
::callout{color="blue" icon="i-ph-info-duotone"}
118-
This config has less priority over the [tailwind.config.js](#tailwindconfigjs) file.
122+
This config option allows only simple primitive values, and has less priority over the [`tailwind.config`](#tailwindconfig) file(s).
119123
::
120124

121125
### Hooks
@@ -163,101 +167,19 @@ Learn more about [Nuxt modules](https://nuxt.com/docs/guide/directory-structure/
163167
These hooks can be asynchronous (using `async/await`) and are called after merging the configurations.
164168
::
165169

166-
### Merging strategy
167-
168-
The provided config will be merged using [defu's array function merger](https://github.com/nuxt-contrib/defu#array-function-merger).
169-
170-
When assigning an array to the `content` property, it will be concatenated with the default value.
171-
172-
**Example**
173-
174-
```js{}[tailwind.config.js]
175-
export default {
176-
content: [
177-
'content/**/*.md'
178-
]
179-
}
180-
```
181-
182-
The `content` option will be:
183-
184-
```js
185-
[
186-
'components/**/*.{vue,js,ts}',
187-
'layouts/**/*.vue',
188-
'pages/**/*.vue',
189-
'composables/**/*.{js,ts}',
190-
'plugins/**/*.{js,ts}',
191-
'App.{js,ts,vue}',
192-
'app.{js,ts,vue}',
193-
'Error.{js,ts,vue}',
194-
'error.{js,ts,vue}',
195-
'content/**/*.md'
196-
]
197-
```
198-
199-
If you want to fully overwrite its value, you can use a `function` that receives the default value:
200-
201-
```js{}[tailwind.config.ts]
202-
import type { ModuleOptions } from '@nuxtjs/tailwindcss'
203-
204-
const config: ModuleOptions['config'] = {
205-
content (contentDefaults) {
206-
return [
207-
// add the defaults
208-
...contentDefaults,
209-
210-
// or filter only vue file patterns from defaults
211-
...contentDefaults.filter((c) => c.endsWith('*.vue')),
212-
213-
// add js and vue files for a directory
214-
'./my-components/**/*.{js,vue}',
215-
216-
// 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-
249170
## Referencing in the application
250171

251172
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.
252173

253174
If you need resolved Tailwind config at runtime, you can enable the [exposeConfig](/getting-started/configuration#exposeconfig) option:
254175

255-
```js{}[nuxt.config]
256-
export default {
176+
```ts [nuxt.config]
177+
export default defineNuxtConfig({
178+
// ...
257179
tailwindcss: {
258180
exposeConfig: true
259181
}
260-
}
182+
})
261183
```
262184

263185
Then, import where needed from `#tailwind-config`:
@@ -272,15 +194,16 @@ import { theme } from '#tailwind-config'
272194

273195
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:
274196

275-
```js{}[nuxt.config]
276-
export default {
197+
```ts [nuxt.config]
198+
export default defineNuxtConfig({
199+
// ...
277200
tailwindcss: {
278201
exposeConfig: {
279202
level: 4,
280203
alias: '#twcss' // if you want to change alias
281204
}
282205
}
283-
}
206+
})
284207
```
285208

286209
```js
@@ -297,3 +220,29 @@ It is unlikely for `level` to ever be over 4 - the usual depth of a Tailwind con
297220
::callout{color="blue" icon="i-ph-info-duotone"}
298221
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.
299222
::
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:
227+
228+
229+
::code-group
230+
231+
```bash [yarn]
232+
yarn add -D [email protected]
233+
```
234+
235+
```bash [npm]
236+
npm install -D [email protected]
237+
```
238+
239+
```sh [pnpm]
240+
241+
```
242+
243+
::
244+
245+
::callout{color="amber" icon="i-ph-warning-duotone"}
246+
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).
247+
::
248+

docs/content/3.examples/1.basic.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Basic Usage
33
description: Example usage of the module.
4-
toc: false
54
---
65

76
This is a minimal example of a Nuxt project using the Tailwind CSS module.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Module Authoring
3+
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.
7+
8+
:sandbox{src="https://stackblitz.com/github/nuxt-modules/tailwindcss/tree/docs-examples/examples/module-authoring"}

docs/content/3.examples/2.dark-mode.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Dark Mode
33
description: Example of enabling dark mode with the module.
4-
toc: false
54
---
65

76
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.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Nuxt Layers
3+
description: Module working with Nuxt Layers
4+
---
5+
6+
In this example, the module works between different Nuxt Layers.
7+
8+
:sandbox{src="https://stackblitz.com/github/nuxt-modules/tailwindcss/tree/docs-examples/examples/nuxt-layers"}

docs/content/3.examples/5.postcss-config.md renamed to docs/content/3.examples/6.postcss-config.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: PostCSS Configuration
33
description: Example of customising PostCSS options for Nuxt.
4-
toc: false
54
---
65

76
<!-- TODO: Replace with another postcss plugin as tailwind supports gray colors natively. -->

docs/content/3.examples/6.daisyui.md renamed to docs/content/3.examples/7.daisyui.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: DaisyUI
33
description: Example of using the module with daisyUI and color mode.
4-
toc: false
54
---
65

76
Example with [daisyUI](https://daisyui.com/) and [`@nuxtjs/color-mode`](https://color-mode.nuxtjs.org/).

docs/content/3.examples/8.nuxt-ui.md renamed to docs/content/3.examples/9.nuxt-ui.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Nuxt UI
3-
description: Example of Nuxt UI.
4-
toc: false
3+
description: Example of Nuxt UI
54
---
65

76
Checkout [Nuxt UI](https://ui.nuxt.com) documentation.

0 commit comments

Comments
 (0)