Skip to content

Instantly share code, notes, and snippets.

@thpoiani
Created March 25, 2014 03:55
Show Gist options
  • Save thpoiani/9755004 to your computer and use it in GitHub Desktop.
Save thpoiani/9755004 to your computer and use it in GitHub Desktop.
Concat normalize.css in css files using Grunt
/**
* Gruntfile loading external tasks
*
* ./Gruntfile.js
*
* @param grunt
* @author Thiago Poiani <[email protected]>
*/
module.exports = function (grunt) {
'use strict';
// load tasks directory
grunt.loadTasks('grunt_tasks');
grunt.registerTask('default', ['normalize-concat']);
};
/**
* Task for concat normalize.css in all css files inside the directory ./css
*
* ./grunt_tasks/normalize-concat.js
*
* @param grunt
* @author Thiago Poiani <[email protected]>
*/
module.exports = function (grunt) {
'use strict';
var normalize, css, files, name, concat;
// normalize.css path
// bower install normalize.css --save
normalize = './bower_components/normalize.css/normalize.css';
// css files path
css = './css/';
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('normalize-concat', function () {
// all .css files
files = grunt.file.expand(css + '*.css');
files.forEach(function (file) {
// css file name
name = file.replace(css, '');
concat = grunt.config.get('concat') || {};
concat[name] = {
src: [normalize, file],
dest: file
};
grunt.config.set('concat', concat);
});
grunt.task.run('concat');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment