2017-11-09 02:34:49 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const gutil = require('gulp-util');
|
2017-11-11 08:26:29 +00:00
|
|
|
const child = require('child_process');
|
2017-11-09 02:34:49 +00:00
|
|
|
const browserSync = require('browser-sync').create();
|
2017-11-21 01:37:43 +00:00
|
|
|
|
2017-11-09 02:34:49 +00:00
|
|
|
const siteRoot = '_site';
|
2017-11-21 01:24:25 +00:00
|
|
|
const mainCSS = 'src/style.css'; /* Main stylesheet (pre-build) */
|
|
|
|
const tailwindConfig = 'tailwind.js'; /* Tailwind config */
|
2017-11-09 02:34:49 +00:00
|
|
|
|
2017-11-21 01:37:43 +00:00
|
|
|
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll'; /* Fix Windows compatibility issue */
|
2017-11-15 12:53:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-21 01:37:43 +00:00
|
|
|
* Build Jekyll Site
|
2017-11-15 12:53:20 +00:00
|
|
|
*/
|
2017-11-21 01:24:25 +00:00
|
|
|
gulp.task('jekyll-build', function () {
|
2017-11-15 12:53:20 +00:00
|
|
|
browserSync.notify('Running: $ jekyll build');
|
2017-11-21 01:37:43 +00:00
|
|
|
return child.spawn(jekyll, ['build'], {stdio: 'inherit'});
|
2017-11-09 02:34:49 +00:00
|
|
|
});
|
|
|
|
|
2017-11-15 12:53:20 +00:00
|
|
|
/**
|
|
|
|
* Compile styles
|
|
|
|
*/
|
2017-11-09 02:34:49 +00:00
|
|
|
gulp.task('css', function () {
|
|
|
|
const atimport = require('postcss-import');
|
|
|
|
const postcss = require('gulp-postcss');
|
|
|
|
const tailwindcss = require('tailwindcss');
|
|
|
|
const autoprefixer = require('gulp-autoprefixer');
|
|
|
|
const cleancss = require('gulp-clean-css');
|
|
|
|
|
2017-11-21 01:24:25 +00:00
|
|
|
return gulp.src(mainCSS)
|
2017-11-09 02:34:49 +00:00
|
|
|
.pipe(postcss([
|
|
|
|
atimport(),
|
2017-11-15 04:03:47 +00:00
|
|
|
tailwindcss(tailwindConfig)
|
2017-11-09 02:34:49 +00:00
|
|
|
]))
|
|
|
|
.pipe(autoprefixer({
|
|
|
|
browsers: ['last 2 versions'],
|
|
|
|
cascade: false
|
|
|
|
}))
|
|
|
|
.pipe(cleancss())
|
2017-11-21 01:24:25 +00:00
|
|
|
.pipe(gulp.dest('assets/css/'))
|
2017-11-15 12:53:20 +00:00
|
|
|
.pipe(gulp.dest('_site/assets/css/'))
|
2017-11-09 02:34:49 +00:00
|
|
|
});
|
|
|
|
|
2017-11-15 12:53:20 +00:00
|
|
|
/**
|
2017-11-21 01:24:25 +00:00
|
|
|
* Serve site with BrowserSync
|
2017-11-15 12:53:20 +00:00
|
|
|
*/
|
2017-11-21 01:24:25 +00:00
|
|
|
gulp.task('serve', ['jekyll-build'], () => {
|
2017-11-09 02:34:49 +00:00
|
|
|
browserSync.init({
|
|
|
|
files: [siteRoot + '/**'],
|
|
|
|
port: 4000,
|
2017-11-21 01:24:25 +00:00
|
|
|
open: "local",
|
2017-11-09 02:34:49 +00:00
|
|
|
server: {
|
|
|
|
baseDir: siteRoot
|
|
|
|
}
|
|
|
|
});
|
2017-11-11 08:26:29 +00:00
|
|
|
|
2017-11-21 01:24:25 +00:00
|
|
|
gulp.watch([mainCSS, tailwindConfig], ['css']);
|
|
|
|
gulp.watch(['**/*.html', '**/*.md', '**/*.yml', '!_site/**/*'], ['jekyll-build']);
|
2017-11-09 02:34:49 +00:00
|
|
|
});
|
|
|
|
|
2017-11-15 12:53:20 +00:00
|
|
|
gulp.task('default', ['css', 'serve']);
|