Table of Contents for
Mastering PostCSS for Web Design

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Mastering PostCSS for Web Design by Alex Libby Published by Packt Publishing, 2016
  1. Cover
  2. Table of Contents
  3. Mastering PostCSS for Web Design
  4. Mastering PostCSS for Web Design
  5. Credits
  6. About the Author
  7. About the Reviewer
  8. www.PacktPub.com
  9. Preface
  10. What you need for this book
  11. Who this book is for
  12. Conventions
  13. Reader feedback
  14. Customer support
  15. 1. Introducing PostCSS
  16. Introducing PostCSS
  17. Setting up a development environment
  18. Creating a simple example using PostCSS
  19. Linting code using plugins
  20. Exploring how PostCSS works
  21. Summary
  22. 2. Creating Variables and Mixins
  23. Creating a hover effect example
  24. Transitioning to using PostCSS
  25. Adding variable support to PostCSS
  26. Updating our hover effect demo
  27. Setting the order of plugins
  28. Creating mixins with PostCSS
  29. Looping content with PostCSS
  30. Summary
  31. 3. Nesting Rules
  32. Navigating through pages
  33. Transitioning to using PostCSS plugins
  34. Exploring the pitfalls of nesting
  35. Making the switch to BEM
  36. Exploring our changes in more detail
  37. Summary
  38. 4. Building Media Queries
  39. Exploring custom media queries in PostCSS
  40. Making images responsive
  41. Adding responsive text support
  42. Optimizing media queries
  43. Retrofitting support for older browsers
  44. Moving away from responsive design
  45. Taking things further with CSS4
  46. Summary
  47. 5. Managing Colors, Images, and Fonts
  48. Managing fonts with PostCSS
  49. Creating image sprites
  50. Working with SVG in PostCSS
  51. Adding support for WebP images
  52. Manipulating colors and color palettes
  53. Creating color functions with PostCSS
  54. Summary
  55. 6. Creating Grids
  56. Creating an example with Bourbon Neat
  57. Exploring the grid plugins in PostCSS
  58. Transitioning to using PostCSS-Neat
  59. Creating a site using Neat and PostCSS
  60. Adding responsive capabilities
  61. Summary
  62. 7. Animating Elements
  63. Moving away from jQuery
  64. Making use of pre-built libraries
  65. Switching to using SASS
  66. Making the switch to PostCSS
  67. Exploring plugin options within PostCSS
  68. Updating code to use PostCSS
  69. Creating a demo in PostCSS
  70. Optimizing our animations
  71. Using our own animation plugin
  72. Summary
  73. 8. Creating PostCSS Plugins
  74. Dissecting the architecture of a standard plugin
  75. Creating an transition plugin
  76. Building a custom font plugin
  77. Simplifying the development process
  78. Guidelines for plugin building
  79. Making the plugin available for use
  80. Summary
  81. 9. Working with Shortcuts, Fallbacks, and Packs
  82. Exploring plugin packs for PostCSS
  83. Adding shortcuts with Rucksack
  84. Linting and optimizing your code
  85. Providing fallback support
  86. Summary
  87. 10. Building a Custom Processor
  88. Exploring our processor
  89. Dissecting issues with our processor
  90. Optimizing the output
  91. Adding reload capabilities
  92. Extending our processor further
  93. Testing the final pre-processor
  94. Getting started with some hints and tips
  95. Introducing the CSStyle library
  96. Summary
  97. 11. Manipulating Custom Syntaxes
  98. Preparing our environment
  99. Implementing custom syntax plugins
  100. Parsing CSS
  101. Formatting the output with the API
  102. Highlighting our syntax code
  103. Summary
  104. 12. Mixing Preprocessors
  105. Exploring the conversion process
  106. Introducing the Pleeease library
  107. Compiling with other preprocessors
  108. Using the PreCSS library
  109. Converting a WordPress installation
  110. Setting up our environment
  111. Considering the conversion process
  112. Making changes to our code
  113. Compiling and testing the changes
  114. Summary
  115. 13. Troubleshooting PostCSS Issues
  116. Exploring some common issues
  117. Getting help from others
  118. Summary
  119. 14. Preparing for the Future
  120. Converting CSS4 styles for use
  121. Supporting future syntax with cssnext
  122. Creating plugins to provide extra CSS4 support
  123. Summary
  124. Index

