vac.dev-experimental-old/gulpfile.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-11-09 02:34:49 +00:00
const gulp = require('gulp');
const gutil = require('gulp-util');
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';
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
*/
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');
return gulp.src(mainCSS)
2017-11-09 02:34:49 +00:00
.pipe(postcss([
atimport(),
tailwindcss(tailwindConfig)
2017-11-09 02:34:49 +00:00
]))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cleancss())
.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
/**
* Serve site with BrowserSync
2017-11-15 12:53:20 +00:00
*/
gulp.task('serve', ['jekyll-build'], () => {
2017-11-09 02:34:49 +00:00
browserSync.init({
files: [siteRoot + '/**'],
port: 4000,
open: "local",
2017-11-09 02:34:49 +00:00
server: {
baseDir: siteRoot
}
});
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']);