-
-
Notifications
You must be signed in to change notification settings - Fork 601
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
@import
with media query produces incorrect output when the imported file is a entry point
#1503
@import
with media query produces incorrect output when the imported file is a entry point
#1503
Comments
Seems I found a solution by adding |
Fix regression from go-gitea#23481. The conditional CSS import was being stripped away by webpack's `css-loader`, resulting in the dark theme always loading. Unfortunately, we have to re-introduce postcss to the CSS pipeline to fix this and I loaded only the minimal plugins to make it work. Related: webpack-contrib/css-loader#1503
Fix regression from #23481. The conditional on the CSS import was being stripped away by webpack's `css-loader`, resulting in the dark theme always loading. The old syntax with `@import` nested inside `@media` also did not work as `css-loader` (rightfully) ignores such non-standard `@import` syntax that was previously supported by Less. Unfortunately, we have to re-introduce postcss to the CSS pipeline to fix this and I loaded only the minimal plugins to make it work. There is one variant of the fix that does work without postcss, which is to exclude the file from transpilation but I did not consider it as it would have meant the `@import` was being done without a version suffix in the URL, which would have caused cache issue. Related: webpack-contrib/css-loader#1503 --------- Co-authored-by: John Olheiser <[email protected]>
Are you sure you are using the latest version? It was implement a long time ago, we supports
|
Anyway feel free to feedback, and check |
This was the setup where I observed it: No |
As you can see we have another result... I can provie history when it was implemented and can provide usage in other repos |
Sure thanks, that's more than I expected from this issue. Now it's on me to debug further :) |
Hm, you have vue-loader, and they are registering own style-loader (which I think doesn't support it), where do you use this styles? |
Can you try to create simple CSS file and do it, like I done in tests |
I really want to help, but as you can see we don't have problem inside css-loader |
Just this plain CSS file, so https://github.com/go-gitea/gitea/blob/main/web_src/css/themes/theme-auto.css |
Yes, I will try to make a minimal webpack repro. |
Vue plugin can register a loader on |
Okay, let me see what happens if I remove |
Yeah, let's try, it is the first place where we potentially can have a probem |
Yeah, I will keep open, feel free to ping me |
Just fyi, the minimal repro so far does not reproduce it, so it's definitely something else in that config interfering. https://github.com/silverwind/media-url It correctly outputs @media (prefers-color-scheme: dark) {
body { background: black }
} Will check further what else in the full config could be a cause. |
To be honest, I don't see anything criminal in the configuration... |
Added the original CSS files to https://github.com/silverwind/media-url, now it reproduces and the
Trying to reduce this further now... |
Yep, as soon as I remove the separate entry point for the file that is being imported, the |
I see...give me time to think how I can fix it and there is a problem (I think in MiniCssExtractPlugin.loader, but need check) |
https://github.com/silverwind/media-url is minimal again. With the two entry points, it fails to emit dark: fileURLToPath(new URL('dark.css', import.meta.url)),
index: fileURLToPath(new URL('index.css', import.meta.url)), If I remove the |
@import url list-of-media-queries
@import
with media query produces incorrect output when the imported file is a entry point
Fix regression from go-gitea#23481. The conditional on the CSS import was being stripped away by webpack's `css-loader`, resulting in the dark theme always loading. The old syntax with `@import` nested inside `@media` also did not work as `css-loader` (rightfully) ignores such non-standard `@import` syntax that was previously supported by Less. Unfortunately, we have to re-introduce postcss to the CSS pipeline to fix this and I loaded only the minimal plugins to make it work. There is one variant of the fix that does work without postcss, which is to exclude the file from transpilation but I did not consider it as it would have meant the `@import` was being done without a version suffix in the URL, which would have caused cache issue. Related: webpack-contrib/css-loader#1503 --------- Co-authored-by: John Olheiser <[email protected]>
Yes, I was right, the problem is in the mini-css-extract-plugin, a fix is simple:
https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/index.js#L168 I am very tired today because I moved to a new country and will send a PR and will do release tomorrow, but if you want to send a PR yourself, feel free you have the fix and the test case, in this case I will do just release 😄 |
No hurry, we have a workaround via postcss until then. But I'll be very happy to rip it out again after this fix is in 😄. |
Should work 👍 |
Confirmed, thanks for the quick fix! 🎉 |
Follow-up and proper fix for #23504 Update to [[email protected]](https://github.com/webpack-contrib/mini-css-extract-plugin/releases/tag/v2.7.4) which fixes our specific issue described in webpack-contrib/css-loader#1503 and which allows us to again drop the postcss dependency. Backport of this is not necessary as I have included it in #23508. Co-authored-by: techknowlogick <[email protected]>
Feature Proposal
Support @import
list-of-media-queries
syntax. Currently the plugin ignores and strips the media query from the output, making runtime-conditional import impossible without additional plugins.Feature Use Case
Currently the plugin outputs the content of
dark.css
file without any media query condition, so the CSS is applied unconditionally at runtime:/* content of dark.css */
A better output would be:
The text was updated successfully, but these errors were encountered: