2018-09-29 16:47:22 +02:00
|
|
|
// Initiate npm-modules
|
|
|
|
var gulp = require('gulp'),
|
2015-07-27 09:49:42 +02:00
|
|
|
autoprefixer = require('gulp-autoprefixer'),
|
2018-08-22 20:22:47 +02:00
|
|
|
concat = require('gulp-concat'),
|
2016-01-30 13:11:47 +01:00
|
|
|
cssnano = require('gulp-cssnano'),
|
2015-07-27 09:49:42 +02:00
|
|
|
livereload = require('gulp-livereload'),
|
2018-08-16 12:26:18 +02:00
|
|
|
notify = require('gulp-notify'),
|
|
|
|
plumber = require('gulp-plumber'),
|
2018-08-22 20:22:47 +02:00
|
|
|
rename = require('gulp-rename'),
|
|
|
|
sass = require('gulp-sass'),
|
2018-09-29 16:47:22 +02:00
|
|
|
merge2 = require('merge2'),
|
|
|
|
rimraf = require('rimraf');
|
2014-06-29 12:46:19 +02:00
|
|
|
|
2018-08-16 21:44:26 +02:00
|
|
|
var Config = {
|
2018-09-29 16:47:22 +02:00
|
|
|
inputDir: '_source/',
|
|
|
|
outputDir: '_dist/'
|
2018-08-16 21:44:26 +02:00
|
|
|
}
|
2015-07-27 09:49:42 +02:00
|
|
|
|
2018-08-16 21:44:26 +02:00
|
|
|
var SassConfig = {
|
2018-09-29 16:47:22 +02:00
|
|
|
inputDir: '_source/sass/',
|
|
|
|
outputDir: '_dist/css/',
|
|
|
|
options: {
|
|
|
|
outputStyle: 'expanded'
|
|
|
|
},
|
2018-08-16 12:26:18 +02:00
|
|
|
autoprefixer: ['last 2 version', 'IE 11', 'Firefox ESR', 'ios 10', 'android 4.4']
|
|
|
|
}
|
2014-07-29 02:50:38 +02:00
|
|
|
|
2018-09-29 16:47:22 +02:00
|
|
|
//:: Tasks
|
2014-07-29 02:50:38 +02:00
|
|
|
|
2018-09-29 16:47:22 +02:00
|
|
|
// delete the output folder
|
2018-08-16 12:26:18 +02:00
|
|
|
gulp.task('clean', function(cb) {
|
2018-09-29 16:47:22 +02:00
|
|
|
return rimraf(Config.outputDir, cb)
|
2014-07-29 02:50:38 +02:00
|
|
|
});
|
|
|
|
|
2018-08-16 12:26:18 +02:00
|
|
|
// render SASS
|
2018-09-29 16:47:22 +02:00
|
|
|
gulp.task('sass', function() {
|
|
|
|
var onError = function(err) {
|
|
|
|
notify.onError({
|
|
|
|
title: 'gulp',
|
|
|
|
subtitle: 'Error!',
|
|
|
|
message: '❌ <%= error.message %>',
|
|
|
|
sound: 'Submarine'
|
|
|
|
})(err);
|
2018-08-16 12:26:18 +02:00
|
|
|
this.emit('end');
|
2018-09-29 16:47:22 +02:00
|
|
|
};
|
2018-08-22 20:22:47 +02:00
|
|
|
|
2018-09-29 16:47:22 +02:00
|
|
|
return merge2(
|
|
|
|
gulp.src([
|
|
|
|
'node_modules/sanitize.css/sanitize.css'
|
|
|
|
]))
|
|
|
|
.pipe(concat('addons.css'))
|
|
|
|
.pipe(gulp.dest(SassConfig.outputDir))
|
|
|
|
.pipe(cssnano())
|
|
|
|
.pipe(rename({suffix: '.min'}))
|
|
|
|
.pipe(gulp.dest(SassConfig.outputDir)),
|
|
|
|
|
|
|
|
gulp.src(SassConfig.inputDir + '*.scss')
|
2018-08-22 20:22:47 +02:00
|
|
|
.pipe(concat('styles.css'))
|
2018-08-16 12:26:18 +02:00
|
|
|
.pipe(plumber({errorHandler: onError}))
|
2018-08-16 21:44:26 +02:00
|
|
|
.pipe(sass(SassConfig.options).on('error', sass.logError))
|
|
|
|
.pipe(autoprefixer(SassConfig.autoprefixer))
|
|
|
|
.pipe(gulp.dest(SassConfig.outputDir))
|
2018-08-16 12:26:18 +02:00
|
|
|
.pipe(cssnano())
|
|
|
|
.pipe(rename({suffix: '.min'}))
|
2018-08-16 21:44:26 +02:00
|
|
|
.pipe(gulp.dest(SassConfig.outputDir))
|
2018-08-22 20:22:47 +02:00
|
|
|
.pipe(livereload())
|
2018-08-16 21:44:26 +02:00
|
|
|
.pipe(notify({
|
|
|
|
title: 'gulp',
|
|
|
|
subtitle: 'Success!',
|
2018-09-29 16:47:22 +02:00
|
|
|
message: '✅ SASS compiled',
|
2018-08-16 21:44:26 +02:00
|
|
|
timeout: '2'
|
2018-08-22 20:22:47 +02:00
|
|
|
}));
|
2015-07-27 09:49:42 +02:00
|
|
|
});
|
|
|
|
|
2018-08-16 12:26:18 +02:00
|
|
|
gulp.task('sass-only', function() {
|
2018-09-29 16:47:22 +02:00
|
|
|
return gulp
|
|
|
|
.src(SassConfig.inputDir + '*.scss')
|
|
|
|
.pipe(sass(SassConfig.options).on('error', sass.logError))
|
|
|
|
.pipe(gulp.dest(SassConfig.outputDir));
|
2018-08-16 21:44:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Copy those other files
|
|
|
|
gulp.task('copy', function() {
|
2018-09-29 16:47:22 +02:00
|
|
|
gulp.src([Config.inputDir + '*.*'])
|
2018-08-16 21:44:26 +02:00
|
|
|
.pipe(gulp.dest(Config.outputDir))
|
|
|
|
.pipe(livereload())
|
2018-09-29 16:47:22 +02:00
|
|
|
gulp.src([Config.inputDir + 'inc/**/*'])
|
2018-08-16 21:44:26 +02:00
|
|
|
.pipe(gulp.dest(Config.outputDir + '/inc'))
|
|
|
|
.pipe(livereload())
|
|
|
|
})
|
|
|
|
|
|
|
|
gulp.task('watch', function() {
|
|
|
|
livereload.listen()
|
|
|
|
|
|
|
|
// Watch .scss files
|
2018-09-29 16:47:22 +02:00
|
|
|
gulp.watch(SassConfig.inputDir + '*.scss', ['sass']);
|
2018-08-16 21:44:26 +02:00
|
|
|
// Watch php files
|
2018-09-29 16:47:22 +02:00
|
|
|
gulp.watch(Config.inputDir + '*.php', ['copy'])
|
|
|
|
gulp.watch(Config.inputDir + 'inc/*.php', ['copy']);
|
2018-08-16 12:26:18 +02:00
|
|
|
});
|
2015-07-27 09:49:42 +02:00
|
|
|
|
2018-08-16 12:26:18 +02:00
|
|
|
// Default: First 'clean', then the rest
|
2014-07-29 02:50:38 +02:00
|
|
|
gulp.task('default', ['clean'], function() {
|
2018-08-16 21:44:26 +02:00
|
|
|
gulp.start('sass', 'copy');
|
2018-09-29 16:47:22 +02:00
|
|
|
});
|