-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
96 lines (87 loc) · 2.57 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
86
87
88
89
90
91
92
93
94
95
96
var gulp = require('gulp'),
less = require('gulp-less'),
path = require('path'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
nodemon = require('gulp-nodemon'),
sourcemaps = require('gulp-sourcemaps');
var BROWSER_SYNC_RELOAD_DELAY = 5000;
gulp.task('nodemon', function (cb) {
var called = false;
return nodemon({
script: 'server.js',
watch: ['server.js']
})
.on('start', function onStart() {
if (!called) { cb(); }
called = true;
})
.on('restart', function onRestart() {
setTimeout(function reload() {
browserSync.reload({
stream: false
});
}, BROWSER_SYNC_RELOAD_DELAY);
});
});
gulp.task('browser-sync', ['nodemon'], function () {
var files = [
'*.html',
'views/*.*',
'views/*.*',
'views/layouts/*.*',
'public/css/*.css',
'public/images/**/*',
'public/js/*.js'
];
browserSync.init(files, {
proxy: "localhost:3011",
port: 4000
});
});
gulp.task('styles', function() {
return gulp.src('src/styles/*.less')
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(gulp.dest('public/css'))
.pipe(autoprefixer('last 3 version', 'android >= 3', { cascade: true }))
.pipe(gulp.dest('public/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('public/css'))
.pipe(notify({ message: 'Styles task complete' }))
.pipe(reload({stream:true}));
});
gulp.task('scripts', function() {
return gulp.src('src/scripts/**/*.js')
.pipe(jshint('tests/.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(gulp.dest('public/js'))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/js'))
.pipe(notify({ message: 'Scripts task complete' }));
});
gulp.task('clean', function() {
return gulp.src(['public/css', 'public/js'], {read: false})
.pipe(clean());
});
gulp.task('watch', function() {
gulp.watch('src/styles/*.less', ['styles']);
gulp.watch('src/scripts/*.js', ['scripts']);
});
gulp.task('default', ['clean', 'browser-sync'], function() {
gulp.start('styles', 'scripts', 'watch');
});