Skip to content
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

Refactor component import to remove Vite-specific globEager dependency #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Notorious-Ali
Copy link

@Notorious-Ali Notorious-Ali commented Sep 17, 2024

Issue

The original code used import.meta.globEager() to dynamically import components, which is a Vite-specific feature not available in browser environments after compilation.

Solution

i modified the component import process to use explicit imports and a manual component registration approach. This ensures compatibility across different build tools and environments.

Modified Code

import PackageJSON from "../package.json"
import type {App} from 'vue'
import {GlobalConfig, provideGlobalConfig} from "@/hooks"

import FilterBar from '@/components/filter-bar/index'
import IconButton from '@/components/icon-button/index'
import ReadWriteSwitch from '@/components/read-write-switch/index'
import SearchBar from '@/components/search-bar/index'
import SpeedDial from '@/components/speed-dial/index'
import Steps from '@/components/steps/index'
import table from '@/components/table/index'
import tabs from '@/components/tabs/index'

const components = [FilterBar, IconButton, ReadWriteSwitch, SearchBar, SpeedDial, Steps, table, tabs]

const install = (app: App, config: GlobalConfig): void => {
  components.forEach(component => {
    if (typeof component === 'object' && 'install' in component) {
      app.use(component)
    } else if (typeof component === 'function' && component.name) {
      app.component(component.name, component)
    }
  })
  provideGlobalConfig(config)
}

const plugin = {
  name: "Fit2CloudUIPlus",
  version: PackageJSON.version,
  install,
}

export default plugin

…cess

index-B0xWKXmx.js:5 Uncaught TypeError: (intermediate value).globEager is not a function
    at index-B0xWKXmx.js:5:83765
 `var Uu = L4(function(e) {
    return _S(ui(e, 1, ig, !0))
});
const Mh = import.meta.globEager("@/components/*/index.ts")
  , wS = (e, t) => {
    Object.keys(Mh).forEach(n => {
        let o = Mh[n].default;
        e.use(o)
    }
    ),
    Yw(t)`
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant