Created
September 26, 2017 20:57
-
-
Save panayotoff/e37f254e315a49ef28281eb608788747 to your computer and use it in GitHub Desktop.
Example Gulp config for working with WP themes;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Package.json | |
{ | |
"name": "gulpdev", | |
"version": "0.0.1", | |
"description": "", | |
"main": "index.php", | |
"scripts": { | |
"dev": "gulp" | |
}, | |
"author": "", | |
"devDependencies": { | |
"autoprefixer": "^7.1.4", | |
"browser-sync": "^2.17.6", | |
"gulp": "^3.9.1", | |
"gulp-image": "^3.0.0", | |
"gulp-jshint": "^2.0.2", | |
"gulp-newer": "^1.3.0", | |
"gulp-postcss": "^7.0.0", | |
"gulp-print": "^2.0.1", | |
"gulp-ruby-sass": "^2.1.1", | |
"gulp-sass": "^3.1.0", | |
"gulp-scss": "^1.4.0", | |
"gulp-sourcemaps": "^2.2.0", | |
"jshint": "^2.9.4" | |
} | |
} | |
*/ | |
var themename = 'themename'; | |
var gulp = require('gulp'), | |
autoprefixer = require('autoprefixer'), | |
browserSync = require('browser-sync').create(), | |
image = require('gulp-image'), | |
jshint = require('gulp-jshint'), | |
postcss = require('gulp-postcss'), | |
sass = require('gulp-sass'), | |
sourcemaps = require('gulp-sourcemaps'), | |
// Only work with new or updated files | |
newer = require('gulp-newer'), | |
// Name of working theme folder | |
root = '../' + themename + '/', | |
scss = root + 'sass/', | |
js = root + 'js/', | |
img = root + 'images/', | |
languages = root + 'languages/'; | |
// CSS via Sass and Autoprefixer | |
gulp.task('css', function () { | |
return gulp.src(scss + '{style.scss}') | |
.pipe(sourcemaps.init()) | |
.pipe(sass({ | |
outputStyle: 'expanded', | |
indentType: 'tab', | |
indentWidth: '1' | |
}).on('error', sass.logError)) | |
.pipe(postcss([ | |
autoprefixer('last 2 versions', '> 1%') | |
])) | |
.pipe(sourcemaps.write(scss + 'maps')) | |
.pipe(gulp.dest(root)); | |
}); | |
// Optimize images through gulp-image | |
gulp.task('images', function () { | |
return gulp.src(img + 'RAW/**/*.{jpg,JPG,png}') | |
.pipe(newer(img)) | |
.pipe(image()) | |
.pipe(gulp.dest(img)); | |
}); | |
// JavaScript | |
gulp.task('javascript', function () { | |
return gulp.src([js + '*.js']) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')) | |
.pipe(gulp.dest(js)); | |
}); | |
// Watch everything | |
gulp.task('watch', function () { | |
browserSync.init({ | |
open: 'external', | |
proxy: 'http://localhost:8888/themename', | |
}); | |
gulp.watch([root + '**/*.css', root + '**/*.scss'], ['css']); | |
gulp.watch(js + '**/*.js', ['javascript']); | |
gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', ['images']); | |
gulp.watch(root + '**/*').on('change', browserSync.reload); | |
}); | |
// Default task (runs at initiation: gulp --verbose) | |
gulp.task('default', ['watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment