framework icon indicating copy to clipboard operation
framework copied to clipboard

Vite::content() no longer returns the full raw CSS with vite 7, it now returns JS import

Open bobbypiperagrovista opened this issue 3 months ago • 3 comments

Laravel Version

12.18.0

PHP Version

8.4.11

Database Driver & Version

No response

Description

https://laravel.com/docs/12.x/vite#inline-assets

We use inline assets for exactly this reason, to inject the CSS directly into the page when passing HTML content to a PDF generator. However since we upgraded to vite 7, the content() method now returns just the JS import rather than the full raw css content.

const e=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{e as T};

For a short term hack we've implemented the following:

function getViteCssContent(string $entryPath): ?string
{
    $manifestPath = public_path('build/manifest.json');
    if (!file_exists($manifestPath)) {
        return null;
    }
    $manifest = json_decode(file_get_contents($manifestPath), true);
    $entry = $manifest[$entryPath] ?? null;
    if (!$entry || !isset($entry['css']) || empty($entry['css'])) {
        return null;
    }
    $cssFile = head($entry['css']);
    $fullPath = public_path('build/' . $cssFile);
    if (!file_exists($fullPath)) {
        return null;
    }
    return file_get_contents($fullPath);
}

Steps To Reproduce

Use Vite::content() with expectation of seeing full raw CSS, not JS import

bobbypiperagrovista avatar Sep 03 '25 08:09 bobbypiperagrovista