diff --git a/playground/pages/ignored.vue b/playground/pages/ignored.vue new file mode 100644 index 00000000..bf9e5211 --- /dev/null +++ b/playground/pages/ignored.vue @@ -0,0 +1,5 @@ + diff --git a/src/module.ts b/src/module.ts index 0e567f9e..433ddb0a 100644 --- a/src/module.ts +++ b/src/module.ts @@ -65,7 +65,7 @@ export default defineNuxtModule({ if (!nuxt.options.dev) { const validatorPath = await resolvePath(fileURLToPath(new URL('./runtime/validator', import.meta.url))) - const { useChecker, getValidator } = await import(isWindows ? pathToFileURL(validatorPath).href : validatorPath) + const { useChecker, getValidator, isIgnored } = await import(isWindows ? pathToFileURL(validatorPath).href : validatorPath) const validator = getValidator(options) const { checkHTML, invalidPages } = useChecker(validator, usePrettier, logLevel) @@ -88,6 +88,9 @@ export default defineNuxtModule({ if (route.contents.match(NuxtRedirectHtmlRegex)) { return } + if (isIgnored(route.route, moduleOptions.ignore)) { + return + } checkHTML(route.route, route.contents) }) }) diff --git a/test/module-prerender.test.ts b/test/module-prerender.test.ts index fe10736d..5350c9ce 100644 --- a/test/module-prerender.test.ts +++ b/test/module-prerender.test.ts @@ -20,7 +20,8 @@ await setup({ hooks: { 'modules:before'() { const nuxt = useNuxt() - nuxt.options.nitro.prerender = { routes: ['/', '/redirect'] } + nuxt.options.htmlValidator = { ignore: ['/ignored'] } + nuxt.options.nitro.prerender = { routes: ['/', '/ignored', '/redirect'] } }, }, }, @@ -57,4 +58,10 @@ describe('Nuxt prerender', () => { expect.stringContaining(' element must have as content'), ) }) + + it('ignores configured pages', () => { + expect(console.error).not.toHaveBeenCalledWith( + expect.stringContaining('/ignored'), + ) + }) })