diff --git a/examples/vitepress/package.json b/examples/vitepress/package.json index d2a0b2d..7e78524 100644 --- a/examples/vitepress/package.json +++ b/examples/vitepress/package.json @@ -1,7 +1,7 @@ { "name": "vitepress", - "private": true, "type": "module", + "private": true, "scripts": { "dev": "vitepress dev", "start": "vitepress dev", diff --git a/src/index.ts b/src/index.ts index 47d7c17..80a8103 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ import { createUnplugin } from 'unplugin' import { getHeadLinkTags } from './loaders' import { customVirtualModule } from './loaders/custom' import { fontsourceImports, fontsourceVirtualModule } from './loaders/fontsource' -import { HtmlTagDescriptor } from 'vite' const virtualStylesId = 'unfonts.css' const resolvedVirtualStylesId = `\0${virtualStylesId}` @@ -91,10 +90,11 @@ export default createUnplugin((userOptions) => { const { prefetch: wantPrefetch, preload: wantPreload } = options?.custom || {} for (const file of files) { if (!( - wantPrefetch === true || wantPreload === true || - (wantPrefetch === undefined && wantPreload === undefined) - )) + wantPrefetch === true || wantPreload === true + || (wantPrefetch === undefined && wantPreload === undefined) + )) { continue + } const ext = extname(file) tags.push({ tag: 'link', @@ -113,7 +113,8 @@ export default createUnplugin((userOptions) => { const newTags = options?.custom?.linkFilter(tags) if (Array.isArray(newTags)) { tagsReturned = newTags - } else { + } + else { tagsReturned = newTags ? tags : [] } } @@ -140,10 +141,11 @@ function generateVitepressBundle( const { prefetch: wantPrefetch, preload: wantPreload } = options?.custom || {} for (const file of files) { if (!( - wantPrefetch === true || wantPreload === true || - (wantPrefetch === undefined && wantPreload === undefined) - )) + wantPrefetch === true || wantPreload === true + || (wantPrefetch === undefined && wantPreload === undefined) + )) { continue + } const ext = extname(file) tags.push({ @@ -164,7 +166,8 @@ function generateVitepressBundle( const newTags = options?.custom?.linkFilter(tags) if (Array.isArray(newTags)) { tagsReturned = newTags - } else { + } + else { tagsReturned = newTags ? tags : [] } } diff --git a/src/types.ts b/src/types.ts index c983972..ad268c4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { HtmlTagDescriptor } from "vite" +import type { HtmlTagDescriptor } from 'vite' export interface Options { custom?: CustomFonts @@ -12,7 +12,7 @@ export interface CustomFontFace { source: string name: string basename: string - weight: number + weight: number | `${number} ${number}` style: string display: string local?: string | string[]