Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/content/2.guide/3.directory-structure/4.components.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ Use a slot as fallback until `<ClientOnly>` is mounted on client side.
</template>
```

::alert{type=warning}
<!-- TODO: Add back after passing treeshakeClientOnly experiment -->
<!-- ::alert{type=warning}
Make sure not to _nest_ `<ClientOnly>` components or other client-only components. Nuxt performs an optimization to remove the contents of these components from the server-side render, which can break in this case.
::
:: -->

## Library Authors

Expand Down
8 changes: 6 additions & 2 deletions packages/nuxt/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export default defineNuxtModule<ComponentsOptions>({
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) => {
Expand All @@ -147,7 +149,9 @@ export default defineNuxtModule<ComponentsOptions>({
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 }))
}
})
})
}
Expand Down
6 changes: 6 additions & 0 deletions packages/schema/src/config/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
3 changes: 2 additions & 1 deletion test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default defineNuxtConfig({
}
},
experimental: {
reactivityTransform: true
reactivityTransform: true,
treeshakeClientOnly: true
}
})