Closed bavodeclercq closed 7 months ago
Appreciate the issue! I think:
$filenameParts = preg_split("/[.-]/", $filename);
Might be problematic if the file name has a -
in it however.
Yeah, you're right. The quick and dirty fix was a stopgap for my scenario. Ideally, if possible, checking which version of Vite is being used and then deciding whether to split file names at dots, or just at the last dash (for Vite 5) based on that information, could be a more stable solution. Alternatively, instead of checking the version, checking if there are dots in the filename and, if not, splitting at the last dash could be another approach.
Addressed in the above commits.
Describe the bug
When using Vite 5, the function
{{ craft.vite.inline(craft.vite.entry('emails.css')) }}
fails to return any output, indicating a significant issue with inline CSS loading. The core of the problem lies within theextractEntry
function inmanifestHelper.php
, which is required to delve deeper due to changes in how CSS files are represented inmanifest.json
in Vite 5. The malfunction occurs because thestyleKey
is not correctly retrieved. This is due to thefilenameWithoutHash
function not functioning correctly, as it only searches for dots in filenames, ignoring dashes. This specific issue traces back to the transition from Vite 3 to Vite 4, where the separator in filenames changed from dots to dashes. However, the repercussions of this change only became apparent with the introduction of Vite 5, due to adjustments in the manifest file structure and the handling of CSS files. A workaround involves modifying line 300 inManifestHelper.php
from$filenameParts = explode('.', $filename);
to$filenameParts = preg_split("/[.-]/", $filename);
, which addresses the issue and allows the CSS fromemail.css
to be correctly inlined.To reproduce
To reproduce the behavior, follow these steps:
{{ craft.vite.inline(craft.vite.entry('emails.css')) }}
.Expected behaviour
The expected behavior is for the CSS from
emails.css
to be correctly inlined when using the{{ craft.vite.inline(craft.vite.entry('emails.css')) }}
function in Craft CMS with Vite 5.Screenshots
N/A
Versions