Skip to content

Instantly share code, notes, and snippets.

@dleatherman
Created July 14, 2017 18:04
Show Gist options
  • Save dleatherman/5f9b674cb837f9266448f6178f96a8c3 to your computer and use it in GitHub Desktop.
Save dleatherman/5f9b674cb837f9266448f6178f96a8c3 to your computer and use it in GitHub Desktop.
Starter Wordpress Theme Gulpfile
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var connect = require('gulp-connect-php');
var browserSync = require('browser-sync').create();
var sassOptions = {
errLogToConsole: true,
outputStyle: 'compact'
};
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
gulp.task('sass', function() {
return gulp.src('./wp-content/themes/{{themename}}/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(autoprefixer(autoprefixerOptions))
.pipe(concat('style.css'))
.pipe(gulp.dest('./wp-content/themes/{{themename}}/'));
});
gulp.task('scripts', function() {
return gulp.src('./wp-content/themes/{{themename}}/js/src/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./wp-content/themes/{{themename}}/js/dist/'));
});
//Watch task
gulp.task('default',function() {
connect.server({}, function (){
browserSync.init({
proxy: '127.0.0.1:8000'
});
});
gulp.watch('./wp-content/themes/{{themename}}/scss/**/*.scss',['sass']);
gulp.watch('./wp-content/themes/{{themename}}/js/src/**/*.js',['scripts']);
gulp.watch('./wp-content/themes/{{themename}}/**/*.php').on('change', browserSync.reload);
gulp.watch('./wp-content/themes/{{themename}}/js/dist/app.js').on('change', browserSync.reload);
gulp.watch('./wp-content/themes/{{themename}}/style.css').on('change', browserSync.reload);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment