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

CSS custom media not working in development mode #402

Open
azat-io opened this issue Jan 19, 2023 · 4 comments
Open

CSS custom media not working in development mode #402

azat-io opened this issue Jan 19, 2023 · 4 comments

Comments

@azat-io
Copy link
Contributor

azat-io commented Jan 19, 2023

I created a demo repo:
https://github.com/azat-io/lightningcss-custom-media

Look it up please.

If you run the command pnpm start, @custom-media will not work.
But if you build the project with pnpm build, everything will work correctly.

@devongovett
Copy link
Member

Unfortunately, the Vite plugin can only process one file at a time so @custom-media defined in a separate file cannot work. Vite would need to switch to using the Lightning CSS bundler in order for us to make this work. Please see vitejs/vite#11029

@azat-io
Copy link
Contributor Author

azat-io commented Jan 19, 2023

@devongovett This code also not works in development mode:

@custom-media --screen-tablet (width >= 860px);

body {
  background: blue
}

@media (--screen-tablet) {
  body {
    background: red;
  }
}

@devongovett
Copy link
Member

Seems to work in the playground.

Make sure that you are setting a browserslist though, or nothing will be compiled. Even though no browser supports@custom-media currently, we need to compile only based on targets for forward compatibility.

@azat-io
Copy link
Contributor Author

azat-io commented Jan 19, 2023

@devongovett I set browserslist but nothing changed.

I updated my repo: https://github.com/azat-io/lightningcss-custom-media

Could you try to run this project?

  1. pnpm install
  2. pnpm start

I expect a red screen but it's blue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants