idleberg / php-wordpress-vite-assets

Injects assets from a Vite manifest to the Wordpress head, supports themes and plugins
https://packagist.org/packages/idleberg/wordpress-vite-assets
MIT License
130 stars 12 forks source link

Updated to support scss #18

Closed gRoberts84 closed 3 months ago

gRoberts84 commented 4 months ago

Manifest contains files with .scss filenames, meaning that the styles are adding script modules too.

$baseUrl  = get_template_directory_uri() . '/dist/';
$manifest = get_template_directory() . "/dist/.vite/manifest.json";

$cssEntry = "assets/styles/main.scss";

$viteAssets = new Assets($manifest, $baseUrl);
$viteAssets->inject($cssEntry);

The above was outputting

<script type="module" src="https://project.test/wp-content/themes/tvw/dist/assets/main-C0ut9XiX.css" crossorigin integrity="sha256-uiuQruCDBu1DLYx6wlb32UAW7NhKG3rtUPv2Hf2R+Q8="></script>
<link rel="stylesheet" href="https://project.test/wp-content/themes/tvw/dist/assets/main-C0ut9XiX.css" crossorigin integrity="sha256-uiuQruCDBu1DLYx6wlb32UAW7NhKG3rtUPv2Hf2R+Q8=" />

because it was looking for files ending in .css which the manifest had .scss.