diff --git a/src/type-generation.ts b/src/type-generation.ts index 20dfc47e2..e55baadff 100644 --- a/src/type-generation.ts +++ b/src/type-generation.ts @@ -55,14 +55,17 @@ export function enableVueI18nTypeGeneration( * * So far these hooks have been the most reliable way to fetch when the endpoint is ready to be used */ - nuxt.hook('vite:serverCreated', () => { - useNitro().hooks.hook('compiled', async () => { - try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - res = await (await fetch(nuxt.options.devServer.url + 'api/merged')).json() - void updateTemplates({ filter: template => template.filename === 'types/i18n-messages.d.ts' }) - } catch { - // console.log('fetch failed') + nuxt.hooks.hookOnce('vite:serverCreated', () => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + useNitro().hooks.afterEach(async e => { + if (e.name === 'dev:reload') { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + res = await (await fetch(nuxt.options.devServer.url + 'api/merged', { cache: 'no-cache' })).json() + await updateTemplates({ filter: template => template.filename === 'types/i18n-messages.d.ts' }) + } catch { + // console.log('fetch failed') + } } }) }) @@ -70,6 +73,7 @@ export function enableVueI18nTypeGeneration( addTypeTemplate({ filename: 'types/i18n-messages.d.ts', getContents: () => { + // console.log(res) if (res == null) return '' return `// generated by @nuxtjs/i18n @@ -109,7 +113,9 @@ export {}` nuxt.hook('builder:watch', async (_, path) => { const paths = nuxt.options._i18n.locales.flatMap(x => x.files.map(f => f.path)) if (!paths.includes(path) && !vueI18nConfigPaths.some(x => x.absolute.includes(path))) return - + // @ts-ignore + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + res = await (await fetch(nuxt.options.devServer.url + 'api/merged', { cache: 'no-cache' })).json() await updateTemplates({ filter: template => template.filename === 'types/i18n-messages.d.ts' }) }) }