From a14e0b7ad799da30855f84d10760dcff2e0bcbe2 Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sat, 4 Oct 2014 20:57:54 +0100 Subject: [PATCH] Add support for grunt-uncss This patch adds grunt-uncss support to the project. It brings uncss configuration to the Gruntfile, disables usemin using the cssmin step and instead adds a custom set of cssmin configuration. The basic idea here is that we take the temporary (.tmp) output from the Autoprefixer step (you can change paths if not using it) and then run it through uncss being doing any minification. Along the way we pass in any other stylesheets being used, like Bootstrap. Works with both the Bootstrap and Sass Bootstrap options. --- app/USAGE | 2 +- app/index.js | 4 +-- app/templates/Gruntfile.js | 61 +++++++++++++++++++++++++++---------- app/templates/_package.json | 3 +- package.json | 4 +-- 5 files changed, 52 insertions(+), 22 deletions(-) diff --git a/app/USAGE b/app/USAGE index 6ae3898..61e5c38 100644 --- a/app/USAGE +++ b/app/USAGE @@ -5,7 +5,7 @@ Options: Bootstrap: Include Bootstrap for Sass Example: - yo webapp [--coffee] + yo webapp-uncss [--coffee] This will create: Gruntfile.js: Configuration for the task runner. diff --git a/app/index.js b/app/index.js index 854d98c..6fe5ccd 100644 --- a/app/index.js +++ b/app/index.js @@ -33,8 +33,8 @@ module.exports = yeoman.generators.Base.extend({ if (!this.options['skip-welcome-message']) { this.log(require('yosay')()); this.log(chalk.magenta( - 'Out of the box I include HTML5 Boilerplate, jQuery, and a ' + - 'Gruntfile.js to build your app.' + 'Out of the box I include HTML5 Boilerplate, jQuery, a ' + + 'Gruntfile.js and UnCSS setup for you.' )); } diff --git a/app/templates/Gruntfile.js b/app/templates/Gruntfile.js index 4f13671..3d980da 100644 --- a/app/templates/Gruntfile.js +++ b/app/templates/Gruntfile.js @@ -265,12 +265,22 @@ module.exports = function (grunt) { // concat, minify and revision files. Creates configurations in memory so // additional tasks can operate on them useminPrepare: { + html: '<%= config.dist %>/index.html', options: { - dest: '<%%= config.dist %>' - }, - html: '<%%= config.app %>/index.html' + dest: '<%= config.dist %>', + flow: { + html: { + steps: { + // Disabled as we'll be using a manual + // cssmin configuration later. This is + // to ensure we work well with grunt-uncss + // css: ['cssmin'] + }, + post: {} + } + } + } }, - // Performs rewrites based on rev and the useminPrepare configuration usemin: { options: { @@ -284,6 +294,25 @@ module.exports = function (grunt) { css: ['<%%= config.dist %>/styles/{,*/}*.css'] }, + uncss: { + dist: { + options: { + // Take our Autoprefixed stylesheet main.css & + // any other stylesheet dependencies we have.. + stylesheets: [ + '../.tmp/styles/main.css', + <% if (includeBootstrap && !includeSass) { %>'../bower_components/bootstrap/dist/css/bootstrap.css'<% } %> + ], + // Ignore css selectors for async content with complete selector or regexp + // Only needed if using Bootstrap + ignore: [/dropdown-menu/,/\.collapsing/,/\.collapse/] + }, + files: { + '.tmp/styles/main.css': ['<%%= config.app %>/index.html'] + } + } + }, + // The following *-min tasks produce minified files in the dist folder imagemin: { dist: { @@ -332,16 +361,15 @@ module.exports = function (grunt) { // By default, your `index.html`'s will take care // of minification. These next options are pre-configured if you do not // wish to use the Usemin blocks. - // cssmin: { - // dist: { - // files: { - // '<%%= config.dist %>/styles/main.css': [ - // '.tmp/styles/{,*/}*.css', - // '<%%= config.app %>/styles/{,*/}*.css' - // ] - // } - // } - // }, + cssmin: { + dist: { + files: { + '<%%= config.dist %>/styles/main.css': [ + '.tmp/styles/{,*/}*.css' + ] + } + } + }, // uglify: { // dist: { // files: { @@ -481,9 +509,10 @@ module.exports = function (grunt) { 'useminPrepare', 'concurrent:dist', 'autoprefixer', - 'concat', + 'uncss', 'cssmin', - 'uglify', + //'concat', + //'uglify', 'copy:dist',<% if (includeModernizr) { %> 'modernizr',<% } %> 'rev', diff --git a/app/templates/_package.json b/app/templates/_package.json index 9a43cc3..a89c595 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -28,7 +28,8 @@ "grunt-wiredep": "^1.7.0", "jshint-stylish": "^0.4.0", "load-grunt-tasks": "^0.4.0", - "time-grunt": "^0.4.0" + "time-grunt": "^0.4.0", + "grunt-uncss": "*" }, "engines": { "node": ">=0.10.0" diff --git a/package.json b/package.json index c7d9a79..1de0614 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "generator-webapp-uncss", - "version": "0.5.0", + "version": "0.1.0", "description": "Scaffold out a front-end web app", "license": "BSD", - "repository": "yeoman/generator-webapp", + "repository": "addyosmani/generator-webapp-uncss", "author": "The Yeoman Team", "main": "app/index.js", "engines": {