weflock/gulpfile.js
Péter Szabolcs Nagy bfcab7172f Minified javascript in zip(#476)
no issue

* Added js minification step to gulp zip script
2018-10-08 16:34:07 +05:30

76 lines
1.9 KiB
JavaScript

var gulp = require('gulp');
// gulp plugins and utils
var gutil = require('gulp-util');
var livereload = require('gulp-livereload');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');
var uglify = require('gulp-uglify');
var filter = require('gulp-filter');
// 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);
};
gulp.task('build', ['css'], function (/* cb */) {
return nodemonServerInit();
});
gulp.task('css', function () {
var processors = [
easyimport,
customProperties,
colorFunction(),
autoprefixer({browsers: ['last 2 versions']}),
cssnano()
];
return gulp.src('assets/css/*.css')
.on('error', swallowError)
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/built/'))
.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';
var jsFilter = filter(['**/*.js'], {restore: true});
return gulp.src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
])
.pipe(jsFilter)
.pipe(uglify())
.pipe(jsFilter.restore)
.pipe(zip(filename))
.pipe(gulp.dest(targetDir));
});
gulp.task('default', ['build'], function () {
gulp.start('watch');
});