diff --git a/docs/content/2.guide/3.directory-structure/4.components.md b/docs/content/2.guide/3.directory-structure/4.components.md index 41b7686e82..d344277d54 100644 --- a/docs/content/2.guide/3.directory-structure/4.components.md +++ b/docs/content/2.guide/3.directory-structure/4.components.md @@ -174,9 +174,10 @@ Use a slot as fallback until `` is mounted on client side. ``` -::alert{type=warning} + + ## Library Authors diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index a601af92bb..3f394b162c 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -137,7 +137,9 @@ export default defineNuxtModule({ getComponents, mode: isClient ? 'client' : 'server' })) - config.plugins.push(TreeShakeTemplatePlugin.vite({ sourcemap: nuxt.options.sourcemap, getComponents })) + if (nuxt.options.experimental.treeshakeClientOnly) { + config.plugins.push(TreeShakeTemplatePlugin.vite({ sourcemap: nuxt.options.sourcemap, getComponents })) + } }) nuxt.hook('webpack:config', (configs) => { configs.forEach((config) => { @@ -147,7 +149,9 @@ export default defineNuxtModule({ getComponents, mode: config.name === 'client' ? 'client' : 'server' })) - config.plugins.push(TreeShakeTemplatePlugin.webpack({ sourcemap: nuxt.options.sourcemap, getComponents })) + if (nuxt.options.experimental.treeshakeClientOnly) { + config.plugins.push(TreeShakeTemplatePlugin.webpack({ sourcemap: nuxt.options.sourcemap, getComponents })) + } }) }) } diff --git a/packages/schema/src/config/experimental.ts b/packages/schema/src/config/experimental.ts index 38ea46164c..0c6709eb36 100644 --- a/packages/schema/src/config/experimental.ts +++ b/packages/schema/src/config/experimental.ts @@ -24,5 +24,11 @@ export default { * @see https://github.com/nuxt/framework/issues/4084 */ externalVue: false, + + /** + * Tree shakes contents of client-only components from server bundle + * @see https://github.com/nuxt/framework/pull/5750 + */ + treeshakeClientOnly: false, } } diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 93c21696cd..ed29626bc2 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -28,6 +28,7 @@ export default defineNuxtConfig({ } }, experimental: { - reactivityTransform: true + reactivityTransform: true, + treeshakeClientOnly: true } })