New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nuxt): allow configuring treeshakeable composables #19383
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! β€οΈ
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
,useServerHeadSafe
useSchemaOrg
defineOgImageStatic
,defineOgImageDynamic
,defineOgImageScreenshot
defineRobotMeta
There 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