casper/gulpfile.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-05-15 20:03:47 +00:00
var gulp = require('gulp');
// gulp plugins and utils
var gutil = require('gulp-util');
var livereload = require('gulp-livereload');
var nodemon = require('gulp-nodemon');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');
2017-05-15 20:03:47 +00:00
// postcss plugins
var autoprefixer = require('autoprefixer');
var colorFunction = require('postcss-color-function');
var cssnano = require('cssnano');
var customProperties = require('postcss-custom-properties');
var easyimport = require('postcss-easy-import');
var swallowError = function swallowError(error) {
gutil.log(error.toString());
gutil.beep();
this.emit('end');
};
var nodemonServerInit = function () {
livereload.listen(1234);
};
2017-06-16 09:13:38 +00:00
gulp.task('build', ['css'], function (/* cb */) {
2017-05-15 20:03:47 +00:00
return nodemonServerInit();
});
gulp.task('css', function () {
var processors = [
easyimport,
customProperties,
colorFunction(),
autoprefixer({browsers: ['last 2 versions']}),
cssnano()
];
return gulp.src('assets/css/*.css')
2017-05-15 20:03:47 +00:00
.on('error', swallowError)
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/built/'))
2017-05-15 20:03:47 +00:00
.pipe(livereload());
});
gulp.task('watch', function () {
gulp.watch('assets/css/**', ['css']);
});
gulp.task('zip', ['css'], function() {
var targetDir = 'dist/';
var themeName = require('./package.json').name;
var filename = themeName + '.zip';
return gulp.src(['**', '!node_modules', '!node_modules/**'])
.pipe(zip(filename))
.pipe(gulp.dest(targetDir));
});
2017-05-15 20:03:47 +00:00
gulp.task('default', ['build'], function () {
gulp.start('watch');
});