-
Notifications
You must be signed in to change notification settings - Fork 75
/
gulpfile.js
75 lines (67 loc) · 1.63 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
// gulpfile.js
var gulp = require('gulp');
var pug = require('gulp-pug');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var imagemin = require('gulp-imagemin');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var paths = {
// css
sassWatch: 'scss/**/*.scss',
css: 'css',
// html
htmlWatch: 'html/*.html',
pugWatch: 'views/*.pug',
pugWatch2: 'views/**/*.pug',
html: 'html',
// img
imgWatch: 'img/**/**/*',
img: 'img'
};
gulp.task('pug', function () {
return gulp.src(paths.pugWatch)
.pipe(rename(function(path){
var filename = path.basename.split('_')[1];
if(!filename) {
return path;
}
path.basename = filename;
return path;
}))
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest(paths.html))
});
gulp.task('html', function () {
return gulp.src(paths.htmlWatch)
pipe(browserSync.reload())
});
gulp.task('sass', function () {
return gulp.src(paths.sassWatch)
.pipe(sass({outputStyle: 'expanded'}))
.pipe(gulp.dest(paths.css))
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('image', function () {
return watch(paths.imgWatch)
.pipe(imagemin())
.pipe(gulp.dest(paths.img))
});
gulp.task('watch', ['sass'], function () {
gulp.watch(paths.pugWatch2, ['pug']);
gulp.watch(paths.sassWatch, ['sass']);
gulp.watch(paths.htmlWatch).on('change', browserSync.reload);
gulp.watch(paths.imgWatch, browserSync.reload);
});
gulp.task('browserSync',function () {
browserSync.init({
server: {
baseDir: './'
}
})
});
gulp.task('default', ['watch', 'pug' ]);