Moar changes to the gulp process

This commit is contained in:
jan 2018-08-16 21:44:26 +02:00
parent 2a51ab0c6c
commit 4331186cca

View File

@ -9,10 +9,14 @@ var del = require('del'),
plumber = require('gulp-plumber'), plumber = require('gulp-plumber'),
rename = require('gulp-rename'); rename = require('gulp-rename');
var Config = {
inputDir: '_source',
outputDir: '_dist'
}
var sassConfig = { var SassConfig = {
inputDirectory: '_source/sass/**/*.scss', inputDir: '_source/sass/**/*.scss',
outputDirectory: '_dist/css', outputDir: '_dist/css',
options: { options: {
outputStyle: 'expanded' outputStyle: 'expanded'
}, },
@ -23,46 +27,68 @@ var sassConfig = {
// clean the folders // clean the folders
gulp.task('clean', function(cb) { gulp.task('clean', function(cb) {
return del([sassConfig.outputDirectory + '/*'], cb) return del([Config.outputDir], cb)
});
// watcher
gulp.task('watch', function() {
gulp.watch(sassConfig.inputDirectory, ['sass']);
livereload.listen()
}); });
// render SASS // render SASS
gulp.task('sass', function() {var onError = function(err) { gulp.task('sass', function() {var onError = function(err) {
notify.onError({ notify.onError({
title: "Gulp", title: 'gulp',
subtitle: "Failure!", subtitle: 'Error!',
message: "Error: <%= error.message %>", message: '❌ <%= error.message %>',
sound: "Submarine" sound: 'Submarine'
})(err); })(err);
this.emit('end'); this.emit('end');
}; };
return gulp return gulp
.src(sassConfig.inputDirectory) .src(SassConfig.inputDir)
.pipe(plumber({errorHandler: onError})) .pipe(plumber({errorHandler: onError}))
.pipe(sass(sassConfig.options).on('error', sass.logError)) .pipe(sass(SassConfig.options).on('error', sass.logError))
.pipe(autoprefixer(sassConfig.autoprefixer)) .pipe(autoprefixer(SassConfig.autoprefixer))
.pipe(gulp.dest(sassConfig.outputDirectory)) .pipe(gulp.dest(SassConfig.outputDir))
.pipe(cssnano()) .pipe(cssnano())
.pipe(rename({suffix: '.min'})) .pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(sassConfig.outputDirectory)) .pipe(gulp.dest(SassConfig.outputDir))
.pipe(notify({ message: 'SASS rendered' })) .pipe(notify({
title: 'gulp',
subtitle: 'Success!',
message: 'SASS compiled ✅',
timeout: '2'
}))
.pipe(livereload()); .pipe(livereload());
}); });
gulp.task('sass-only', function() { gulp.task('sass-only', function() {
return gulp return gulp
.src(sassConfig.inputDirectory) .src(SassConfig.inputDir)
.pipe(sass(sassConfig.options).on('error', sass.logError)) .pipe(sass(SassConfig.options).on('error', sass.logError))
.pipe(gulp.dest(sassConfig.outputDirectory)); .pipe(gulp.dest(SassConfig.outputDir));
});
// Copy those other files
gulp.task('copy', function() {
gulp.src([Config.inputDir + '/*.*'])
.pipe(gulp.dest(Config.outputDir))
.pipe(livereload())
gulp.src([Config.inputDir + '/inc/**/*'])
.pipe(gulp.dest(Config.outputDir + '/inc'))
.pipe(livereload())
gulp.src([Config.inputDir + '/js/**/*.*'])
.pipe(gulp.dest(Config.outputDir + '/js'))
.pipe(livereload())
})
gulp.task('watch', function() {
livereload.listen()
// Watch .scss files
gulp.watch(SassConfig.inputDir, ['sass']);
// Watch php files
gulp.watch(Config.inputDir + '/*.php', ['copy'])
gulp.watch(Config.inputDir + '/inc/*.php', ['copy']);
}); });
// Default: First 'clean', then the rest // Default: First 'clean', then the rest
gulp.task('default', ['clean'], function() { gulp.task('default', ['clean'], function() {
gulp.start('sass'); gulp.start('sass', 'copy');
}); });