Modifies your CSS before it gets to a browser
Modifies CSS in a different way from other preprocessors
Converts CSS (a string in a file) into a giant object
Allows JS to traverse that object & add/remove/edit
PostCSS alone does nothing to your CSS;
PostCSS plugins make all the changes.
// Bourbon Mixin for Sass
.element {
@include transform(rotate(90deg));
}
/* Autoprefixer */
.element {
transform: rotate(90deg);
}
// Neat Mixin for Sass
.element {
@include span-columns(3 of 12);
}
/* PostCSS "Grid" Plugin */
.element {
grid-span: 3, 12;
}
.element {
float: left;
margin-right: 2.3576516%;
width: 23.2317613%;
}
.element:last-child {
margin-right: 0;
}
/* Gulp/Sass packages */
var gulp = require('gulp');
var glob = require('glob');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('sass', function() {
gulp.src('src/scss/styles.scss')
.pipe( sourcemaps.init() )
.pipe( sass({outputStyle: 'expanded'}) )
.pipe( sourcemaps.write() )
.pipe( gulp.dest('src/css/') );
});
/* PostCSS packages */
var postcss = require('gulp-postcss');
var prefix = require('autoprefixer');
var cssnano = require('cssnano');
var sorting = require('postcss-sorting');
gulp.task('postcss', function() {
var postcss_tools = [
prefix({browsers: ['last 3 versions']}),
sorting()
];
if ( is_production )
postcss_tools.push(cssnano());
gulp.src('src/css/styles.css')
.pipe( postcss(postcss_tools) )
.pipe( gulp.dest('src/css/') );
});
Use Sass to turn non-CSS into CSS;
use PostCSS to turn CSS into better CSS.
All you’ll ever get from PostCSS is … CSS;
PostCSS can’t make unsupported CSS work.
postcss-sorting
postcss-flexbugs-fixes
css-colorguard
@font-face
with Font Magiciancssstats
list-selectors
stylelint
postcss-bem-linter