Testing the final pre-processor

Throughout this book, we've explored a number of different plugins and concepts to help construct a processor; over the last few pages, we've brought together some of those concepts as the final version of our processor—at least one we can start using in anger.

There is one key step left to complete—we've compiled code for simple exercises, this works well, but doesn't really represent the kind of processes we might go through as developers! For this, we need to construct a real-world example, and put our processor through its paces.

As luck would have it, there is an example web page we can use from the code download that accompanies this book—let's take a look at putting its style sheet code through our processor. We'll begin by running the normal tasks we've done before, but will add a selection of plugins to make for a more realistic example:

  1. We'll start by extracting a copy of the T55 - testing our processor folder from the code download that accompanies this book; go ahead and save it to the root of our project area.
  2. Copy the gulpfile.js and package.json files from within this sub-folder to the root of our project area.
  3. Fire up a Node.js command prompt, then change the working folder to our project area.
  4. In the prompt, go ahead and enter these three lines, pressing Enter after each:
    npm install postcss-nesting --save-dev
    npm install postcss-short-color --save-dev
    npm install postcss-pixrem
    
  5. Copy the site.css file from within the css – completed version folder under T55 – testing our processor, to the src folder at the root of our project area.
  6. Revert to the Node.js session, then enter gulp at the prompt and press Enter—wait for it to complete compiling.
  7. When compilation has finished, copy the contents of the dest folder to the css folder within T55 – testing our processor.
  8. Try previewing the results of the compiled file—if all is well, we should see something akin to this screenshot:
    Testing the final pre-processor

Try resizing the browser window, or enabling Responsive Design mode in your browser (if supported)—we should see that content automatically flows or resizes, according to the size you set for the browser window. Overall, a successful result!

The question is—what happened here? If we take a look at our code, the sharp-eyed should spot the addition of three plugins, plus a lot more code in the compiled version; let's take a moment to digest the results of our exercise.

Digesting the results of our exercise

If we look through our Gulp task file carefully, there should not be much in there that comes as a surprise—many of the tasks used are ones we have used on many occasions throughout the book.

The key here, though, is that whilst we can run the standard processor that we've already used before, it's unlikely to suit all occasions. It's more likely that we can use it as our base (as stated earlier), then add any extra plugins as needed. The great thing about this is that most of the configuration work is done—it keeps a consistent approach to our work. All that remains is to install any plugins that we don't already have in place—we of course have most of them, but need to install three additional ones, as highlighted here:

gulp.task('styles', function () {
  return gulp.src('src/*.css')
    .pipe(postcss([ rucksack({ fallbacks: true }), autoprefixer(), shortcolor, nesting, pixrem ]))
    .pipe(gulp.dest('dest/'));
});

These have to be accompanied with the relevant calls at the top of our Gulp task file:

var nesting = require('postcss-nesting');
var shortcolor = require('postcss-short-color');
var pixrem = require('pixrem');

In turn, these plugins are as follows:

We can of course add others, and continue converting our code—there are other instances where Nesting can be applied, such as in the rules that control styling for our navigation. The key here, though, is that success is measured in how much we have to change our processor's default setup—in this instance, we didn't have to change it at all! We of course added extra plugins that required a change to one line of code in the processor, but none of the other tasks required any changes at all.

It's at this stage that we have effectively completed the journey to create our processor—well, strictly speaking, our journey should always be considered without end; this will help ensure our tool remains up to date. This aside, though, there are some useful tips we can use when creating our processor, so let's take a moment to cover these in more detail.