feat(nuxt): allow configuring treeshakeable composables#19383
Conversation
|
|
|
Interesting idea! However, I have a few questions:
In that sense, I think I would push back for the current implementation as I see the trade-off is not worth it. People better use |
Thanks for the detailed review! Good points I agree that it could be a useful feature but the limitations open the scope for too many issues. I'd like to see it in Nuxt one day but sounds like some work needs to go into Unimport first. I've minimised the scope of this PR to only make the treeShake config extendable which I think is more reasonable. |
Co-authored-by: Daniel Roe <daniel@roe.dev>
…les' into feat/server-client-only-composables
|
Merging so @harlan-zw can go ahead with linked PR. But would particularly appreciate feedback @antfu on the schema change in this PR. If we do end up supporting something like this in unimport down the line, does it give you enough info? (it's in the preset format, so (Happy to change the schema before we release v3.3 if you have any suggestions for improvement.) |
🔗 Linked issue
Not an issue but to unblock me on #19302
❓ Type of change
📚 Description
Background
Isolating composables to a specific environment is a useful way to optimise bundles. There are many instances of code that only need to run on a single environment that are introduced through modules.
However, there isn't an easy way for modules to opt-in to this treeshaking config.
For example:
useServerHead,useServerSeoMeta,useServerHeadSafeuseSchemaOrgdefineOgImageStatic,defineOgImageDynamic,defineOgImageScreenshotdefineRobotMetaThere is currently a way to handle this by wrapping code in env if blocks. This works okay, but it means the function arguments won't be tree-shaken (afaik).
You can wrap the composable call itself but this gets pretty verbose quickly and is not something module authors have control over.
Solution
Make the treeShake config extendable by moving it to nuxt config.
📝 Checklist