I don't assume you have public in the url so it should be here either
url('public/fonts/Nuckle-Thin.woff2')
//fix
url('/fonts/Nuckle-Thin.woff2')
Hi everyone,
I hope someone has an answer to this, as I can’t seem to resolve it.
I’m working on a Laravel project and have deployed it, but the font is missing. I’ve tried various solutions, including starting a brand new project, but the same issue keeps appearing.
On the live project (local), the error I get is: [Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (Nuckle-Bold.woff, line 0)
On the new project, the error is a 404 status instead of 500. What’s even stranger is that in Chrome and Firefox, the font displays correctly, but not in Safari. (But the error stays in Chrome and Firefox)
The font path is located in public/fonts/...
Thanks in advance for your help! Shane
Here’s what the new project setup looks like:
<title>Laravel</title>
<!-- Styles / Scripts -->
@if (file_exists(public_path('build/manifest.json')) || file_exists(public_path('hot')))
@vite(['resources/scss/app.scss', 'resources/css/app.css', 'resources/js/app.js'])
@else
@endif
</head>
<body>
<div class="box">
hello
</div>
</body>
@font-face {
font-family: 'Nuckle';
src: local('Nuckle Thin'), local('Nuckle-Thin'),
url('public/fonts/Nuckle-Thin.woff2') format('woff2'),
url('public/fonts/Nuckle-Thin.woff') format('woff'),
url('public/fonts/Nuckle-Thin.ttf') format('truetype');
font-weight: 100;
font-style: normal;
font-display: swap;
}
body {
font-family: 'Nuckle', sans-serif;
}
.box {
width: 300px;
height: 300px;
background: red;
color: white;
font-size: 50px;
}
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/scss/app.scss', 'resources/js/app.js'],
refresh: true,
}),
],
});
Hi there, I had a similar issue with local vs production environments. The main issue lies in how vite translates the urls in dev mode vs prod mode. You have to make sure that vite knows where to look for or rather how to "build" the absolute/relative paths. With the 2 css files and vite config I managed to resolve the issue - it might not be the prettiest, but it works.
//style-dev.css
@font-face {
font-family: "BrandonGrotesque";
src: url('public/assets/fonts/BRANDONGROTESQUE-REGULAR.OTF') format("opentype");
//style-prod.css
@font-face {
font-family: "BrandonGrotesque";
src: url('../assets/fonts/BRANDONGROTESQUE-REGULAR.OTF') format("opentype");
// vite.config.js
export default defineConfig(({command, mode})=>{
const envs = loadEnv(mode, process.cwd());
const base = envs.VITE_BASE_PATH;
const origin = process.env.NODE_ENV === 'production' ? envs.VITE_BASE_PATH : "http://" + envs.VITE_DOMAIN + ":5173";
const host = envs.VITE_DOMAIN;
const app_container = envs.VITE_APP_CONTAINER;
where the envs are loaded from the .env file (.env for dev, .env.staging for staging, .env.prod for prod)
Make sure you completely match the url path especially if your project is nested in a directory (aka. not in the public_html or something).
Hope this helps.
Please or to participate in this conversation.