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

url() in a CSS file imported by @import is not resolved correctly when using lightningcss #16457

Open
7 tasks done
ghost opened this issue Apr 18, 2024 · 5 comments
Open
7 tasks done
Labels
feat: css has workaround p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@ghost
Copy link

ghost commented Apr 18, 2024

Describe the bug

url() inside a CSS file that is imported from a CSS file by @import is not resolved correctly when using css.transformer: 'lightningcss'. The same source code works with css.transformer: 'postcss'.

original description

Hello.
When a CSS file is imported with .css?inline, it is correctly minified and transformed with css.transformer=postcss and build.cssMinify=esbuild.

When I change to build.cssMinify=lightningcss, the build process still works correctly. 👍

However, when I change to css.transformer=lightningcss in vite.config.js, then the .css?inline isn't recognized anymore and when I run the build process of Vite, it prints a message in the console: "(...).css?inline didn't resolve at build time, it will remain unchanged to be resolved at runtime" 👎

In the documentation, nothing is said about .css?inline being specific to postcss, so I expected it would work with lightningcss too.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-cil2qs?file=vite.config.js,src%2Fpages%2Fbeginning.css

Steps to reproduce

Run the script _vite:build.
You are going to see that the image Border.avif is not built into the dist folder, because the app.css file was not considered in the build process. I tried debugging and at least discarded the plugins as the cause.

System Info

System:
    OS: Linux 6.5 Ubuntu 23.10 23.10 (Mantic Minotaur)
    CPU: (1) x64 Intel Celeron N4020 Core(TM) N4020
    Memory: 15.11 GB / 15.34 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 21.7.2 - ~/.nvm/versions/node/v21.7.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v21.7.2/bin/npm

Used Package Manager

npm

Logs

No response

Validations

@ghost ghost added the pending triage label Apr 18, 2024
Copy link

stackblitz bot commented Apr 18, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

Copy link

Hello @1GBpendrive. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@sapphi-red
Copy link
Member

Ah, Vite's build script doesn't work on the reproduction on stackblitz, but it works correctly locally.

It seems to happen because dependencies field was upper case. If I fix that, I got a different error (Could not resolve entry module "./app.js".) that is valid.
https://stackblitz.com/edit/vitest-dev-vitest-bsvjcm?file=package.json

@ghost
Copy link
Author

ghost commented Apr 19, 2024

Thank you @sapphi-red
Please see this StackBlitz: https://stackblitz.com/edit/vitest-dev-vitest-pezgng
The problem mentioned before is seen when running the script _vite:build.
You are going to see that the image Border.avif is not built into the dist folder, because the app.css file was not considered in the build process. I tried debugging and at least discarded the plugins as the cause.

@sapphi-red sapphi-red added feat: css has workaround p3-minor-bug An edge case that only affects very specific usage (priority) and removed needs reproduction labels Apr 20, 2024
@sapphi-red sapphi-red changed the title .css?inline is not working with Lightning CSS url() in a CSS file imported by @import is not resolved correctly with lightningcss Apr 20, 2024
@sapphi-red sapphi-red changed the title url() in a CSS file imported by @import is not resolved correctly with lightningcss url() in a CSS file imported by @import is not resolved correctly when using lightningcss Apr 20, 2024
@sapphi-red
Copy link
Member

I was able to reproduce with that. I trimmed down the reproduction and clarified the issue description.

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

No branches or pull requests

1 participant