Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adityakunhare's avatar

adityakunhare liked a comment+100 XP

3mos ago

Add custom font to Laravel 10 via vite

Just found an even better solution than the one I suggested earlier, and that seems to me even easier than sysoutlucas's, thanks to the Laravel doc (vite#blade-processing-static-assets). You can leave your assets in resources and then put:

import.meta.glob([
    '../fonts/**',
]);

in your app.js file. Leave url('../fonts/your-font.ttf') (or /resources/fonts/your-font.ttf I think it would also work) in your css. After running npm run build, I can see in my browser that Vite has changed the url to /build/assets/my-font.ttf (if I'm just running npm run dev, it shows /resources/fonts/my-font.ttf). Hope this helps!