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

[Feature Request] Add a media query only compiler option #2477

Closed
cmahnke opened this issue Jan 7, 2025 · 2 comments
Closed

[Feature Request] Add a media query only compiler option #2477

cmahnke opened this issue Jan 7, 2025 · 2 comments

Comments

@cmahnke
Copy link
Contributor

cmahnke commented Jan 7, 2025

Use case

I'm currently using SASS to provide styles to an HTML to print (PDF) workflow. I would like to be able to use the provided stylesheet to web pages as well. While this works in one direction using media queries, the other way doesn't since the PDF rendering mechanism ignore @media print queries.

Solution

Provide a mechanism (for the JS API) to able to pass a media query to sass.compile, as in sass.compile(scssFilename, 'print') that would only return the flattened stylesheet with resolved attributes according to the @media print. That is screen related / only styles won't be part of the result. Same should be possible for the CLI interface.

Possible alternatives

Not yet checked, but maybe this could be done via PostCSS (and a hand crafted plugin) as well.

Disclaimer: Even though this uses the JS API as an example, it shouldn't be limited to this specific API. But needs to be added to the core first. If this is the wrong repository for such a request please move.

@ntkme
Copy link
Contributor

ntkme commented Jan 7, 2025

I suppose you can split the media=print stylesheet as a dedicated sass/css file (without @media in the file), and just link it separately in the HTML file:

<link rel="stylesheet" href="print.css" media="print">

If you really, really want to have everything in the same input file, and create multiple outputs by filtering based on certain rules, that's exactly what PostCSS is designed for.

@jathak
Copy link
Member

jathak commented Jan 7, 2025

Yes, this does seem like a better fit for a PostCSS plugin.

@jathak jathak closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
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

3 participants