Skip to content

Instantly share code, notes, and snippets.

@tilomitra
Last active January 2, 2016 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tilomitra/8321165 to your computer and use it in GitHub Desktop.
Save tilomitra/8321165 to your computer and use it in GitHub Desktop.
updated grunt-stripmq to work with css-media-match
'use strict';
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// Configuration to be run (and then tested).
stripmq: {
options: {
width: 1024,
type: 'screen'
},
all: {
files: {
'test/output.css': ['test/input.css']
}
}
}
});
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'stripmq']);
};
body {
background: url('mobile-background.png');
}
@media screen and (min-width: 640px) {
body {
background: url('tablet-background.png');
}
}
@media screen and (max-width: 800px) {
body {
background: url('until-800px-background.png');
}
}
@media (min-width: 900px) {
body {
background: url('desktop-background.png');
}
}
@media screen and (min-width: 1200px) {
body {
background: url('large-background.png');
}
}
@media (monochrome) {
body {
background: black;
}
}
body {
background: url('mobile-background.png');
}
body {
background: url('tablet-background.png');
}
body {
background: url('desktop-background.png');
}
'use strict';
var parse = require('css-parse'),
stringify = require('css-stringify'),
doesMQMatch = require('css-media-match');
function stripMediaQueries (ast, options) {
ast.stylesheet.rules = ast.stylesheet.rules.reduce(function (tree, rule) {
if (rule.type === 'media') {
if (doesMQMatch(rule.media, options)) {
tree.push.apply(tree, rule.rules);
}
}
else {
tree.push(rule);
}
return tree;
}, []);
return ast;
}
/**
* strip media queries
* @param {string} input
* @returns {string} output
*/
function StripMQ(input, options) {
var tree = parse(input);
tree = stripMediaQueries(tree, options);
return stringify(tree);
}
module.exports = StripMQ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment