fix(nuxt): handle pages with no content and log warning (#20373)

This commit is contained in:
Preet Mishra 2023-04-19 22:28:43 +05:30 committed by GitHub
parent 820fecd9ee
commit 48b48dec00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -109,7 +109,14 @@ export const PageMetaPlugin = createUnplugin((options: PageMetaPluginOptions) =>
} }
if (!hasMacro && !code.includes('export { default }') && !code.includes('__nuxt_page_meta')) { if (!hasMacro && !code.includes('export { default }') && !code.includes('__nuxt_page_meta')) {
if (!code) {
s.append(CODE_EMPTY + (options.dev ? CODE_HMR : ''))
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
console.error(`The file \`${pathname}\` is not a valid page as it has no content.`)
} else {
s.overwrite(0, code.length, CODE_EMPTY + (options.dev ? CODE_HMR : '')) s.overwrite(0, code.length, CODE_EMPTY + (options.dev ? CODE_HMR : ''))
}
return result() return result()
} }

0
test/fixtures/basic/pages/empty.ts vendored Normal file
View File