Skip to content

Commit a216b73

Browse files
committedNov 10, 2024
fix: simplified clent bundle deps injection
1 parent 29d4b60 commit a216b73

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed
 

‎src/bundle-client.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ export function registerClientBundle(
4444
const collectionsRaw = `JSON.parse(${JSON.stringify(valuesCompat)})`
4545

4646
return [
47-
'import { addIcon } from "@iconify/vue"',
4847
'let _initialized = false',
49-
'export function init() {',
48+
'export function init(addIcon) {',
5049
' if (_initialized)',
5150
' return',
5251
` const collections = ${collectionsRaw}`,

‎src/runtime/components/shared.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed } from 'vue'
2-
import { getIcon as _getIcon, loadIcon as _loadIcon } from '@iconify/vue'
2+
import { getIcon as _getIcon, addIcon as _addIcon, loadIcon as _loadIcon } from '@iconify/vue'
33
import { consola } from 'consola'
44
import type { IconifyIcon } from '@iconify/types'
55
import type { NuxtIconRuntimeOptions } from '../../types'
@@ -11,7 +11,7 @@ export { initClientBundle }
1111
export async function loadIcon(name: string, timeout: number): Promise<Required<IconifyIcon> | null> {
1212
if (!name)
1313
return null
14-
initClientBundle()
14+
initClientBundle(_addIcon)
1515
const _icon = _getIcon(name)
1616
if (_icon)
1717
return _icon

‎src/runtime/components/svg.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const NuxtIconSvg = /* @__PURE__ */ defineComponent({
4141
addIcon(name.value, payload)
4242
}
4343
else {
44-
initClientBundle()
44+
initClientBundle(addIcon)
4545
}
4646
}
4747
}

‎src/shim.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ declare module '#nuxt-icon-server-bundle' {
55
}
66

77
declare module '#build/nuxt-icon-client-bundle' {
8-
export function init(): void
8+
import type { IconifyIcon } from '@iconify/types'
9+
10+
export function init(addIcon: ((name: string, data: IconifyIcon) => void)): void
911
}

0 commit comments

Comments
 (0)
Please sign in to comment.