Skip to content

Commit 42388b2

Browse files
fix(fonts): import side effect (#13674)
1 parent 2b11d50 commit 42388b2

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

.changeset/plenty-loops-cry.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes a case where an experimental fonts API error would be thrown when using another `astro:assets` API

packages/astro/src/assets/fonts/vite-plugin-fonts.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,22 @@ async function fetchFont(url: string): Promise<Buffer> {
6262

6363
export function fontsPlugin({ settings, sync, logger }: Options): Plugin {
6464
if (!settings.config.experimental.fonts) {
65-
// this is required because the virtual module does not exist
66-
// when fonts are not enabled, and that prevents rollup from building
65+
// This is required because the virtual module may be imported as
66+
// a side effect
6767
// TODO: remove once fonts are stabilized
6868
return {
6969
name: 'astro:fonts:fallback',
70-
config() {
71-
return {
72-
build: {
73-
rollupOptions: {
74-
external: [VIRTUAL_MODULE_ID],
75-
},
76-
},
77-
};
70+
resolveId(id) {
71+
if (id === VIRTUAL_MODULE_ID) {
72+
return RESOLVED_VIRTUAL_MODULE_ID;
73+
}
74+
},
75+
load(id) {
76+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
77+
return {
78+
code: '',
79+
};
80+
}
7881
},
7982
};
8083
}

0 commit comments

Comments
 (0)