-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite lossily combines link[rel=stylesheet]
and link[rel=stylesheet][media="(prefers-color-scheme:dark)"]
#6748
Comments
Besides Maybe we can deal with it together in this PR #6751 |
Maybe |
Hello, I have same issues for this. <link rel="stylesheet" href="/src/styles/mobile.scss">
<link rel="stylesheet" href="/src/styles/desktop.scss" media="(min-width: 768px)"> But vite combie these on build and lost the media attribute. <link rel="stylesheet" href="/assets/style.c5411e4b.css"> I tried to set rollup options like this. // vite.config
export default defineConfig({
return {
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('.scss')) {
// e.g. ".../styles/desktop.scss" to "desktop"
const cssName = id.split('styles/')[1].split('.')[0]
return cssName
}
},
},
},
},
}
}) vite split the css files as expected. but still could not save the media attribute. So I manually add the media attribute after build. // build output
<link rel="stylesheet" href="/assets/mobile.6f120d68.css">
<link rel="stylesheet" href="/assets/desktop.76768932.css"> I saw PR #6751, will this feature be released in the next version? EditWell, I thought |
I ran into this issue, because I provide print styles and screen styles: <!doctype html>
<link rel="stylesheet" href="/screen.css" media="screen" />
<link rel="stylesheet" href="/print.css" media="print" /> Only ever one of these files should load. But vite combines them into one, breaking my site a bit 😅 |
It looks like #6751 is ready to go. Thanks to everyone involved for working on this! |
Describe the bug
Vite lossily (note the
media
attribute) combinesto
How to prevent this? Ideally both files were optimized and name-hashed, but not combined into one and the media attribute preserved:
Reproduction
https://stackblitz.com/edit/vitejs-vite-tbytgv?devtoolsheight=33&file=index.html
System Info
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
The text was updated successfully, but these errors were encountered: