You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0 KiB

  1. # grunt-contrib-cssmin [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-cssmin.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-cssmin)
  2. > Compress CSS files.
  3. ## Getting Started
  4. This plugin requires Grunt `~0.4.0`
  5. If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
  6. ```shell
  7. npm install grunt-contrib-cssmin --save-dev
  8. ```
  9. Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
  10. ```js
  11. grunt.loadNpmTasks('grunt-contrib-cssmin');
  12. ```
  13. *This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that [you upgrade](http://gruntjs.com/upgrading-from-0.3-to-0.4), but in case you can't please use [v0.3.2](https://github.com/gruntjs/grunt-contrib-cssmin/tree/grunt-0.3-stable).*
  14. ## Cssmin task
  15. _Run this task with the `grunt cssmin` command._
  16. Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
  17. Files are compressed with [clean-css](https://github.com/GoalSmashers/clean-css).
  18. ### Options
  19. #### banner
  20. Type: `String`
  21. Default: `null`
  22. Prefix the compressed source with the given banner, with a linebreak inbetween.
  23. #### keepSpecialComments
  24. Type: `String` `Number`
  25. Default: `'*'`
  26. To keep or remove special comments, exposing the underlying option from [clean-css](https://github.com/GoalSmashers/clean-css).. `'*'` for keeping all (default), `1` for keeping first one, `0` for removing all.
  27. #### report
  28. Choices: `false`, `'min'`, `'gzip'`
  29. Default: `false`
  30. Either do not report anything, report only minification result, or report minification and gzip results.
  31. This is useful to see exactly how well clean-css is performing but using `'gzip'` will make the task take 5-10x longer to complete.
  32. Example ouput using `'gzip'`:
  33. ```
  34. Original: 198444 bytes.
  35. Minified: 101615 bytes.
  36. Gzipped: 20084 bytes.
  37. ```
  38. ### Usage Examples
  39. #### Combine two files into one output file
  40. ```js
  41. cssmin: {
  42. combine: {
  43. files: {
  44. 'path/to/output.css': ['path/to/input_one.css', 'path/to/input_two.css']
  45. }
  46. }
  47. }
  48. ```
  49. #### Add a banner
  50. ```js
  51. cssmin: {
  52. add_banner: {
  53. options: {
  54. banner: '/* My minified css file */'
  55. },
  56. files: {
  57. 'path/to/output.css': ['path/to/**/*.css']
  58. }
  59. }
  60. }
  61. ```
  62. #### Minify all contents of a release directory and add a `.min.css` extension
  63. ```js
  64. cssmin: {
  65. minify: {
  66. expand: true,
  67. cwd: 'release/css/',
  68. src: ['*.css', '!*.min.css'],
  69. dest: 'release/css/',
  70. ext: '.min.css'
  71. }
  72. }
  73. ```
  74. ## Release History
  75. * 2013-05-25   v0.6.1   Support import in-lining vis clean-css ~1.0.4.
  76. * 2013-04-05   v0.6.0   Update clean-css dependency to ~1.0.0
  77. * 2013-03-14   v0.5.0   Support for 'report' option (false by default)
  78. * 2013-03-10   v0.4.2   Add banner option Support clean-css keepSpecialComments
  79. * 2013-02-17   v0.4.1   Update clean-css dependency to ~0.10.0
  80. * 2013-02-15   v0.4.0   First official release for Grunt 0.4.0.
  81. * 2013-01-23   v0.4.0rc7   Updating grunt/gruntplugin dependencies to rc7. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.
  82. * 2013-01-09   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Switching to this.files api.
  83. * 2012-11-01   v0.3.2   Update clean-css dep.
  84. * 2012-10-12   v0.3.1   Rename grunt-contrib-lib dep to grunt-lib-contrib.
  85. * 2012-09-23   v0.3.0   Options no longer accepted from global config key.
  86. * 2012-09-10   v0.2.0   Refactored from grunt-contrib into individual repo.
  87. ---
  88. Task submitted by [Tim Branyen](http://goingslowly.com/)
  89. *This file was generated on Sat May 25 2013 18:52:13.*