PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/node_modules/grunt-uncss/README.md

https://gitlab.com/danieldanielecki/ditectrev_v2
Markdown | 227 lines | 168 code | 59 blank | 0 comment | 0 complexity | 95bff8a2317de9028fa2a0a76d47bf9e MD5 | raw file
  1. # grunt-uncss [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
  2. [![NPM version](https://img.shields.io/npm/v/grunt-uncss.svg)](https://www.npmjs.com/package/grunt-uncss)
  3. [![Linux Build Status](https://img.shields.io/travis/addyosmani/grunt-uncss/master.svg?label=Linux%20build)](https://travis-ci.org/addyosmani/grunt-uncss)
  4. [![Windows Build status](https://img.shields.io/appveyor/ci/addyosmani/grunt-uncss/master.svg?label=Windows%20build)](https://ci.appveyor.com/project/addyosmani/grunt-uncss/branch/master)
  5. [![dependencies Status](https://img.shields.io/david/addyosmani/grunt-uncss.svg)](https://david-dm.org/addyosmani/grunt-uncss)
  6. [![devDependencies Status](https://img.shields.io/david/dev/addyosmani/grunt-uncss.svg)](https://david-dm.org/addyosmani/grunt-uncss?type=dev)
  7. >A grunt task for removing unused CSS from your projects with [UnCSS](https://github.com/giakki/uncss). Works across multiple files and supports dynamically injected CSS via PhantomJS.
  8. ## Getting Started
  9. If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the
  10. [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create
  11. a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins.
  12. Once you're familiar with that process, you may install this plugin with this command:
  13. ```shell
  14. npm install grunt-uncss --save-dev
  15. ```
  16. Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
  17. ```js
  18. grunt.loadNpmTasks('grunt-uncss');
  19. ```
  20. **Issues with the output should be reported on the UnCSS [issue tracker](https://github.com/giakki/uncss/issues).**
  21. ## Preview
  22. Taking a multi-page project using Bootstrap with >120KB of CSS down to 11KB.
  23. ![Demo](https://i.imgur.com/uhWMALH.gif)
  24. ## Uncss task
  25. *Run this task with the `grunt uncss` command.*
  26. Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
  27. ## Options
  28. Options are passed to [UnCSS](https://github.com/giakki/uncss#within-nodejs). In addition this task defines an extra option:
  29. ### report
  30. * Choices: `'min'`, `'gzip'`
  31. * Default: `'min'`
  32. Report minification result or both minification and gzip results.
  33. 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. [Example output](https://github.com/sindresorhus/maxmin#readme).
  34. ## Usage examples
  35. Use the `grunt-uncss` task by specifying a target destination (file) for your cleaned CSS.
  36. Below this is `dist/css/tidy.css`.
  37. Along-side, specify the input HTML files you would like scanned for used selectors.
  38. In this case `app/index.html` and `app/about.html` are the two files we would like checked.
  39. ```js
  40. uncss: {
  41. dist: {
  42. files: {
  43. 'dist/css/tidy.css': ['app/index.html', 'app/about.html']
  44. }
  45. }
  46. }
  47. ```
  48. Which you can then use alongside a processor like
  49. [processhtml](https://github.com/dciccale/grunt-processhtml) to
  50. rewrite the location of your stylesheet to `tidy.css` using a block like:
  51. ```html
  52. <!-- build:css css/tidy.css -->
  53. <link rel="stylesheet" href="css/normalize.css">
  54. <link rel="stylesheet" href="css/main.css">
  55. <link rel="stylesheet" href="css/bootstrap.css">
  56. <!-- /build -->
  57. ```
  58. and some configuration like:
  59. ```js
  60. processhtml: {
  61. dist: {
  62. files: {
  63. 'dist/index.html': ['app/index.html'],
  64. 'dist/about.html': ['app/about.html']
  65. }
  66. }
  67. }
  68. ```
  69. ```js
  70. // Remove unused CSS across multiple files
  71. uncss: {
  72. dist: {
  73. files: {
  74. 'dist/css/tidy.css': ['app/index.html', 'app/about.html']
  75. }
  76. }
  77. }
  78. ```
  79. ```js
  80. // Remove unused CSS across multiple files and ignore specific selectors
  81. uncss: {
  82. dist: {
  83. options: {
  84. ignore: ['#added_at_runtime', '.created_by_jQuery']
  85. },
  86. files: {
  87. 'dist/css/tidy.css': ['app/index.html', 'app/about.html']
  88. }
  89. }
  90. }
  91. ```
  92. ```js
  93. // Remove unused CSS from URLs (php, node, etc.)
  94. // (Note that`nonull` must be true, or else Grunt
  95. // removes remote paths that it can't find locally)
  96. uncss: {
  97. dist: {
  98. files: [{
  99. nonull: true,
  100. src: ['http://localhost:8080/path1', 'http://localhost:8080/path2'],
  101. dest: 'dist/css/tidy.css'
  102. }]
  103. }
  104. }
  105. ```
  106. ### Test project
  107. There is a test project included under the `tests/app` directory which you can build by running `grunt` after an `npm install`.
  108. It also includes a `grunt compare_size` task for getting a feel of the before and after CSS sizes:
  109. ![grunt compare_size](https://i.imgur.com/bUseCPh.png)
  110. ## Examples
  111. ### Sites
  112. * [HTML5Boilerplate.com website](https://github.com/h5bp/html5boilerplate.com)
  113. * [Mozilla's DXR documentation viewer](https://github.com/mozilla/dxr)
  114. * [Vanilla forums docs site](https://github.com/vanilla/vanilla-docs)
  115. ### Apps
  116. * [GitHub Team Viewer - Angular app](https://github.com/vinitkumar/github-team-viewer)
  117. * [Angular Todo application](https://github.com/JeremyCarlsten/grunt-uncss-angular-example)
  118. * [CashSplitter - Angular app with PouchDB, Bootstrap](https://github.com/carlo-colombo/CashSplitter)
  119. * [This Week's Comics Express app](https://github.com/WillsonSmith/thisWeeksComics)
  120. * [Sample grunt-uncss in a Sass project](https://github.com/addyosmani/grunt-uncss-sass-example)
  121. ### Other
  122. * [Using grunt-uncss with Wordpress](https://github.com/sboodhoo/Grunt-UnCSS-WordPress)
  123. * [JSON Sitemap generator for grunt-uncss](https://github.com/phoenixMag00/JSON-Sitemap-Generator-for-Grunt-UnCSS-with-WordPress)
  124. ## The problem
  125. User-interface libraries like [Bootstrap](https://getbootstrap.com), [TopCoat](http://topcoat.io)
  126. and so on are fairly prolific, however many developers use less than 10% of the CSS they provide
  127. (when opting for the full build, which most do). As a result, they can end up with fairly bloated
  128. stylesheets which can significantly increase page load time and affect performance.
  129. `grunt-uncss` is an attempt to help with by generating a CSS file containing only the CSS used
  130. in your project, based on selector testing.
  131. ## Research and alternative solutions
  132. There have been many efforts to try solving the problem of finding unused CSS in the past. Opera created
  133. [ucss](https://github.com/oyvindeh/ucss), @aanand created <https://github.com/aanand/deadweight>,
  134. Brian Le Roux [CSS Slap Chop](https://github.com/brianleroux/css-slap-chop) and there were a number of
  135. client-side solutions also crafted, such as [Helium-CSS](https://github.com/geuis/helium-css),
  136. [CSSESS](https://github.com/driverdan/cssess) and the Python [mincss](https://www.peterbe.com/plog/mincss).
  137. Unfortunately, most of these solutions don't actually generate what you're really after - a leaner build
  138. of your project CSS containing only those rules you used. Finding that a more recent project called
  139. [UnCSS](https://github.com/giakki/uncss) did try tackling this, I set out to share some of the problems we
  140. need to solve in this space with the developer and build a Grunt task to enable usage of it in builds more
  141. easily.
  142. Huge thanks go out to Giacomo Martino for his help with the Node module this task uses.
  143. ## Coverage
  144. * [Spring-cleaning unused CSS with Grunt, Gulp & other build systems](https://addyosmani.com/blog/removing-unused-css/)
  145. * [Automating the removal of unused CSS - VelocityConf](https://www.youtube.com/watch?v=833xr1MyE30)
  146. * [Use Grunt and UnCSS to speed up the load time of your site](http://xdamman.com/website-optimization-grunt-uncss)
  147. * [Foundation 5, Sass and Grunt UnCSS](https://corydowdy.com/blog/foundation-5-sass-and-grunt-uncss)
  148. * [Automating Front-end Workflow (slides)](https://speakerdeck.com/addyosmani/automating-front-end-workflow)
  149. * [Automatically removing unused CSS - Windows](http://deanhume.com/Home/BlogPost/automatically-removing-unused-css-using-grunt/6101)
  150. * [Workflow for responsive email with Grunt and UnCSS](https://medium.com/p/32d607879082)
  151. ## WordPress
  152. While UnCSS works best (and quickest) with static HTML files, it is possible to pass in
  153. a URL array that contains all the URLs on your website, and process all used selectors that way.
  154. [@lgladdy](https://github.com/lgladdy) wrote a guide on how to do this
  155. [on his blog](https://gladdy.uk/blog/2014/04/13/using-uncss-and-grunt-uncss-with-wordpress/)
  156. ## Yeoman Generator
  157. If you're looking for a webapp starting point with grunt-uncss integrated, see [generator-webapp-uncss](https://github.com/addyosmani/generator-webapp-uncss).
  158. ## Limitations
  159. Please note that the CSS parser used in the `uncss` module we rely on currently isn't able to work with complex selectors.
  160. For example `[data-section=''] > section > [data-section-title] a`. This may mean that at build time you run into exceptions
  161. such as `TypeError: Cannot convert undefined or null to object`. If this is the case, please consider moving these selectors
  162. to a separate stylesheet which the task does not run on.
  163. We are actively looking at how to improve the CSS parsers used and will update this notice once this problem has been solved.
  164. ## Maintainers
  165. * [@addyosmani](https://github.com/addyosmani)
  166. * [@XhmikosR](https://github.com/XhmikosR)
  167. ## License
  168. (C) Addy Osmani 2016, released under the MIT license