Andrey Sitnik, Evil Martians
a {
<%= include clickable %>
color: <%= $link-color %>;
}
gulp.task('css', () => {
let postcss = require('gulp-postcss');
return gulp.src('src/*.css')
.pipe( postcss([ plugin1, plugin2 ]) )
.pipe( gulp.desc('build/') );
});
To overcome older preprocessors' limits:
postcss([
require('autoprefixer')({
browsers: 'last 2 version'
}),
require('postcss-cssnext'),
require('precss')
])
.icon {
top: center;
}
@use postcss-center;
.icon {
top: center;
}
@use
: lost, postcss-center, postcss-circleprecss
: Sass-like featurescssnext
: polyfills for “CSS 4”oldie
: IE 8 supportvar moment = require('moment');
logo/
logo.js
logo.css
logo.svg
header/
header.js
header.css
logo.css
header.css
.name {
color: black;
}
.name {
color: gray;
}
import styles from './logo.css';
class Logo extends React.Component {
render() {
return <div className={ styles.name }>We</div>;
}
}
CSS Modules:
BEM
<Header>
color: white
<Logo>
background: white
</Logo>
</Header>
* {
box-sizing: border-box;
}
div {
margin-top: 10px;
}
.logo {
color: black;
}
.logo--big {
width: 200px;
}
.logo {
all: initial;
color: black;
}
.logo--big {
width: 200px;
}
.logo {
all: initial;
}
.logo {
color: black;
background: white;
box-sizing: content-box;
line-height: normal;
text-shadow: none;
vertical-align: baseline;
white-space: normal;
postcss-autoreset
postcss-initial
Image sizes:
.icon {
width: width('logo.png');
height: height('logo.png');
background: inline('logo.png');
}
Make a reference to another property:
.icon {
width: 20px;
height: @width;
}
@custom-media --phones (width <= 700px);
@custom-media --hidpi (resolution >= 2dppx);
@media (--phones) { }
@media (--phones) and (--hidpi) { }
:fullscreen { }
:-webkit-full-screen { }
:-moz-full-screen { }
:-ms-fullscreen { }
:fullscreen { }
body {
font-family: Alice;
}
@font-face {
font-family: Alice;
font-style: normal;
font-weight: 400;
src: local("Alice"),
url("//fonts.gstatic.com/….woff")
format("woff");
}
body {
font-family: Alice;
}
.popup {
background:
rgba(153, 221, 153, 0.8);
}
.popup {
background: #99dd99; /* IE 8 */
background:
rgba(153, 221, 153, 0.8);
}
.icon {
background: url(logo.svg);
background-size: 20px 20px;
}
.icon {
background: url(logo.svg);
background-size: 20px 20px;
}
.no-svg.icon {
background: url(logo-20x20.png);
}
.icon {
background: svg('logo.svg', '[fill]: #c00');
}
More than 85 rules:
"rules": {
"indentation": 2,
"number-leading-zero": 2,
"color-no-invalid-hex": 2
}
main.css:13:3: Pointer events not supported by: IE (9,10)
.arrow {
@svg {
polygon {
fill: green;
points: 50,100 0,0 0,100;
}
}
}
Legacy project:
New project:
.pipe( sass() )
.pipe( postcss([
...plugins
]) )
.pipe( postcss([
precss,
...plugins
]) )
postcss-use
for plugins with custom syntax