I create PDFs with spatie/laravel-pdf on Laravel 11, styled with TailwindCSS. My layout has
@vite(['resources/css/app.css'])
I was working locally with vite running. PDfs were looking great.
My deployment includes building the css with
npm ci
npm run build
rm -rf node_modules
The website renders just fine with the built stylesheets from /build/assets/...
.
But: When I deployed my app to my forge server, the PDFs were missing the stylesheet after generation.
I tried motomedialab/laravel-vite-helper
and including the CSS with variants of
<link rel="stylesheet" href="{{ vite('resources/css/app.css', 'build', false, false) }}">
and even
<link rel="stylesheet" href="/build/assets/app-Bq_2mYPq.css">
This did both not work. But I want to use my build CSS, and not keeping vite running 24/7 on my production server.
What am I missing here?
I also encountered this issue, but I gave up with external stylesheet and made it render within the HTML like this.
<style>{!! Vite::content('resources/scss/app.scss') !!}</style>
I'm not sure why external stylesheet cannot render, but my guess is that the blade template couldn't fetch the stylesheet without it's hostname.
Hope this helps.