Skip to content
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

fix!: default build.cssMinify to 'esbuild' for SSR #15637

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Jan 18, 2024

Description

Even for SSR, there's no reason to skip minify for CSS files.

SvelteKit and Astro sets this.
https://github.com/sveltejs/kit/blob/6200a48befe538176b1f5c1cb9e32c51af84345b/packages/kit/src/exports/vite/index.js#L607
https://github.com/withastro/astro/blob/7e1db8b4ce2da9e044ea0393e533c6db2561ac90/packages/astro/src/core/build/static-build.ts#L178-L180

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added has workaround p2-nice-to-have Not breaking anything but nice to have (priority) breaking change labels Jan 18, 2024
Copy link

stackblitz bot commented Jan 18, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

patak-dev
patak-dev previously approved these changes Jan 18, 2024
@patak-dev patak-dev added this to the 5.1 milestone Jan 18, 2024
@patak-dev
Copy link
Member

@sapphi-red you marked this as a breaking change, would we still be able to merge it for Vite 5.1? Vite 6 is too far away right now.

@patak-dev
Copy link
Member

Ah, ok, I see:

I think we could still merge this one in Vite 5.1, but maybe I'm missing something here.

@patak-dev patak-dev removed this from the 5.1 milestone Jan 18, 2024
@sapphi-red
Copy link
Member Author

I think the change has a slightly big impact. Given that there's a workaround, I think it's better to wait for Vite 6.

@patak-dev patak-dev added this to the 6.0 milestone Jan 18, 2024
@bluwy
Copy link
Member

bluwy commented Jan 18, 2024

Should we also only minify only if ssrEmitAssets is true? Otherwise the minified result is thrown away.

@sapphi-red
Copy link
Member Author

Should we also only minify only if ssrEmitAssets is true? Otherwise the minified result is thrown away.

Even if ssrEmitAssets is false, the user wants the same file hash for CSS files (also for other assets). To get the same file name between client and server, the same content needs to be generated. So I think we need to enable minify.

@bluwy
Copy link
Member

bluwy commented Jan 18, 2024

I don't quite understand how one would compare the same file name between client and server if ssrEmitAssets is false? There won't be any assets in the first place. And the JS generated by client and server builds would already be different.

@bluwy
Copy link
Member

bluwy commented Jan 18, 2024

Ah I guess checking the Remix issue, it's because the hash is exposed for .css?url 🤔

@sapphi-red
Copy link
Member Author

Yep, the the hash is exposed for .css?url. The URL on the server points to nothing.
Example: https://stackblitz.com/edit/vitejs-vite-8zxxdh?file=main.js

@@ -451,7 +451,7 @@ export function resolveBuildEnvironmentOptions(
}

if (resolved.cssMinify == null) {
resolved.cssMinify = !!resolved.minify
resolved.cssMinify = raw.ssr ? 'esbuild' : !!resolved.minify
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using raw.ssr to align with minify: raw.ssr ? false : 'esbuild', above. Do we want to update that to consumer === 'server'? I guess we don't want to, because we would want to enable minify for edge runtimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change has workaround p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants