Skip to content

Commit 359c349

Browse files
feat(fonts): merge families (#12696)
Co-authored-by: Sarah Rainsberger <[email protected]>
1 parent e1ab0ae commit 359c349

File tree

1 file changed

+38
-1
lines changed
  • src/content/docs/en/reference/experimental-flags

1 file changed

+38
-1
lines changed

src/content/docs/en/reference/experimental-flags/fonts.mdx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ optimizedFallbacks: false
507507

508508
### Remote font properties
509509

510-
Further configuration options are available for remote fonts. Set these to customize the data loaded from your [font provider](#available-remote-font-providers), for example to only download certain font weights or styles.
510+
Further configuration options are available for remote fonts. Set these to customize the data loaded from your [font provider](#available-remote-font-providers), for example to only download certain font weights or styles. For more control, more [granular configuration](#granular-remote-font-configuration) is available.
511511

512512
Under the hood, these options are handled by [unifont](https://github.com/unjs/unifont/). Some properties may not be supported by some providers and may be handled differently by each provider.
513513

@@ -787,6 +787,43 @@ export default defineConfig({
787787
});
788788
```
789789
790+
## Granular remote font configuration
791+
792+
<p>
793+
794+
<Since v="5.15.6" />
795+
</p>
796+
797+
A font family is defined by a combination of properties such as weights and styles (e.g. `weights: [500, 600]` and `styles: ["normal", "bold"]`), but you may want to download only certain combinations of these.
798+
799+
For greater control over which font files are downloaded, you can specify the same font (ie. with the same `cssVariable`, `name`, and `provider` properties) multiple times with different combinations. Astro will merge the results and download only the required files. For example, it is possible to download normal `500` and `600` while downloading only italic `500`:
800+
801+
```js
802+
// astro.config.mjs
803+
import { defineConfig, fontProviders } from "astro/config"
804+
805+
export default defineConfig({
806+
experimental: {
807+
fonts: [
808+
{
809+
name: "Roboto",
810+
cssVariable: "--roboto",
811+
provider: fontProviders.google(),
812+
weights: [500, 600],
813+
styles: ["normal"]
814+
},
815+
{
816+
name: "Roboto",
817+
cssVariable: "--roboto",
818+
provider: fontProviders.google(),
819+
weights: [500],
820+
styles: ["italic"]
821+
}
822+
]
823+
}
824+
})
825+
```
826+
790827
## Build your own font provider
791828
792829
If you do not wish to use one of the [built-in providers](#available-remote-font-providers) (eg. you want to use a 3rd-party unifont provider or build something for a private registry), you can build your own.

0 commit comments

Comments
 (0)