POSTCSS Tools
If you do not want to manually set up your project from scratch, you can download the source attachment provided in this tutorial, extract the Gulp or grunt items into an empty folder.
Then run at the command terminal: npm install
.
Installing plugins
Whether you are using Gulp or grunt, run the following command in the directory of your project:
--save-dev
Now that the plugin is installed, we will continue to load these plugins into your project.
Loading plugins via Gulp
If you are using Gulp, gulpfile.js
load These variables in your:
var autoprefixer = require ( ' autoprefixer '); var color_rgba_fallback = require (var opacity = require ( ' postcss-opacity '); var pseudoelements = require ( ' postcss-pseudoelements ') ; var vmin = require ( ' postcss-vmin '); var pixrem = require ( ' Pixrem '); require ( ' Postcss-will-change ');
and add the names of these variables to your processors
array:
var processors = [ will_change, autoprefixer, color_rgba_fallback, opacity, pseudoelements, vmin, pixrem];
Do a quick test, run at the command terminal, check that the files are not gulp css
style.css
placed dest
in the folder.
"Reference article 1"
"Reference article 2"
Package.json Code:
1 {2 "name": "Gulppostcssstarter",3 "version": "1.0.0",4 " description": "Basic starter Project for POSTCSS use via Gulp",5 " Author": "Kezz Bracey",6 " License": "MIT",7 "Devdependencies": {8 " autoprefixer": "^5.2.0",9 " Gulp": "^3.9.0",Ten " gulp-postcss": "^5.1.10", One " Pixrem": "^1.3.1", A " postcss-color-rgba-fallback": "^1.3.1", - " postcss-opacity": "^2.0.1", - " postcss-pseudoelements": "^2.2.0", the " postcss-vmin": "^1.0.0", - " postcss-will-change": "^0.2.0 " - } -}
configuration of the Gulpfle.js :
1 var gulp = require (' gulp ');2 var postcss = require (' gulp-postcss ');3 4 var autoprefixer = require (' autoprefixer ');5 var color_rgba_fallback = require (' Postcss-color-rgba-fallback ');6 var opacity = require (' postcss-opacity ');7 var pseudoelements = require (' postcss-pseudoelements ');8 var vmin = require (' postcss-vmin ');9 var pixrem = require (' Pixrem ');Ten var will_change = require (' Postcss-will-change '); One A gulp.task (' CSS ', function () { - var processors = [ - Will_change, the Autoprefixer ({ - browsers: [' > 1% ', ' last 2 versions ', ' IE >=8 ', ' Firefox > ', ' Chrome > + '] - }), - Color_rgba_fallback, + opacity, - pseudoelements, + Vmin, A Pixrem at ]; - return Gulp.src ('./src/*.css ') - . Pipe (POSTCSS (processors)) - . Pipe (Gulp.dest ('./dest ')); -});
POSTCSS: cross-browser compatibility