npm install -g uncssUsing UnCSS from the Command Line
UnCSSrequiresthefilepathorURLofanHTMLpagethatcontainsalinkedCSS
file;forexample:uncss http://sitepoint.com/UnCSSwillparsetheHTMLanditslinkedstylesheets,andprinttheoptimized
CSStostandardoutput.Toredirecttoafile,usetheredirectoperator(>):uncss http://sitepoint.com/ > optimized.cssYoucanalsopassmultiplefilepathsorURLstothecommandline.CSSwillanalyze
eachfileanddumpoptimizedCSSthatcontainsrulesaffectingoneormorepages:uncss index.html article-1.html article-2.html > optimized.cssFor a full list of commands―and an example of how to use UnCSS with a Node.js
script―consult the UnCSSdocs.^8Consider a Task Runner
Thisprobablysoundslikealotofextratimeandstepstoaddtoyourworkflow,but
youshouldconsiderataskrunnersuchGrunt^9 orbuildsystemsuchasGulp.^10 It’s
whereautomationcanhelpquiteabit.Gruntisthemoreestablishedofthetwotools,sotherearemorepluginsandalarger
community.IhappentobepartialtoGulp’ssyntax.Usewhichevertoolworksbest
foryouandyourcolleagues.What’sgreataboutGruntandGulpisthatyoucanassembleatoolchainthatwill
automaticallyrunconcatenation,minification,andoptimizationtasksforCSS,
JavaScript,andimagefiles.BecausetheconfigurationandbuildscriptfilesareJSON(^8) https://github.com/giakki/uncss
(^9) http://gruntjs.com
(^10) http://gulp.js
126 CSS Master