Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download functionality to presetWebFonts for offline/local network website #3646

Open
4 tasks done
HassanDomeDenea opened this issue Mar 21, 2024 · 1 comment
Open
4 tasks done

Comments

@HassanDomeDenea
Copy link

HassanDomeDenea commented Mar 21, 2024

Clear and concise description of the problem

When you add fonts using presetWebFonts, for example:

//uno.config.ts
export default defineConfig({
  presets: [
    //   ...
    presetWebFonts({
      fonts:{
        lobster: 'Lobster',
        vibes: 'Vibes',
      }
    })
  ]
})

this will create @font-face definition for each font, containing the URL from google for example:


@font-face {
  font-family: Vibes;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(https://fonts.gstatic.com/s/vibes/v14/QdVYSTsmIB6tmYd1FJfcuA.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F /* .... */
}

For some web application that works offline or inside (local network), we cannot use this as we need the files to those fonts in the assets of our applications to work properly.

Suggested solution

My suggested solution is inspired from a vite plugin vite-plugin-webfont-dl
An option (global or per font) inside presetWebFonts config, to allow downloading fonts locally, thus the generated styles use the relative path to font file from our project.

Example for suggested config:


presetWebFonts({
  downloadLocally: true, //Global setting, unless overridden 
  fonts: {  
       vibes: 'Vibes',
       lobster: [
           {
                 name: 'Lobster,
                 provider: 'none',
                 downloadLocally: false, // Overridden here
           }
        ],
    ],
  },
})

Generated code will be for example:

@font-face {
  font-family: Vibes; 
  src: url(assets/font-vibes-QdVYSTsmIB6tmYd1FJfcuA.woff2) format("woff2");
}

Alternative

No response

Additional context

This vite plugin https://github.com/feat-agency/vite-plugin-webfont-dl unfortunately does not work with font-faces generated by unocss/presetWebFonts (whether inline import is true or false)
Or did I miss a working configuration or workaround?

Validations

  • Read the Contributing Guidelines.
  • Read the README.md of using the package.
  • Already used the Interactive Docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@antfu
Copy link
Member

antfu commented Apr 5, 2024

I'd love to have that feature! PR welcome if anyone wants to work on that. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants