vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
67.63k stars 6.09k forks source link

vite build alters the <link> tag wrongly #17322

Open Botato300 opened 4 months ago

Botato300 commented 4 months ago

Describe the bug

I am compiling my .html file with the command vite build, and when I see the final code, specifically the <link> tags that are in <head>, they are different because it erases the attributes that I added.

What I was expecting is this final code: <link rel=“preload” as=“style” onload=“this.onload=null;this.rel=‘stylesheet’” href=“./assets/index-CjVjCqpO.css”>

What really happened... <link rel=“stylesheet” crossorigin href=“./assets/index-CjVjCjCqpO.css”>

Reproduction

https://stackblitz.com/edit/vitejs-vite-2k4shi?file=dist%2Findex.html

Steps to reproduce

just run npm run build and see the generated html code and compare it with the original

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 AMD Ryzen 5 5600G with Radeon Graphics
    Memory: 5.49 GB / 12.90 GB
  Binaries:
    Node: 18.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.19041.4355

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 4 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

bluwy commented 4 months ago

Similar https://github.com/vitejs/vite/issues/8739. Currently Vite reconstructs the links, hence the original attributes are not preserved. Vite does have partial support for preserving some attributes, but it has its own issues too: https://github.com/vitejs/vite/issues/9402

geeksilva97 commented 3 months ago

hello @bluwy . do you think it's something a newcomer can work on? If so, I would like to give a try.

bluwy commented 3 months ago

I think this requires a fair bit of refactor to fix and likely some re-architecture to link handling, so probably not a good first issue for a newcomer 😅

geeksilva97 commented 3 months ago

I think this requires a fair bit of refactor to fix and likely some re-architecture to link handling, so probably not a good first issue for a newcomer 😅

wow, yeah I didn't see that. will try to find another issue. thank you!