Merges duplicate media queries into one rule, appended to the bottom of your stylesheet. This allows you to write your media queries "inline" but still combine them into one rule to avoid code duplication.
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-merge-media --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-merge-media');
In your project's Gruntfile, add a section named merge_media
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
merge_media: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
Type: Boolean
Default value: false
A Boolean value that will switch the compression of the processed file. This is passed straight into the stringify
method in css.
Type: Boolean
Default value: false
When set to true
, a log file with details of the merge will be created in the working directory.
grunt.initConfig({
merge_media: {
options: {
compress: true,
logFile: true
},
files: {
'styles/css': ['styles/base.css', 'styles/layout/*.css'],
},
}
});
If the file destination is a folder, the stylesheet will be created in that folder with the same name as the original. Otherwise, it will be created in the exact path specified.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- 2014-11-21 v0.4.0 Adds support for nested media queries
- 2014-11-21 v0.3.0 Adds log file
- 2014-11-21 v0.2.3 Initial release