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(css): .css?url support #15259

Merged
merged 6 commits into from Jan 12, 2024
Merged

fix(css): .css?url support #15259

merged 6 commits into from Jan 12, 2024

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Dec 6, 2023

Description

  • .css?url now returns a URL to transformed CSS
    • before, it was returning a URL to transformed CSS in dev, and to raw CSS after build
  • .css?raw&url now returns a URL to raw CSS
    • note that .css?raw returns a JS module (export default ".foo {}") but .css?raw&url returns a URL to CSS file (.foo {})
  • .module.css?url now throws an error
    • this was never useful because there's no way to get the class name map ({ 'foo': 'foo_hash' }) without injecting the actual CSS

fixes #2522
fixes #7842
fixes #13416

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 feat: css p3-minor-bug An edge case that only affects very specific usage (priority) labels Dec 6, 2023
Copy link

stackblitz bot commented Dec 6, 2023

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

@bluwy
Copy link
Member

bluwy commented Dec 9, 2023

  • .css?raw&url now returns a URL to raw CSS

Is there a reason this is supported? I can't quite think of a case where a user would use this, using plain .css?raw and maybe manualChunks should be good enough. Was it for compat for .css?url in prod before?

@sapphi-red
Copy link
Member Author

  • .css?raw&url now returns a URL to raw CSS

Is there a reason this is supported? I can't quite think of a case where a user would use this, using plain .css?raw and maybe manualChunks should be good enough. Was it for compat for .css?url in prod before?

I added it for compat for .css?url in prod before. I'm fine removing it.

@sapphi-red sapphi-red changed the title fix(css): .css?url/.css?raw&url support fix(css): .css?url support Jan 10, 2024
@sapphi-red
Copy link
Member Author

In the last meeting, we discussed that we should add ?raw&url after we find a use case.


I removed the ?raw&url feature and rebased on main branch.

@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on f5106ac: Open

suite result latest scheduled
analogjs success success
astro success success
histoire failure failure
ladle success success
laravel failure failure
marko success success
nuxt success failure
nx success success
previewjs success success
qwik success success
rakkas success success
sveltekit success success
unocss failure failure
vike failure failure
vite-plugin-pwa success success
vite-plugin-react success success
vite-plugin-react-pages success success
vite-plugin-react-swc success success
vite-plugin-svelte failure failure
vite-plugin-vue success success
vite-setup-catalogue success success
vitepress failure failure
vitest success success

patak-dev
patak-dev previously approved these changes Jan 10, 2024
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Nuxt fail seems unrelated. Awesome work @sapphi-red 💚

@patak-dev patak-dev enabled auto-merge (squash) January 12, 2024 09:05
@patak-dev patak-dev merged commit ed56d96 into vitejs:main Jan 12, 2024
10 checks passed
@sapphi-red sapphi-red deleted the feat/css-url branch January 12, 2024 10:42
@josephmarkus
Copy link

There appears to be a similar issue with SCSS. Say I have:

import selectStyles from "somePackage/Select.scss?inline";

export const Theme = () => <style>{selectStyles}</style>;

And that Select.scss has

:root,
:host {
  --select-icon: url("./chevron.svg");
}

.selectStyles {
  background-image: var(--select-icon);
}

Vite thinks that ./chevron.svg is relative to the app and not node_modules and so tries to resolve it by looking up /assets/chevron.svg

@patak-dev
Copy link
Member

Hey @josephmarkus! Your comment in this merged PR will be quickly lost in the repo activity. Would you create a new issue with a minimal reproduction against the latest Vite so we can properly track the problem you are reporting?

@josephmarkus
Copy link

Was just filling in a bug report and whilst reproducing the error realised that my SCSS file imports another SCSS file, but if I target the end file directly, Vite resolves everything fine, so maybe not an issue 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Archived in project
4 participants