From 97f88eaf2c5130de6d8ab6e1b74cafd60cf2ff2a Mon Sep 17 00:00:00 2001 From: Darko Gjorgjijoski Date: Sat, 4 Apr 2026 10:15:00 +0200 Subject: [PATCH] Fix build warnings: add isImageFile util, exclude heavy components from eager glob, clean up dynamic import conflicts - Add missing isImageFile() to format-money utils - Exclude BaseMultiselect, InvoicePublicPage, InvoiceInformationCard from eager glob in global-components.ts using negative patterns - Short-circuit English locale in i18n to avoid redundant dynamic import - Only en.json warning remains (intentional: English bundled inline) Co-Authored-By: Claude Opus 4.6 (1M context) --- resources/scripts-v2/global-components.ts | 43 +++++++++++++--------- resources/scripts-v2/plugins/i18n.ts | 7 ++++ resources/scripts-v2/utils/format-money.ts | 7 ++++ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/resources/scripts-v2/global-components.ts b/resources/scripts-v2/global-components.ts index 19e7bd1b..4d5f1800 100644 --- a/resources/scripts-v2/global-components.ts +++ b/resources/scripts-v2/global-components.ts @@ -1,19 +1,29 @@ import { defineAsyncComponent } from 'vue' import type { App, Component } from 'vue' +/** + * Exclude list for components that should be async-loaded or are + * not needed as global registrations. + */ +const EXCLUDE = new Set([ + 'BaseMultiselect', + 'InvoicePublicPage', + 'InvoiceInformationCard', +]) + /** * Register all base components globally so they can be used in * templates without explicit imports. - * - * Eager-loaded components come from `./components/base/*.vue` via - * Vite's `import.meta.glob`. A handful of heavier components - * (table, multiselect, editor) are registered as async components - * to keep the initial bundle small. */ export function defineGlobalComponents(app: App): void { - // Eager-load all single-file base components + // Eager-load base components (excluding heavy/page-level ones) const components: Record = import.meta.glob( - './components/base/*.vue', + [ + './components/base/*.vue', + '!./components/base/BaseMultiselect.vue', + '!./components/base/InvoicePublicPage.vue', + '!./components/base/InvoiceInformationCard.vue', + ], { eager: true } ) @@ -26,19 +36,18 @@ export function defineGlobalComponents(app: App): void { } // Async-load heavier components - const BaseTable = defineAsyncComponent( - () => import('./components/table/DataTable.vue') + app.component( + 'BaseTable', + defineAsyncComponent(() => import('./components/table/DataTable.vue')) ) - const BaseMultiselect = defineAsyncComponent( - () => import('./components/base/BaseMultiselect.vue') + app.component( + 'BaseMultiselect', + defineAsyncComponent(() => import('./components/base/BaseMultiselect.vue')) ) - const BaseEditor = defineAsyncComponent( - () => import('./components/editor/RichEditor.vue') + app.component( + 'BaseEditor', + defineAsyncComponent(() => import('./components/editor/RichEditor.vue')) ) - - app.component('BaseTable', BaseTable) - app.component('BaseMultiselect', BaseMultiselect) - app.component('BaseEditor', BaseEditor) } diff --git a/resources/scripts-v2/plugins/i18n.ts b/resources/scripts-v2/plugins/i18n.ts index e04d5ff7..ff79d7d4 100644 --- a/resources/scripts-v2/plugins/i18n.ts +++ b/resources/scripts-v2/plugins/i18n.ts @@ -27,6 +27,13 @@ async function loadLanguageMessages( return languageCache.get(locale)! } + // English is already statically imported — no dynamic import needed + if (locale === 'en') { + const messages = en as unknown as Record + languageCache.set('en', messages) + return messages + } + const fileName = LOCALE_FILE_MAP[locale] ?? locale try { diff --git a/resources/scripts-v2/utils/format-money.ts b/resources/scripts-v2/utils/format-money.ts index 915bd004..c3ada19a 100644 --- a/resources/scripts-v2/utils/format-money.ts +++ b/resources/scripts-v2/utils/format-money.ts @@ -76,6 +76,13 @@ export function formatMoney( * @param currency - Currency configuration used for parsing * @returns Amount in cents */ +/** + * Check if a MIME type represents an image file. + */ +export function isImageFile(mimeType: string): boolean { + return mimeType.startsWith('image/') +} + export function parseMoneyCents( formattedAmount: string, currency: CurrencyConfig = DEFAULT_CURRENCY