Log1x / laravel-webfonts

Download, install, and preload Google fonts locally in your Laravel project.
https://github.com/Log1x/laravel-webfonts
MIT License
121 stars 7 forks source link

Fonts per CSS file #38

Open royduin opened 1 month ago

royduin commented 1 month ago

Just curious about your thoughts on this; currently all fonts from the manifest are added with @preloadFonts. So when you've multiple CSS files (for multisite):

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/website1.css',
                'resources/css/website2.css',
                'resources/css/website3.css',
                'resources/js/app.js'
            ],

And within the <head> something like:

@vite([
    'resources/css/website.' . $websiteId . '.css',
    'resources/js/app.js'
])
@preloadFonts

With different fonts in the CSS files on all websites you'll get all fonts. From the manifest you can't relate the fonts to a file so the achieve that you've to scan the CSS files again, or Vite does have something for that? But then @preloadFonts needs to know the CSS file to scan for fonts; @preloadFonts('resources/css/website.' . $websiteId . '.css') but maybe hooking into @vite so we don't need an extra directive would be cleaner. Not sure how Vite scans the CSS for fonts, but we've to repeat that from PHP.

Log1x commented 2 weeks ago

I think we'd have to wait on https://github.com/vitejs/vite/issues/18392 but this would definitely be nice.