Certainly! Here’s how you can handle different font families for your public and admin layouts in a Laravel 12 + Vite + Tailwind setup, without needing two separate CSS files.
Solution: Use CSS Variables and Layout-specific Classes
1. Define Both Fonts in Your CSS
In your main CSS (e.g., app.css), define both font families as CSS variables, each under a unique class:
/* app.css */
:root {
--font-sans-public: 'Work Sans', ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
--font-sans-admin: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}
/* Optional: fallback for Tailwind's font-sans */
.font-sans-public {
font-family: var(--font-sans-public);
}
.font-sans-admin {
font-family: var(--font-sans-admin);
}
2. Use Tailwind’s fontFamily Customization
If you want to use Tailwind’s font-sans utility, you can override it per layout using a custom class:
// tailwind.config.js
module.exports = {
theme: {
extend: {
fontFamily: {
'sans-public': ['var(--font-sans-public)'],
'sans-admin': ['var(--font-sans-admin)'],
},
},
},
}
3. Apply the Class in Your Blade Layouts
Public Layout:
<body class="font-sans-public">
<!-- Public content -->
</body>
or with Tailwind utility:
<body class="font-sans-public font-sans-public">
<!-- Public content -->
</body>
Admin Layout:
<body class="font-sans-admin">
<!-- Admin content -->
</body>
or with Tailwind utility:
<body class="font-sans-admin font-sans-admin">
<!-- Admin content -->
</body>
4. Load Both Fonts
Make sure both fonts are loaded in your HTML (e.g., via Google Fonts CDN in your layouts):
<!-- In public layout -->
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;700&display=swap" rel="stylesheet">
<!-- In admin layout -->
<link href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;700&display=swap" rel="stylesheet">
5. Result
Now, each layout will use its own font, but you’re still using a single CSS file. No need to split your Vite build.
Summary:
- Define both fonts as CSS variables and/or Tailwind custom font families.
- Apply the appropriate class at the layout level.
- Load the correct font in each layout’s
<head>. - No need for multiple CSS files or Vite configs.
Let me know if you need a more detailed example or help with your tailwind.config.js!