-
Notifications
You must be signed in to change notification settings - Fork 144
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
Have a discussion about the 3 different component naming conventions #94
Comments
I think the best option is example 2 |
With respect to Example 1, I came across this while looking into whether it could be tree-shaken properly: So if I'm understanding correctly, if we do end up going for Example 1's syntax, for tree-shaking to work correctly, imports will have to originate from the file where the component is implemented. Currently, the Select component is imported like so: Implementation is exported via an index file: // packages/headless/src/index.ts aliased as '@qwik-ui/headless'
export * as Select from './components/select/select' and then imported for usage: import { component$ } from '@builder.io/qwik'
import { Select } from '@qwik-ui/headless'
export default component$(() => {
return (
<Select.Root>
<Select.Trigger />
<Select.ListBox />
</Select.Root>
)
}) For it to be tree-shaken correctly, I believe import { component$ } from '@builder.io/qwik'
// select.tsx could be renamed index.tsx for it to be terser
// will become '@qwik-ui/headless/select' instead
import * as Select from '@qwik-ui/headless/select/select'
export default component$(() => {
return (
<Select.Root>
<Select.Trigger />
<Select.ListBox />
</Select.Root>
)
}) Personally, I prefer Example 1 as I find it a little nicer to not have to import multiple components. A little added benefit is that as I type |
Is example 1 tree-shakable and the other examples not? |
The difference between Example 2 and 3 is really just naming. Both are tree-shakable by default as each sub-component is its own export and the usage model for both of them would look like this: import { component$ } from '@builder.io/qwik'
import {
SelectRoot,
SelectTrigger,
SelectListBox
} from '@qwik-ui/headless'
// note that it doesn't have to be re-aliased like what I elaborated previously
// but you do have to import each sub-component individually
export default component$(() => {
return (
<SelectRoot>
<SelectTrigger />
<SelectListBox />
</SelectRoot>
)
}) Example 1 exports the sub-components as an object which is why it needs to be imported directly from the file where it is implemented or tree-shaking doesn't work. (this is assuming I understand evanw/esbuild#1420 correctly) |
I see, thanks for the clarification. |
Reference:
The text was updated successfully, but these errors were encountered: