Vite lossily combines `link[rel=stylesheet]` and `link[rel=stylesheet][media="(prefers-color-scheme:dark)"]`
See original GitHub issueDescribe the bug
Vite lossily (note the media
attribute) combines
<link rel=stylesheet href="a.css" />
<link rel=stylesheet href="b.css" media="(prefers-color-scheme:dark)" />
to
<link rel=stylesheet href="c123.css" />
How to prevent this? Ideally both files were optimized and name-hashed, but not combined into one and the media attribute preserved:
<link rel=stylesheet href="a123.css" />
<link rel=stylesheet href="b456.css" media="(prefers-color-scheme:dark)" />
Reproduction
https://stackblitz.com/edit/vitejs-vite-tbytgv?devtoolsheight=33&file=index.html
System Info
N/A
Used Package Manager
npm
Logs
❯ npm run build
$ vite build
vite v2.7.13 building for production...
✓ 3 modules transformed.
dist/assets/favicon.17e50649.svg 1.49 KiB
dist/index.html 0.35 KiB
dist/assets/index.3d17f766.css 0.05 KiB / gzip: 0.05 KiB
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:5 (3 by maintainers)
Top Results From Across the Web
The External Resource Link element - HTML - MDN Web Docs
The HTML element specifies relationships between the current document and an external resource. This element is most commonly used to link ...
Read more >Features | Vite
Vite is pre-configured to support CSS @import inlining via postcss-import . Vite aliases are also respected for CSS @import . In addition, all...
Read more >What is the utility of the media attribute in the Link tag?
First render at 1100ms; The style rendering is deferred until all css are downloaded and parsed (CSS render blocking). The second version using ......
Read more >A Complete Guide to CSS Media Queries
CSS Media queries are a way to target browser by certain characteristics, features, and user preferences, then apply styles based on those ...
Read more >Media queries - web.dev
<link rel="stylesheet" href="print.css" media="print"> ... You can also combine media queries to apply more than one condition. Use the word and to combine...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into this issue, because I provide print styles and screen styles:
Only ever one of these files should load. But vite combines them into one, breaking my site a bit 😅
Hello, I have same issues for this. I want to split scss files into mobile and desktop for mobile optimization. It’s working on serve mode. (css is the same)
But vite combie these on build and lost the media attribute.
I tried to set rollup options like this.
vite split the css files as expected. but still could not save the media attribute. So I manually add the media attribute after build.
I saw PR #6751, will this feature be released in the next version?
Edit
Well, I thought
link media
would allow browser to automatically choose which one to download. But it doesn’t seem to work that way. I got it wrong.