Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-tires-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a case where fonts files would unecessarily be copied several times during the build
9 changes: 9 additions & 0 deletions packages/astro/src/assets/fonts/vite-plugin-fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function fontsPlugin({ settings, sync, logger }: Options): Plugin {
let isBuild: boolean;
let fontFetcher: FontFetcher | null = null;
let fontTypeExtractor: FontTypeExtractor | null = null;
let built = false;

const cleanup = () => {
componentDataByCssVariable = null;
Expand All @@ -88,6 +89,9 @@ export function fontsPlugin({ settings, sync, logger }: Options): Plugin {
isBuild = command === 'build';
},
async buildStart() {
if (sync) {
return;
}
const { root } = settings.config;
// Dependencies. Once extracted to a dedicated vite plugin, those may be passed as
// a Vite plugin option.
Expand Down Expand Up @@ -304,6 +308,10 @@ export function fontsPlugin({ settings, sync, logger }: Options): Plugin {
},
},
async buildEnd() {
// Run once during the build, no matter how many environments there are
if (built) {
return;
}
if (sync || !settings.config.fonts?.length || !isBuild) {
cleanup();
return;
Expand Down Expand Up @@ -335,6 +343,7 @@ export function fontsPlugin({ settings, sync, logger }: Options): Plugin {
}
} finally {
cleanup();
built = true;
}
},
};
Expand Down
Loading