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

Getting started with some hints and tips

The time has come when it is over to you as developers to start creating your own processor! It may seem a daunting task at first, depending on the size and nature of your project; I've listed a few tips to help you over the initial hurdle of planning and creating your processor:

  • Every processor is unique—do not be afraid to experiment. The processor of course must meet your requirements, but there are several ways to crack a nut, so if the first plugin you try doesn't work, then move on and try another.
  • Don't fall into the trap that many do, and consider PostCSS as either a pre-processor or a post-processor; it is neither and yet it is also both. The library itself does nothing; the magic lies in the plugins you add, which determine how it performs.
  • Start small—PostCSS was designed to be modular, so if all you need to begin with is a facility to add vendor prefixes, then fine. Over time, you can easily add extra plugins to your processor; it does not matter if this is adding to existing functionality, or replacing an old process that is no longer efficient or works.
  • Think iteratively—don't even try to convert something as large as the style sheet for WordPress in one go! You will soon lose patience and momentum, and potentially abandon a project before you get the benefits of using PostCSS.
  • The only time a processor should be retired is if there is a fundamental change in the architecture of your project, which makes it incompatible with PostCSS. The versatility of PostCSS is such that this isn't likely to happen—you should always review the functionality periodically to ensure you are getting the best out of your processor. Plugins change, are deprecated, or new ones are added—a check will ensure your solution still works as efficiently as possible.
  • Any processor should not be limited to PostCSS plugins only—even though this is what we've focused on, there are thousands of other plugins available for your task runner of choice, which will likely work with PostCSS. The key here is that if it helps automate a mundane task that saves you time as a developer, then consideration should be given to whether it can be included in your processor.
  • I personally take the view that if it can be automated reliably, then include a task for it—we live in an age where time is precious; there is no value in manually resizing images, for example, if it can be done automatically!
  • Although we've talked about some of the tasks we can complete using a task runner, we must not forget the folder structure too. There is nothing worse than compiling files for different environments, for example, if they land up in badly-organized folders! Gulp can automate a multitude of tasks, so the fewer changes we have to do, or the fewer files we have to copy, the better.

Hopefully, they are a few tips to get you started! The great thing about PostCSS is that no two processors will be the same; whilst some may count that as a shortcoming, it should be noted that there is a wealth of possibilities out there to be explored, and that you can make your processor as simple or as complex as your project requirements dictate.

Before we bow out from our journey through building a custom processor, there is something we should consider. Our processor was constructed entirely using PostCSS plugins; in reality, our processor is more likely to go through a transitional phase, where we convert from the likes of SASS or less to using PostCSS.

To help with this process, we can always make use of a library such as CSStyle—this little interesting gem can work with either SASS or PostCSS, and could be a useful addition to the transition process. Over the course of the next two chapters, we will learn how to create custom syntaxes and explore some of the ways we can process both PostCSS and SASS content through the same process. As a taster for what is coming, let's take a quick tour through CSSStyle and see how it works in action.