Repository navigation
fix: prevent duplicate CSS files after build - #9382
Conversation
|
vitejs/vite#12207 will be released any day now, so I guess the question is just which solution we'd prefer |
|
I wasn't sure when the Vite update would be released. Feel free to close this PR if needed. |
|
With that Vite PR being released now, what's the status here? Set this if we detect Vite<4.2? Anything that needs to be done for user that have 4.2 installed, or do they get this fix automatically? |
I did a quick test with sveltekit.new and it seems that vite 4.2 doesn't automatically fix the issue. Specifying either I think it's still best to go ahead with this fix since it's backwards compatible |
Co-authored-by: Bjorn Lu <[email protected]>
🦋 Changeset detectedLatest commit: 3752841 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thank you! |
|
I just updated to |
|
I mean there are may duplicates, like:
and so on. The hash is fake in this message. |
Which type of adapter are you using? In some cases, the duplicate CSS files are correct, where URL paths will be different on the server vs the client. The previous CSS duplicates were caused by differences such as values of |
|
I'm using static adapter. But one of the two files is not used anywhere. If I search it by name in all the build dir I found nothing, the other is there. So one of those two files is generated but not used. |
Got it. That's caused by the builder copying over everything (server + client). This currently can't be disabled at the adapter level, hence this issue. Same thing reported here #9161 |
Related to #17794 `plugin_compile` sets `build.cssMinify` from `build.minify`, so a `build.cssMinify` set in the user's Vite config is ignored. #9382 added this as a workaround until Vite shipped a separate CSS minify option (vitejs/vite#12207); that option is `build.cssMinify` and it now exists. This uses `build.cssMinify` when the user sets it and keeps the existing `minify`-derived value otherwise, so default behaviour is unchanged. Server and client CSS still get matching hashes (the reason for #9382). `build.cssMinify` isn't in `enforced_config`, so Kit doesn't currently warn that it overrides it. Without this, `build.cssMinify: 'esbuild'` is ignored and Vite 8 falls back to Lightning CSS, which fails on CSS it can't parse (reproduction in the linked issue).
Prevents duplicate CSS files due to a different hash when the server CSS assets are not minified but the same client CSS is minified.
Explicitly specifying the Vite build option
minify: 'esbuild'ensures they are always minified.The default is
esbuildbut only minifies JS when it comes to server assets.This is a workaround until Vite has been updated with vitejs/vite#12207 to separately specify CSS minification. This is also nice for those who haven't updated Vite.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.