Repository navigation
Replies: 5 comments 14 replies
|
Hi @jacobg, Thanks for the kind words about MazInputPhoneNumber! I think this is actually a misunderstanding about what The plugin does not register components The // main.ts — this is just theme + translations setup, nothing heavy
import { MazUi } from 'maz-ui/plugins/maz-ui'
import { mazUi } from '@maz-ui/themes'
import { en } from '@maz-ui/translations'
import 'maz-ui/styles'
app.use(MazUi, {
theme: { preset: mazUi },
translation: { locale: 'en', messages: { en } }
})This is required because MazInputPhoneNumber internally uses useTranslations(), which relies on this setup and consumes CSS variable tokens. Components are individually importable and tree-shakeable Just like in v3, you import only the components you need. Vite will tree-shake everything else — you're not loading the entire Maz UI library: <script setup lang="ts">
import MazInputPhoneNumber from 'maz-ui/components/MazInputPhoneNumber'
const phoneNumber = ref('')
</script>
<template>
<MazInputPhoneNumber v-model="phoneNumber" />
</template>Only MazInputPhoneNumber and its dependencies (like libphonenumber-js) end up in your bundle — nothing else from Maz UI. Bonus: true lazy loading with defineAsyncComponent If you want to go further and defer the download until the component is actually rendered (e.g. the form is not visible on initial page load), you can use defineAsyncComponent: <script setup lang="ts">
import { defineAsyncComponent } from 'vue'
const MazInputPhoneNumber = defineAsyncComponent(
() => import('maz-ui/components/MazInputPhoneNumber')
)
</script>This way, the component code + libphonenumber-js are only downloaded when the component is rendered for the first time. Combine this with route-level const routes = [
{
path: '/contact',
component: () => import('./pages/ContactForm.vue'),
},
]app.use() is only for lightweight theme/translation injection — no components are loaded. Individual imports are tree-shakeable (same as v3). For deferred loading, use defineAsyncComponent. |
|
Thank you @LouisMazel for the explanation. Are you saying the Vue.use bootstrap is still necessary with defineAsyncComponent? I think so, as it seems orthogonal. The component part I think is ok, because the routes are already loaded via async. But I'm still hoping to be able to move the maz ui bootstrap stuff to the specific component that uses the phone number input. It doesn't get used so often, and the benefits of keeping it out of main.js are: (1) cleaner app bootstrapping; and (2) there is still maz ui bootstrap code that needs to get loaded. Would it be possible to support an alternative lazy approach not at vue app creation time? Thanks again! |
|
Hi @jacobg, To answer your question directly: yes, installing the plugin in main.js is currently required, even if you lazy load all your components with I understand your use case, actually. You want zero Maz UI footprint in your main bundle until a component actually needs it. I'm going to develop something like a <script setup lang="ts">
import { mazUi } from '@maz-ui/theme/presets'
</script>
<template>
<MazUiProvider :theme="{ preset: mazUi }" :translations="{ locale: 'en' }">
<MazInputPhoneNumber v-model="phone" />
</MazUiProvider>
</template>This way, nothing related to Maz UI would be in your main.js and in your bundle entry, everything gets loaded only with the pages that need it. This won't be available immediately, but it's on my radar. I'll keep this discussion updated. What do you think about it? Sound good for you? |
|
You can already test or migrate to the new Let me know if you need documentation (https://github.com/LouisMazel/maz-ui/blob/develop/apps/docs/src/guide/maz-ui-provider.md) and if the solution is working for you! If all is good for you, I will release it in a stable version. |
Uh oh!
There was an error while loading. Please reload this page.
Our SPA uses Prime Vue as the main UI framework. We use Maz UI's phone number input, which is amazing and the best out there!
In v3, we can just import/bootstrap Maz UI in the form components that use the phone number input, and the vite bundler will automatically lazily dynamically load the Maz UI code just-in-time.
In v4, Maz UI seems to want to be bootstrapped into the Vue application right away. How can we delay that and just lazy load in the components where it's needed?
Thanks very much.
All reactions