expo / google-fonts

Use any of the 1000+ fonts (and their variants) from fonts.google.com in your Expo app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Each font variant as a separate module

RobertSasak opened this issue · comments

I really love how easy it is to use fonts in this package. It is much faster and less error-prone than manually downloading and loading fonts.

Problem

The final bundle size is too big and contains all the variants of the selected font, even if only a few variants are used in the app.

Proposal

Split the module into multiple submodules for each font variant individually. This approach ensures not all the fonts are imported.

This is how the fonts are currently included:

import { useFonts, RobotoMono_700Bold, RobotoMono_400Regular } from '@expo-google-fonts/roboto-mono'

I propose allowing the import of font variants from submodules as well, as follows:

import { useFonts } from '@expo-google-fonts/roboto-mono/hooks'
import RobotoMono_700Bold from '@expo-google-fonts/roboto-mono/700bold'
import RobotoMono_400Regular from '@expo-google-fonts/roboto-mono/400regular'

Benefits

Selective importing of font variants can significantly reduce the final app size. For instance, for the highly popular Inter font family, the app size can be reduced from 2.8MB to as little as 320kb for a single font variant.

I can look into the PR if you find this issue relevant.