Last active
January 2, 2016 15:09
-
-
Save tilomitra/8321165 to your computer and use it in GitHub Desktop.
updated grunt-stripmq to work with css-media-match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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']); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: url('mobile-background.png'); | |
} | |
body { | |
background: url('tablet-background.png'); | |
} | |
body { | |
background: url('desktop-background.png'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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