mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
perf(nuxt): don't prefetch all global components (#7069)
This commit is contained in:
parent
fd6d1d4fbe
commit
a520185442
@ -130,6 +130,18 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Do not prefetch global components chunks
|
||||||
|
nuxt.hook('build:manifest', (manifest) => {
|
||||||
|
const sourceFiles = getComponents().filter(c => c.global).map(c => relative(nuxt.options.srcDir, c.filePath))
|
||||||
|
|
||||||
|
for (const key in manifest) {
|
||||||
|
if (manifest[key].isEntry) {
|
||||||
|
manifest[key].dynamicImports =
|
||||||
|
manifest[key].dynamicImports?.filter(i => !sourceFiles.includes(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Scan components and add to plugin
|
// Scan components and add to plugin
|
||||||
nuxt.hook('app:templates', async () => {
|
nuxt.hook('app:templates', async () => {
|
||||||
const newComponents = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
const newComponents = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
||||||
|
@ -380,6 +380,13 @@ describe('prefetching', () => {
|
|||||||
it('should prefetch components', async () => {
|
it('should prefetch components', async () => {
|
||||||
await expectNoClientErrors('/prefetch/components')
|
await expectNoClientErrors('/prefetch/components')
|
||||||
})
|
})
|
||||||
|
it('should not prefetch certain dynamic imports by default', async () => {
|
||||||
|
const html = await $fetch('/auth')
|
||||||
|
// should not prefetch global components
|
||||||
|
expect(html).not.toMatch(/<link [^>]*\/_nuxt\/TestGlobal[^>]*\.js"/)
|
||||||
|
// should not prefetch all other pages
|
||||||
|
expect(html).not.toMatch(/<link [^>]*\/_nuxt\/navigate-to[^>]*\.js"/)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (process.env.NUXT_TEST_DEV) {
|
if (process.env.NUXT_TEST_DEV) {
|
||||||
|
Loading…
Reference in New Issue
Block a user