Four reasons why node.js is useful for EPUB CSS
Linters are that locked cabinet for foot-shooting shotguns. They read your code and shout at you when you’re breaking one of their rules. CSSlint is the one to use for CSS.
Once you have Node.js, install it like so:
$ npm install -g csslint, possibly with a
sudo there first on some platforms. That gives you the CSSlint command line tool.
It is useful on three levels:
- It helps you avoid practices you know intellectually are a bad idea but never seem to avoid in practice.
- It checks your code for basic syntax errors, catching all kinds of dumb bugs and typos that would otherwise come back to haunt you.
- It forces you to consider, analyze, and decide beforehand what good practice means for your particular project.
That third bit comes from the fact that before you use it, you really should go through CSSlint’s rule set and decide which ones apply to your work and which ones don’t. That process will teach you more about CSS and how you use it than most “how to” blog posts will.
Install it like so:
$ npm install -g less.
The important bit in a CSS preprocessor is how it lets you split your CSS into smaller, more manageable files and variables. Everything else is, in my not so humble opinion, a bonus that you can learn at a later date.
Gulp and Grunt
Their concept is pretty simple: They watch a bunch of files and when those files change, they run a bunch of code on them. The magic happens in the plugins you can use to write powerful scripts that not only build your project’s assets, but also modify and process them.
The most interesting plugins (from a CSS perspective) are…
Rework and PostCSS
Death to regular expressions!
Seriously, using regular expressions to modify CSS is a recipe for disaster because regexps don’t understand the code they modify. This usually isn’t an issue with CSS you wrote yourself. In that case, you both know the stylesheet’s structure. More importantly, you probably didn’t fill your own stylesheet with crap you need to fix. (InDesign, however… If you can imagine me shuddering visibly, please do so at this point.)
Only the beginning