blog_theme/gulpfile.js

85 lines
2.1 KiB
JavaScript
Raw Normal View History

const {series, parallel, watch, src, dest} = require('gulp');
const pump = require('pump');
// gulp plugins and utils
const livereload = require('gulp-livereload');
const gulpStylelint = require('gulp-stylelint');
const postcss = require('gulp-postcss');
2019-04-29 19:46:11 +03:00
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const beeper = require('beeper');
// postcss plugins
const easyimport = require('postcss-easy-import');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
function serve(done) {
livereload.listen();
done();
2019-04-29 19:46:11 +03:00
}
function handleError(done) {
return function (err) {
if (err) {
beeper();
}
return done(err);
};
};
function hbs(done) {
pump([
src(['*.hbs', 'partials/**/*.hbs', 'members/**/*.hbs']),
livereload()
], handleError(done));
2019-04-29 19:46:11 +03:00
}
function css(done) {
pump([
src('assets/css/screen.css', {sourcemaps: true}),
postcss([
easyimport,
autoprefixer(),
cssnano()
]),
dest('assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
2019-04-29 19:46:11 +03:00
}
function js(done) {
pump([
src([
'assets/js/lib/*.js',
'assets/js/main.js'
], {sourcemaps: true}),
concat('main.min.js'),
uglify(),
dest('assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
2019-04-29 19:46:11 +03:00
}
function lint(done) {
pump([
src(['assets/css/**/*.css', '!assets/css/vendor/*']),
gulpStylelint({
fix: true,
reporters: [
{formatter: 'string', console: true}
]
}),
dest('assets/css/')
], handleError(done));
2019-04-29 19:46:11 +03:00
}
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs', 'members/**/*.hbs'], hbs);
const cssWatcher = () => watch('assets/css/**/*.css', css);
const jsWatcher = () => watch('assets/js/**/*.js', js);
const watcher = parallel(hbsWatcher, cssWatcher, jsWatcher);
const build = series(css, js);
exports.build = build;
exports.lint = lint;
exports.default = series(build, serve, watcher);