This repository has been archived by the owner on Dec 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·58 lines (51 loc) · 1.6 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
var gulp = require('gulp');
var g = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/
});
var browserSync = require('browser-sync');
var cssnext = require('postcss-cssnext');
var cssnano = require('cssnano');
var reporter = require('postcss-reporter');
var browser = require('postcss-browser-reporter');
var handler = function (error) {console.log(error.message);this.emit('end');};
gulp.task('browser-sync', function() {
browserSync({
proxy: "localhost:2000",
online: false
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
return gulp.src('public/images/**/*')
.pipe(g.plumber({errorHandler: handler}))
.pipe(g.cache(g.imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('public/images/'));
});
gulp.task('styles', function(){
return gulp.src(['less/**/*.less'])
.pipe(g.plumber({errorHandler: handler}))
.pipe(g.sourcemaps.init())
.pipe(g.less())
.pipe(g.postcss([
cssnext({warnForDuplicates: false}),
cssnano(),
reporter(),
browser(),
]))
.pipe(gulp.dest('public/css/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts', function(){
return gulp.src(['public/js/**/*.js'])
.pipe(g.plumber({errorHandler: handler}))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('build', gulp.parallel('styles', 'scripts', 'images'));
gulp.task('default', gulp.series('browser-sync', function(){
gulp.watch("public/js/**/*.js", ['scripts']);
gulp.watch("less/**/*.less", ['styles']);
gulp.watch("views/**/*.pug", ['bs-reload']);
}));