laravel-webfonts icon indicating copy to clipboard operation
laravel-webfonts copied to clipboard

Fonts per CSS file

Open royduin opened this issue 1 year ago • 1 comments

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.

royduin avatar Oct 18 '24 09:10 royduin

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

Log1x avatar Nov 12 '24 19:11 Log1x