fix(nuxt): add type support for router composables without pages/ integration

This commit is contained in:
Daniel Roe 2023-05-22 14:48:08 +01:00
parent 2518cf8d37
commit 397c54c9db

View File

@ -64,6 +64,14 @@ export default defineNuxtModule({
}
})
// adds support for #vue-router alias (used for types) with and without pages integration
addTemplate({
filename: 'vue-router.d.ts',
getContents: () => `export * from '${useExperimentalTypedPages ? 'vue-router/auto' : 'vue-router'}'`
})
nuxt.options.alias['#vue-router'] = join(nuxt.options.buildDir, 'vue-router')
if (!nuxt.options.pages) {
addPlugin(resolve(distDir, 'app/plugins/router'))
addTemplate({
@ -78,6 +86,12 @@ export default defineNuxtModule({
return
}
addTemplate({
filename: 'vue-router.mjs',
// TODO: use `vue-router/auto` when we have support for page metadata
getContents: () => 'export * from \'vue-router\';'
})
if (useExperimentalTypedPages) {
const declarationFile = './types/typed-router.d.ts'
@ -261,17 +275,6 @@ export default defineNuxtModule({
}
})
// adds support for #vue-router alias
addTemplate({
filename: 'vue-router.mjs',
// TODO: use `vue-router/auto` when we have support for page metadata
getContents: () => 'export * from \'vue-router\';'
})
addTemplate({
filename: 'vue-router.d.ts',
getContents: () => `export * from '${useExperimentalTypedPages ? 'vue-router/auto' : 'vue-router'}'`
})
// Add routes template
addTemplate({
filename: 'routes.mjs',
@ -365,8 +368,6 @@ export default defineNuxtModule({
filePath: resolve(distDir, 'pages/runtime/page')
})
nuxt.options.alias['#vue-router'] = join(nuxt.options.buildDir, 'vue-router')
// Add declarations for middleware keys
nuxt.hook('prepare:types', ({ references }) => {
references.push({ path: resolve(nuxt.options.buildDir, 'types/middleware.d.ts') })