Skip to content

Commit

Permalink
Add support for grunt-uncss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
addyosmani committed Oct 4, 2014
1 parent b997f9f commit a14e0b7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
));
}

Expand Down
61 changes: 45 additions & 16 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -332,16 +361,15 @@ module.exports = function (grunt) {
// By default, your `index.html`'s <!-- Usemin block --> 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: {
Expand Down Expand Up @@ -481,9 +509,10 @@ module.exports = function (grunt) {
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'uncss',
'cssmin',
'uglify',
//'concat',
//'uglify',
'copy:dist',<% if (includeModernizr) { %>
'modernizr',<% } %>
'rev',
Expand Down
3 changes: 2 additions & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit a14e0b7

Please sign in to comment.