Last active
May 28, 2018 17:25
-
-
Save adeonir/4d2f652f5a00b2124b4f640fe268a0c8 to your computer and use it in GitHub Desktop.
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
const gulp = require('gulp'); | |
const yargs = require('yargs'); | |
const plumber = require('gulp-plumber'); | |
const sass = require('gulp-sass'); | |
const postcss = require('gulp-postcss'); | |
const autoprefixer = require('autoprefixer'); | |
const cssnano = require('cssnano'); | |
const svgmin = require('gulp-svgmin'); | |
const rename = require('gulp-rename'); | |
const babel = require('gulp-babel'); | |
const minify = require('gulp-babel-minify'); | |
const ftp = require('vinyl-ftp'); | |
const browserSync = require('browser-sync'); | |
const childProcess = require('child_process'); | |
const deploy = Boolean(yargs.argv.production); | |
gulp.task('jekyll', (done) => { | |
if (deploy) { | |
const production = process.env; | |
production.JEKYLL_ENV = 'production'; | |
return childProcess.spawn('jekyll', ['build'], { stdio: 'inherit', env: production }) | |
.on('close', done); | |
} | |
return childProcess.spawn('jekyll', ['build'], { stdio: 'inherit' }) | |
.on('close', done); | |
}); | |
gulp.task('rebuild', ['jekyll'], () => { | |
browserSync.reload(); | |
}); | |
gulp.task('browser-sync', ['jekyll'], () => { | |
browserSync({ | |
server: { | |
baseDir: '_site', | |
}, | |
}); | |
}); | |
gulp.task('styles', () => { | |
gulp.src('src/sass/main.scss') | |
.pipe(plumber()) | |
.pipe(sass()) | |
.pipe(postcss([autoprefixer(), cssnano()])) | |
.pipe(gulp.dest('_site/assets/css/')) | |
.pipe(browserSync.reload({ stream: true })) | |
.pipe(gulp.dest('assets/css/')); | |
}); | |
gulp.task('scripts', () => { | |
gulp.src('src/js/*.js') | |
.pipe(plumber()) | |
.pipe(babel()) | |
.pipe(minify()) | |
.pipe(gulp.dest('_site/assets/js/')) | |
.pipe(browserSync.reload({ stream: true })) | |
.pipe(gulp.dest('assets/js/')); | |
}); | |
gulp.task('images', () => { | |
gulp.src('src/img/**/*') | |
.pipe(gulp.dest('_site/assets/img/')) | |
.pipe(browserSync.reload({ stream: true })) | |
.pipe(gulp.dest('assets/img/')); | |
}); | |
gulp.task('vectors', () => { | |
gulp.src('src/svg/**/*') | |
.pipe(plumber()) | |
.pipe(svgmin()) | |
.pipe(rename({ | |
extname: '.html', | |
})) | |
.pipe(gulp.dest('_includes/')) | |
.pipe(browserSync.reload({ stream: true })); | |
}); | |
gulp.task('watch', () => { | |
gulp.watch('src/sass/**/*', ['styles', 'rebuild']); | |
gulp.watch('src/js/*.js', ['scripts', 'rebuild']); | |
gulp.watch(['**/*.html', '_includes/*.html', '_layouts/*.html'], ['rebuild']); | |
}); | |
gulp.task('deploy', () => { | |
const conn = ftp.create({ | |
host: '', | |
user: '', | |
pass: '', | |
parallel: 10, | |
}); | |
return gulp.src('_site/**', { base: '_site/', buffer: false }) | |
.pipe(conn.newer('/public_html')) | |
.pipe(conn.dest('/public_html')); | |
}); | |
gulp.task('dev', ['images', 'vectors', 'styles', 'scripts', 'browser-sync', 'watch']); | |
gulp.task('build', ['images', 'vectors', 'styles', 'scripts', 'jekyll']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment