Created
December 20, 2016 18:49
-
-
Save wokalek/1c09199364d16a0b6a63c9d90f22fe24 to your computer and use it in GitHub Desktop.
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
// Для корректной разметки рекомендуется использовать таб равный 2 пробелам. | |
const | |
// Подключаем таким образом пакеты для работы с ними. | |
gulp = require('gulp'), // Gulp | |
sass = require('gulp-sass'), // Sass | |
browserSync = require('browser-sync'), // Browser Sync | |
jshint = require('gulp-jshint'), // Для обнаружения ошибок в JS | |
concat = require('gulp-concat'), // Для конкатенации файлов | |
uglify = require('gulp-uglify'), // Для сжатия JS | |
cleancss = require('gulp-clean-css'), // Для минификации CSS | |
rename = require('gulp-rename'), // Для переименования файлов | |
del = require('del'), // Для удаления файлов и папок | |
imagemin = require('gulp-imagemin'), // Для работы с изображениями | |
pngquant = require('imagemin-pngquant'), // Для работы с png | |
cache = require('gulp-cache'), // Для кеширования | |
autoprefixer = require('gulp-autoprefixer'), // Для автоматического добавления вендорных префиксов | |
child = require('child_process'), | |
gutil = require('gulp-util'), | |
jade = require('gulp-jade'), | |
sassGlob = require('gulp-sass-glob'); | |
// | |
// Далее - таски (задачи для пакетов) | |
// | |
// "Смотрать" за файлами, и, в случае их изменения, запускать соответствующие | |
// задачи для компиляции и рефрешиться сайт. | |
gulp.task('watch', function() { | |
// Пути Процессы Рефреш | |
gulp.watch('assets/_sass/*.sass', ['sass']); | |
gulp.watch('assets/_js/*.js', ['js']) .on("change", browserSync.reload); | |
gulp.watch('_jade/*.jade', ['jade']); | |
gulp.watch(['*.html', | |
'_layouts/*.html', | |
'_posts/*', | |
'_includes/*'], ['jekyll-rebuild']); | |
//gulp.watch('_site/**/*.html') .on("change", browserSync.reload); | |
}); | |
// Браузер синк | |
gulp.task('browser-sync', ['sass', 'js', 'jade', 'jekyll-build'], function() { | |
browserSync({ | |
server: { | |
baseDir: '_site' | |
}, | |
notify: false | |
}); | |
}); | |
// Jekyll стафф | |
var messages = {jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'}; | |
gulp.task('jekyll-build', function (done) { | |
browserSync.notify(messages.jekyllBuild); | |
var pl = process.platform === "win32" ? "jekyll.bat" : "jekyll"; | |
return child.spawn(pl, ['build'], {stdio: 'inherit'}) | |
.on('close', done); | |
}); | |
gulp.task('jekyll-rebuild', ['jekyll-build'], function (done) { | |
browserSync.reload(); | |
done(); | |
}); | |
// Компиляция Sass | |
gulp.task('sass', function(){ | |
var sassOptions = | |
{ | |
errLogToConsole: true, | |
outputStyle: 'expanded', | |
includePaths: ['_sass'] | |
}; | |
return gulp.src('assets/_sass/main.sass') | |
.pipe(sassGlob()) | |
.pipe(sass(sassOptions).on('error', sass.logError)) | |
.pipe(autoprefixer(['last 15 versions', '> 1%'], { cascade: true })) | |
//Кидаем преобразованный файл для проверки | |
.pipe(rename("_style.css")) | |
.pipe(gulp.dest('assets/css')) | |
//Минификация CSS и в продакшен | |
.pipe(rename("style.min.css")) | |
.pipe(cleancss()) | |
.pipe(gulp.dest('_site/assets/css')) | |
.pipe(gulp.dest('assets/css')) | |
.pipe(browserSync.stream()) | |
}); | |
// Компиляция Jade | |
gulp.task('jade', function() { | |
return gulp.src('_jade/**/*.jade') | |
.pipe(jade()) | |
.pipe(gulp.dest('_includes')); | |
}); | |
// Конкатинируются JS'ки и сжимаются | |
gulp.task('js', function() { | |
return gulp.src([ | |
'assets/_js/**/*.js' | |
]) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')) | |
.pipe(concat('scripts.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('assets/js')); | |
}); | |
// Таск для сжатия изображений без потерь в качестве | |
gulp.task('img', function() { | |
return gulp.src('assets/_img/**/*') | |
.pipe(cache(imagemin({ | |
interlaced: true, | |
progressive: true, | |
svgoPlugins: [{removeViewBox: false}], | |
use: [pngquant()] | |
}))) | |
.pipe(gulp.dest('assets/img')); | |
}); | |
// Очистить кеш. Это для такска изображений. Выполняется по нужде | |
gulp.task('clean-cache', function (callback) { | |
return cache.clearAll(); | |
}) | |
// Очистить папку с сайтом. | |
gulp.task('clean-site', function() { | |
return del.sync('_site'); | |
}); | |
// Напиши в консоли "gulp" - и всё запустится | |
gulp.task('default', ['browser-sync', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment