From a mobile-first static CSS file (minified) I'd like to remove all @media queries, so that the site will always show as on mobile, is there any command/tool to process (.min).css files in that way? (I'm looking around but found nothing yet)



I found and used postcss-filter-mq that removed the media queries correctly but something else is wrong with the website.

For anyone who could be interested, initialize a npm project

npm init

Install postcss and the media query filter

npm install --save-dev postcss postcss-filter-mq

add/edit index.js

var postcss = require("postcss"),
    filtermq = require("postcss-filter-mq"),
    fs = require('fs');

fs.readFile('input.min.css', function(err, css) {    
    postcss([ filtermq({invert: true, keepBaseRules: true}) ])
        .process(css, { from: "input.min.css", to: "output.min.css" })
        .then(function (result) {
            fs.writeFileSync("output.min.css", result.css);
            if ( result.map ) fs.writeFileSync("output.min.css.map", result.map);

run with node index.js, input/output filenames wired in the code (input.min.css output.min.css ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.