Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/damir-sijakovic/gulp_postcss

Gulp, PostCSS and BrowserSync Example
https://github.com/damir-sijakovic/gulp_postcss

browsersync gulp postcss

Last synced: 7 days ago
JSON representation

Gulp, PostCSS and BrowserSync Example

Awesome Lists containing this project

README

        

# Gulp, PostCSS and BrowserSync Example

Tutorial describing how Gulp works with PostCss and BrowserSync.
Basically, Gulp is used to monitor file changes. On change, PostCSS(and addons)
are processing all files from ./pcss directory. After that new files are
compiled into ./css directory.

### Install Gulp as terminal command

sudo npm install gulp-cli -g

### Project install

npm install --save-dev gulp gulp-postcss browser-sync

### List of PostCSS plugins

https://github.com/postcss/postcss/blob/main/docs/plugins.md

### Install plugin

npm install --save-dev autoprefixer

### Run inside project dir

mkdir ./pcss
touch ./pcss/style.css
touch ./gulpfile.js

### Add to './pcss/style.css'

::placeholder {
color: gray;
}

.image {
background-image: url([email protected]);
}
@media (min-resolution: 2dppx) {
.image {
background-image: url([email protected]);
}
}

### Add to './gulpfile.js'

const { src, dest, watch, series } = require('gulp');
const autoprefixer = require('autoprefixer');
const postcss = require('gulp-postcss');
const browsersync = require('browser-sync').create();

function cssTask(){
return src('./pcss/*.css', { sourcemaps: true })
.pipe(postcss([autoprefixer()]))
.pipe(dest('css', { sourcemaps: '.' }));
}

function browsersyncServe(cb){
browsersync.init({
server: {
baseDir: '.'
}
});
cb();
}

function browsersyncReload(cb){
browsersync.reload();
cb();
}

function watchTask(){
watch('*.html', browsersyncReload);
watch(['./pcss/**/*.css', './js/**/*.js'], series(cssTask, browsersyncReload));
}

exports.default = series(
cssTask,
browsersyncServe,
watchTask
);

### That creates ./css directory with newly compiled file

::-moz-placeholder {
color: gray;
}

:-ms-input-placeholder {
color: gray;
}

::placeholder {
color: gray;
}

.image {
background-image: url([email protected]);
}
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
.image {
background-image: url([email protected]);
}
}

### Run BrowserSync as service

gulp


This will automatically watch files for changes process/compile and move them to './css'.

### Have Fun!