From c4285f222db68e6b21e1bc1b8137d41811498d58 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Wed, 23 Apr 2025 09:30:20 +0200 Subject: [PATCH] fix(fonts): import side effect --- .changeset/plenty-loops-cry.md | 5 ++++ .../src/assets/fonts/vite-plugin-fonts.ts | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .changeset/plenty-loops-cry.md diff --git a/.changeset/plenty-loops-cry.md b/.changeset/plenty-loops-cry.md new file mode 100644 index 000000000000..6d5cce36cbe8 --- /dev/null +++ b/.changeset/plenty-loops-cry.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a case where an experimental fonts API error would be thrown when using another `astro:assets` API diff --git a/packages/astro/src/assets/fonts/vite-plugin-fonts.ts b/packages/astro/src/assets/fonts/vite-plugin-fonts.ts index e6ea231e67cd..a7bf8ad9a91a 100644 --- a/packages/astro/src/assets/fonts/vite-plugin-fonts.ts +++ b/packages/astro/src/assets/fonts/vite-plugin-fonts.ts @@ -62,19 +62,22 @@ async function fetchFont(url: string): Promise { export function fontsPlugin({ settings, sync, logger }: Options): Plugin { if (!settings.config.experimental.fonts) { - // this is required because the virtual module does not exist - // when fonts are not enabled, and that prevents rollup from building + // This is required because the virtual module may be imported as + // a side effect // TODO: remove once fonts are stabilized return { name: 'astro:fonts:fallback', - config() { - return { - build: { - rollupOptions: { - external: [VIRTUAL_MODULE_ID], - }, - }, - }; + resolveId(id) { + if (id === VIRTUAL_MODULE_ID) { + return RESOLVED_VIRTUAL_MODULE_ID; + } + }, + load(id) { + if (id === RESOLVED_VIRTUAL_MODULE_ID) { + return { + code: '', + }; + } }, }; }