From f6dad49af36015b7644d00d6e4bf4139c0fa0dab Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 29 Jul 2026 15:52:16 +0100 Subject: [PATCH] fix: avoid separate chunks for shared code --- nuxt.config.ts | 16 ++++++++++++++++ test/unit/bundle.spec.ts | 12 +++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/nuxt.config.ts b/nuxt.config.ts index 13a0ecdc..7a2f97db 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -267,6 +267,22 @@ export default defineNuxtConfig({ modulePreload: { polyfill: false, }, + rollupOptions: { + output: { + // Merge modules shared between the entry and lazy chunks into a + // single chunk (excluding /admin js) + advancedChunks: { + groups: [ + { + name: 'shared', + minShareCount: 2, + test: (id: string) => + !/[\\/](?:app[\\/](?:components|pages)[\\/]admin|shared[\\/](?:lex|cms)|node_modules[\\/](?:@formkit|@atproto|@atcute|multiformats|gsap|mediabunny|modern-screenshot))[\\/]/.test(id), + }, + ], + }, + }, + }, }, vue: { features: { diff --git a/test/unit/bundle.spec.ts b/test/unit/bundle.spec.ts index f4f68d65..6d60a04b 100644 --- a/test/unit/bundle.spec.ts +++ b/test/unit/bundle.spec.ts @@ -55,7 +55,7 @@ describe('project sizes', () => { expect .soft(roundToKilobytes(stats.client.totalBytes)) - .toMatchInlineSnapshot(`"290k"`) + .toMatchInlineSnapshot(`"288k"`) expect.soft(stats.client.files.map(f => f.replace(/\..*\.js/, '.js')).sort()) .toMatchInlineSnapshot(` [ @@ -87,14 +87,8 @@ describe('project sizes', () => { "_nuxt/ProseTr.js", "_nuxt/ProseUl.js", "_nuxt/SocialPost.js", - "_nuxt/defu.js", - "_nuxt/dist.js", "_nuxt/entry.js", - "_nuxt/nuxt.js", - "_nuxt/ready.js", - "_nuxt/route-composables.js", - "_nuxt/runtime-core.js", - "_nuxt/virtual_nuxt_node_modules_.js", + "_nuxt/shared.js", ] `) }) @@ -103,7 +97,7 @@ describe('project sizes', () => { stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) expect .soft(roundToKilobytes(stats.server.totalBytes, 10)) - .toMatchInlineSnapshot(`"2990k"`) + .toMatchInlineSnapshot(`"2970k"`) const modules = await analyzeSizes('node_modules/**/*', serverDir) expect -- 2.51.2