Eptagone / Vite.AspNetCore

Small library to integrate Vite into ASP.NET projects
MIT License
264 stars 35 forks source link

Using modulepreload causes warning for ES modules #51

Closed seangwright closed 10 months ago

seangwright commented 1 year ago

I have the following in my <head>

<link rel="preload" vite-href="~/styles/style.scss" as="style" />
<link rel="modulepreload" vite-href="~/js/main.js" as="script" />

<!-- ... other stuff -->

<link rel="stylesheet" vite-href="~/styles/style.scss" />

and at the end of my <body>

<script type="module" vite-src="~/js/main.js"></script>

These preload keywords are used to inform the browser to start downloading an asset even before it is used.

When I use these with a .js module using vite-href I get the following warning

warn: Vite.AspNetCore.TagHelpers.ViteTagHelper[0]
The entry 'js/main.js' doesn't have CSS chunks

My thought is that the logic in the ViteTagHelper needs to be expanded to handle these scenarios or it needs to be less strict about what it's validating.

Eptagone commented 10 months ago

Hi, sorry for the delay. I added a validation for link tags with 4a2a47a31e6cdf471ab25f4f442ece3dca277941. For non-stylesheet links, the script url will be used instead of CSS url.