Last active
October 31, 2017 02:06
-
-
Save jonasmello/7551c343aa62faa8aa114b211ec621e3 to your computer and use it in GitHub Desktop.
Sample of gulpfile.js
This file contains hidden or 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
var gulp = require('gulp'), | |
sass = require('gulp-sass'), | |
concat = require('gulp-concat'), | |
sourcemaps = require('gulp-sourcemaps'), | |
imagemin = require('gulp-imagemin'), | |
livereload = require('gulp-livereload'), | |
autoprefixer = require('gulp-autoprefixer'), | |
notify = require("gulp-notify"), | |
del = require('del'); | |
gulp.task('clean-styles', function() { | |
return del(['wp/wp-content/themes/theme-name/css/']); | |
}); | |
gulp.task('styles', function() { | |
return gulp.src('src/scss/main.scss') | |
.pipe(sourcemaps.init()) | |
.pipe(sass({ | |
style: 'expanded' | |
}).on('error', sass.logError)) | |
.pipe(autoprefixer({ | |
browsers: ['last 2 versions'] | |
})) | |
.pipe(sourcemaps.write()) | |
.pipe(gulp.dest('wp/wp-content/themes/theme-name/css/')) | |
.pipe(notify({ | |
message: 'Styles task complete' | |
})); | |
}); | |
gulp.task('clean-scripts', function() { | |
return del(['wp/wp-content/themes/theme-name/js/']); | |
}); | |
gulp.task('scripts', function() { | |
console.log('called scripts-compile'); | |
return gulp.src('src/js/**/*.js') | |
.pipe(concat('main.js')) | |
.pipe(gulp.dest('wp/wp-content/themes/theme-name/js/')); | |
}); | |
gulp.task('clean-images', function() { | |
return del(['wp/wp-content/themes/theme-name/img/']); | |
}); | |
gulp.task('images', function() { | |
console.log('called images'); | |
return gulp.src('src/img/**/*') | |
.pipe( | |
imagemin( | |
[ | |
imagemin.gifsicle({ | |
interlaced: true | |
}), | |
imagemin.jpegtran({ | |
progressive: true | |
}), | |
imagemin.optipng({ | |
optimizationLevel: 5 | |
}), | |
imagemin.svgo({ | |
plugins: [{ | |
removeViewBox: true | |
}, { | |
cleanupIDs: false | |
}] | |
}) | |
], { | |
verbose: true | |
} | |
) | |
) | |
.pipe(gulp.dest('wp/wp-content/themes/theme-name/img/')) | |
.pipe(notify({ | |
message: "Images Done!", | |
onLast: true | |
})); | |
}); | |
gulp.task('copy-config', function() { | |
return gulp.src([ | |
'src/wp-config.php', | |
'src/.htaccess' | |
]).pipe(gulp.dest('wp/')); | |
}); | |
gulp.task('copy-theme', function() { | |
console.log('called copy-theme'); | |
return gulp.src('src/theme/theme-name/**') | |
.pipe(gulp.dest('wp/wp-content/themes/theme-name/')) | |
.pipe(notify({ | |
message: "Theme copied!", | |
onLast: true | |
})); | |
}); | |
gulp.task('clean-all', ['clean-styles', 'clean-scripts', 'clean-images']); | |
gulp.task('build-all', ['styles', 'scripts', 'images']); | |
gulp.task('copy-all', ['copy-config', 'copy-theme']); | |
gulp.task('init', ['clean-all', 'build-all', 'copy-all']); | |
gulp.task('default', ['build-all', 'copy-theme'], function() { | |
gulp.watch('src/scss/**/*.scss', ['styles']); | |
gulp.watch('src/js/**/*.js', ['scripts']); | |
gulp.watch('src/img/**/*', ['images']); | |
gulp.watch('src/theme/theme-name/**/*.php', ['copy-theme']); | |
livereload.listen(); | |
gulp.watch(['wp/wp-content/themes/theme-name/**']).on('change', livereload.changed); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment