|
1 | 1 | --- |
2 | 2 | title: Introduction |
3 | | -description: 'Automatically validate Nuxt server-rendered HTML (SSR and SSG) to detect common issues with HTML that can lead to hydration errors, as well as improve accessibility and best practice.' |
| 3 | +description: "Automatically validate Nuxt server-rendered HTML (SSR and SSG) to detect common issues with HTML that can lead to hydration errors, as well as improve accessibility and best practice." |
4 | 4 | category: Getting started |
5 | | - |
6 | 5 | --- |
7 | 6 |
|
8 | | -<img src="/preview.png" class="light-img" /> |
9 | | -<img src="/preview-dark.png" class="dark-img" /> |
| 7 | +::u-container |
| 8 | + |
| 9 | +{class="block dark:hidden w-full rounded-xl shadow"} |
| 10 | +{class="hidden dark:block w-full rounded-xl shadow"} |
| 11 | + |
| 12 | +Validate your SSR/SSG HTML automatically to catch hydration and accessibility issues before they ship. |
10 | 13 |
|
11 | 14 | ## Key features |
12 | 15 |
|
13 | | -::list |
14 | | - - Zero-configuration required |
15 | | - - Helps reduce hydration errors |
16 | | - - Detects common accessibility mistakes |
17 | | -:: |
| 16 | +- Zero-configuration required |
| 17 | +- Helps reduce hydration errors |
| 18 | +- Detects common accessibility mistakes |
18 | 19 |
|
19 | 20 | This module configures [`html-validate`](https://html-validate.org/) to automatically validate Nuxt server-rendered HTML (SSR and SSG) to detect common issues with HTML that can lead to hydration errors, as well as improve accessibility and best practice. |
20 | 21 |
|
21 | 22 | ## Quick start |
22 | 23 |
|
23 | 24 | ### Install |
24 | | -```bash |
| 25 | + |
| 26 | +```bash [Terminal] |
25 | 27 | npx nuxi@latest module add html-validator |
26 | 28 | ``` |
27 | 29 |
|
28 | | -### nuxt.config.js |
29 | | - |
30 | | -::code-group |
31 | | - ```js [Nuxt 3] |
32 | | - defineNuxtConfig({ |
33 | | - modules: ['@nuxtjs/html-validator'] |
34 | | - }) |
35 | | - ``` |
36 | | - ```js {}[Nuxt 2.9+] |
37 | | - export default { |
38 | | - buildModules: ['@nuxtjs/html-validator'] |
39 | | - } |
40 | | - ``` |
41 | | - ```js [Nuxt < 2.9"> |
42 | | - export default { |
43 | | - // Install @nuxtjs/html-validator as dependency instead of devDependency |
44 | | - modules: ['@nuxtjs/html-validator'] |
45 | | - } |
46 | | - ``` |
| 30 | +### Configure Nuxt |
| 31 | + |
| 32 | +::tabs |
| 33 | +:::tabs-item{label="Nuxt 3"} |
| 34 | + |
| 35 | +```js |
| 36 | +defineNuxtConfig({ |
| 37 | + modules: ["@nuxtjs/html-validator"], |
| 38 | +}); |
| 39 | +``` |
| 40 | + |
| 41 | +::: |
| 42 | +:::tabs-item{label="Nuxt 2.9+"} |
| 43 | + |
| 44 | +```js |
| 45 | +export default { |
| 46 | + buildModules: ["@nuxtjs/html-validator"], |
| 47 | +}; |
| 48 | +``` |
| 49 | + |
| 50 | +::: |
| 51 | +:::tabs-item{label="Nuxt < 2.9"} |
| 52 | + |
| 53 | +```js |
| 54 | +export default { |
| 55 | + // Install @nuxtjs/html-validator as a dependency instead of devDependency |
| 56 | + modules: ["@nuxtjs/html-validator"], |
| 57 | +}; |
| 58 | +``` |
| 59 | + |
| 60 | +::: |
47 | 61 | :: |
48 | 62 |
|
49 | | -::alert{type="info"} |
50 | | -`html-validator` won't be added to your production bundle - it's just used in development and at build/generate time. |
| 63 | +::note |
| 64 | +`html-validator` won't be added to your production bundle — it's only used in development and at build/generate time. |
51 | 65 | :: |
52 | 66 |
|
53 | | -### Configuration (optional) |
| 67 | +## Configuration |
54 | 68 |
|
55 | | -`@nuxtjs/html-validator` takes four options. |
| 69 | +`@nuxtjs/html-validator` exposes four options: |
56 | 70 |
|
57 | 71 | - `usePrettier` enables prettier printing of your source code to show errors in-context. |
58 | 72 |
|
59 | | - ::alert |
| 73 | + ::tip |
60 | 74 | Consider not enabling this if you are using TailwindCSS, as prettier will struggle to cope with parsing the size of your HTML in development mode. |
61 | 75 | :: |
62 | 76 |
|
63 | 77 | - `logLevel` sets the verbosity to one of `verbose`, `warning` or `error`. It defaults to `verbose` in dev, and `warning` when generating. |
64 | 78 |
|
65 | | - ::alert |
66 | | - You can use this configuration option to turn off console logging for the `No HTML validation errors found for ...` message. |
| 79 | + ::note |
| 80 | + Use this option to turn off console logging for the `No HTML validation errors found for ...` message. |
67 | 81 | :: |
68 | 82 |
|
69 | 83 | - `failOnError` will throw an error after running `nuxt generate` if there are any validation errors with the generated pages. |
70 | 84 |
|
71 | | - ::alert |
| 85 | + ::tip |
72 | 86 | Useful in continuous integration. |
73 | 87 | :: |
74 | 88 |
|
75 | | -- `options` allows you to pass in `html-validate` options that will be merged with the default configuration |
| 89 | +- `options` allows you to pass in `html-validate` options that will be merged with the default configuration. |
76 | 90 |
|
77 | | - ::alert{type="info"} |
| 91 | + ::note |
78 | 92 | You can find more about configuring `html-validate` [here](https://html-validate.org/rules/index.html). |
79 | 93 | :: |
80 | 94 |
|
81 | 95 | **Defaults** |
82 | 96 |
|
83 | | -```js{}[nuxt.config.js] |
| 97 | +```js [nuxt.config.ts] |
84 | 98 | { |
85 | 99 | htmlValidator: { |
86 | 100 | usePrettier: false, |
87 | 101 | logLevel: 'verbose', |
88 | 102 | failOnError: false, |
89 | 103 | /** A list of routes to ignore (that is, not check validity for). */ |
90 | | - ignore: [/\.(xml|rss|json)$/], |
| 104 | + ignore: [/\\.(xml|rss|json)$/], |
91 | 105 | options: { |
92 | 106 | extends: [ |
93 | 107 | 'html-validate:document', |
@@ -115,3 +129,5 @@ npx nuxi@latest module add html-validator |
115 | 129 | **You're good to go!** |
116 | 130 |
|
117 | 131 | Every time you hard-refresh (server-render) a page in Nuxt, you will see any HTML validation issues printed in your server console. |
| 132 | + |
| 133 | +:: |
0 commit comments