forked from ahmadajmi/underscore-wordpress-with-gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
66 lines (58 loc) · 1.93 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require('es6-promise').polyfill();
var gulp = require('gulp'),
sass = require('gulp-sass'),
rtlcss = require('gulp-rtlcss'),
autoprefixer = require('gulp-autoprefixer'),
plumber = require('gulp-plumber'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
browserSync = require('browser-sync').create(),
reload = browserSync.reload;
var onError = function( err ) {
console.log('An error occurred:', gutil.colors.magenta(err.message));
gutil.beep();
this.emit('end');
};
// Sass
gulp.task('sass', function() {
return gulp.src('./sass/**/*.scss')
.pipe(plumber({ errorHandler: onError }))
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulp.dest('./'))
.pipe(rtlcss()) // Convert to RTL
.pipe(rename({ basename: 'rtl' })) // Rename to rtl.css
.pipe(gulp.dest('./')); // Output RTL stylesheets (rtl.css)
});
// JavaScript
gulp.task('js', function() {
return gulp.src(['./js/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./js'));
});
// Images
gulp.task('images', function() {
return gulp.src('./images/src/*')
.pipe(plumber({ errorHandler: onError }))
.pipe(imagemin({ optimizationLevel: 7, progressive: true }))
.pipe(gulp.dest('./images/dist'));
});
// Watch
gulp.task('watch', function() {
browserSync.init({
files: ['./**/*.php'],
proxy: 'http://localhost:8888/wordpress/',
});
gulp.watch('./sass/**/*.scss', ['sass', reload]);
gulp.watch(['./js/*.js', '!./js/app.min.js'], ['js', reload]);
gulp.watch('images/src/*', ['images', reload]);
});
gulp.task('default', ['sass', 'js', 'images', 'watch']);