feat(nuxt): respect custom `dir.pages` in page placeholder (#20079)

This commit is contained in:
Daniel Roe 2023-04-04 14:18:29 +01:00 committed by GitHub
parent bf8fe61b33
commit bc9c7dcac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -278,7 +278,10 @@ export const publicPathTemplate: NuxtTemplate = {
export const nuxtConfigTemplate = {
filename: 'nuxt.config.mjs',
getContents: (ctx: TemplateContext) => {
return Object.entries(ctx.nuxt.options.app).map(([k, v]) => `export const ${camelCase('app-' + k)} = ${JSON.stringify(v)}`).join('\n\n')
return [
...Object.entries(ctx.nuxt.options.app).map(([k, v]) => `export const ${camelCase('app-' + k)} = ${JSON.stringify(v)}`),
`export const devPagesDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.dir.pages) : 'null'}`
].join('\n\n')
}
}

View File

@ -1,10 +1,12 @@
import { defineComponent } from 'vue'
// @ts-expect-error virtual file
import { devPagesDir } from '#build/nuxt.config.mjs'
export default defineComponent({
name: 'NuxtPage',
setup (_, props) {
if (process.dev) {
console.warn('Create a Vue component in the `pages/` directory to enable `<NuxtPage>`')
console.warn(`Create a Vue component in the \`${devPagesDir}/\` directory to enable \`<NuxtPage>\``)
}
return () => props.slots.default?.()
}