Skip to content

How to discard a media query along with its content? #679

Closed Answered by Stigjb
Stigjb asked this question in Q&A
Discussion options

You must be logged in to vote

I found the solution. MediaQuery was the wrong visitor here, but a Rule visitor did the trick. Here is my solution:

const { code } = transform({
  filename: 'test.css',
  code: Buffer.from(styleString),
  minify: true,
  visitor: {
    Rule(rule) {
      if (rule.type === 'media') {
        if (rule.value.query.mediaQueries.some((q) => q.mediaType === 'print')) {
          return [];
        }
      }
      return rule;
    },
  },
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Stigjb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant