From 8323220f74529b84c465d535c81921e31e084b1e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 9 Mar 2024 11:25:11 +0100 Subject: [PATCH] perf(nuxt): tree shake island renderer --- packages/nuxt/src/app/components/nuxt-root.vue | 4 +++- test/bundle.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/app/components/nuxt-root.vue b/packages/nuxt/src/app/components/nuxt-root.vue index cfbb1aaea9..9c8c91516e 100644 --- a/packages/nuxt/src/app/components/nuxt-root.vue +++ b/packages/nuxt/src/app/components/nuxt-root.vue @@ -24,8 +24,10 @@ import { useRoute, useRouter } from '../composables/router' import { PageRouteSymbol } from '../components/injections' import AppComponent from '#build/app-component.mjs' import ErrorComponent from '#build/error-component.mjs' +// @ts-expect-error virtual file +import { componentIslands } from '#build/nuxt.config.mjs' -const IslandRenderer = import.meta.server +const IslandRenderer = import.meta.server && componentIslands ? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r)) : () => null diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 9a26f20e1f..dd756d50d7 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -32,7 +32,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"205k"') + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"204k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"1335k"') @@ -72,7 +72,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output-inline/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"524k"') + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"523k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"78.0k"')