58
Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS

Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

  • Upload
    others

  • View
    19

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Build Powerful FrontEnd Workflows with PostCSS

Guide to writing/generating cutting edge CSS

Page 2: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Key TakeAways

PostCSS - Deep Diveplugins you can usecustom plugins

WorkflowEssential ConceptsPlugins to help with tasks

Drupal ThemeStarter Template

Page 3: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Introduction AdvancedEssential

Page 4: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Introductionwhat - why - how

What is it? Microservice ArchitectureSingle Responsibility PrincipleInstallationGulp Script

Page 5: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Philosopher’s Stone

Page 6: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Alchemy

Page 7: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

What is PostCSS?

Transformer!

A Workflow Tool - (post/pre)processor

Language Extender

CSS Wayback/Time Machine

Page 8: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Collection of API &Micro Services

architecture

Page 9: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Architecture

Page 10: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

What does PostCSS do?

Parses CSSCreates Node Tree

Provides APIs for processorsPipes between processors

Page 11: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Plugin Design Principle

Single Responsibility PrincipleDo one thing and do well

Node ModulesWritten in JS

Page 12: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

You have a plugin for that! PostCSS.parts

200+

Page 13: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Why roll yours in PostCSS?

Choice - freedom to choose

Usage - tailor to your workflow

Modular/ lightweight hence faster

Page 14: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Limitations of pre-processors

@extend across media queries

Automatically fix errors

Feature Requests and how it is handled

Page 15: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Installation and First Task

Page 16: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Required Tools

Node.js

NPM - Dependency Management System

Gulp/Grunt - The task runner

Page 17: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Workflow Anatomy

Page 18: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Installation

Install Node

Page 19: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Gulp Task

Page 20: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Essential PostCSS

Build custom workflow

Requirements of a Workflow?AutoprefixerLintingfutureCSSQuantity QueriesContainer QueriesCSS ModulesPacks

Page 21: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Workflow Goals

ENVIRONMENT

Mechanical Rules EnforcementDebugLintingEasy SetUp

CODE HELPERS

Future ProofingFallback SupportLanguage ExtensionsShortcutsUtilities

Page 22: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Toolchain

ENVIRONMENT

Mechanical Rules Enforcement - stylelintDebug - sourcemapsLinting - stylelintEasy SetUp - npmI/O - import/cssnano

CODE HELPERS

Fallback Support - oldieFuture Proofing - cssnextLanguage Extensions precssShortcuts - shortUtilities - lot

Page 23: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

ENVIRONMENT

Page 24: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Importer - postcss-importBefore

PostCSS - CSS

Page 25: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Linters - Stylelint

StyleLintMechanical Rules EnforcementOver 100 RulesChoose the ones you want

Page 26: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Linters - Stylelint

Page 27: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

PackerscssnanoDoes minify and some errors.

postcss-css-mqpackerConcats all styles of same media query.

postcss-cachebusterBusts assets cache using url params.

postcss-data-packerembedded base64 to separate file.

Page 28: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Source Maps

Page 29: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Style Guides

postcss-style-guide, psg-theme-default

Provides KSS Style Living GuidesUses Annotation to generate HTML

Page 30: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Style Guides

Page 31: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

CODE HELPERS

Future CSS

Page 32: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Future CSSpostcss-custom-mediapostcss-custom-propertiespostcss-extendpostcss-initialpostcss-media-minmaxcq-prolyfill

Page 33: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

PostCSS Extend

example from plugin page

Page 34: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Container Queries

cq-prolyfill

Page 35: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Quantity Queries

postcss-quantity-queries

:at-least(count):at-most(count):between(start,end):exactly(count)

Page 36: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

CSS Modules

postcss-initial

{all:initial}

Page 37: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

CODE HELPERS

Language Extenders

Page 38: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Pre/post compiler

PRE COMPILER

write code in scss/less/stylus, gets converted into css.

precss

POST COMPILER

write CSS Code, gets converted into CSS.

cssnext

Page 39: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Pre/post compiler

PRE COMPILER

mixins needs to be learned, their APIs

provides sass like mixins, functions etc.

POST COMPILER

plain CSS, which is parsed by Autoprefixers

uses W3C css Variables

Page 40: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

CODE HELPERS

Utility Plugins

Page 41: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Utility Plugins

autoprefixerpxtorempostcss-sortingperfectionistpostcss-font-packpostcss-fontpath

Page 42: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Utility Plugins - AutoPrefixer

refers caniuse.com to generatedoes not generate for border-radius etc…http://autoprefixer.github.io/

Page 43: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Utility Plugins - pxtorem

Page 44: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Packs

Curated plugins

Takes care of interplay

Does heavy lifting

Page 45: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Packscssnano - packer, optimizer for productionrucksack - new features and shortcutsshort - shorthand propertiesprecss - language extendercssnext - language extender (W3C)

https://github.com/timaschew/postcss-compare-packs

Page 46: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

AdvancedBeyond the Basics

Write your own pluginCSS ArchitectureBEM / SMACSS OrganizationPutting it all together

Page 47: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

PostCSS Boilerplatepostcss-plugin-boilerplate

Wizard to help creationClean git historyWrite index.js and test.jsDocument

Page 48: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Examine a plugin

Page 49: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Anatomy of a Plugin

this is postcss-currency plugin

Page 50: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

CSS Architecture

Page 51: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Architecture Challenges

AbstractionMaintainabilityChange Management

DebuggingDocumentation

Page 52: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

SMACSSCategorizing / Organizing CSS Rules

Base - base level CSSLayout - layout based classes (l-)Module - reusable modules State - state of an item is-activeTheme - related to colors

Reduced dependency on structureThinking in Components

Page 53: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Block Element ModifierRules to Name selectors

Page 54: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

Theming Process

Component Inventory - pptComponent Library - code

Layout Pages Composition of Components

Oddball ComponentsContext based alignment/changes

Page 55: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

End To End Workflow

CLASSY THEMEConfigure with postCSSFolder StructuresPlugins

Code OrganizationDebugging - source mapsLinting

Page 56: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

DEMO & CODE WALKTHROUGH

Page 57: Build Powerful FrontEnd Workflows with PostCSS · Build Powerful FrontEnd Workflows with PostCSS Guide to writing/generating cutting edge CSS. Key TakeAways PostCSS - Deep Dive plugins

SummaryWhat is PostCSSArchitectureWhy PostCSSHow To start coding in PostCSS

Workflow GoalsPostCSS Tools that supportUseful Plugins

Write PluginSMACSS/BEMAll together