-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
85 lines (71 loc) · 2.11 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// INCLUDE GULP
var gulp = require('gulp');
// INCLUDE PLUGINS
var babel = require('gulp-babel');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var minify = require('gulp-minify');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var jswrap = require('gulp-js-wrapper');
var autoprefixer = require('gulp-autoprefixer');
// LINT JS
gulp.task('lint', function() {
return gulp.src('public/_js/*.js')
.pipe(jshint())
.pipe(plumber())
.pipe(jshint.reporter('default'))
});
// COMPILE SASS
gulp.task('sass', function () {
return gulp.src('public/_sass/*.sass')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions','last 3 iOS versions','> 1%'],
cascade: true
}))
.pipe(gulp.dest('dist/css'));
});
// CONCATENATE & MINIFY JS
gulp.task('scripts', function() {
return gulp.src([
'public/_js/**/*.js',
'public/_js/*.js',
])
.pipe(babel({
presets: ['env']
}))
.pipe(concat('scripts.js'))
.pipe(plumber())
.on('error', function(error) {
// Would like to catch the error here
//console.log(error);
//console.log(error.toString())
console.log('SCRIPTS ERROR');
this.emit('end')
})
// .pipe(jswrap({
// // pass a safe undefined into the encapsulation
// opener: '$(document).ready(function() {',
// closer: '});'
// }))
.pipe(gulp.dest('dist/js'))
.pipe(rename('scripts.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
});
// WATCH FILES FOR CHANGES
gulp.task('watch', function() {
gulp.watch([
'public/_js/*.js',
'public/_js/**/*.js',
], gulp.series('scripts'));
gulp.watch([
'public/_sass/*.sass',
'public/_sass/**/*.sass',
], gulp.series('sass'));
});
// DEFAULT TASK
gulp.task('default', gulp.series('sass','scripts','watch'));