/
gulpfile.js
72 lines (63 loc) · 1.86 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
const gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
cleanCSS = require('gulp-clean-css'),
connect = require('gulp-connect'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
babel = require('gulp-babel'),
autoprefixer = require('gulp-autoprefixer'),
pug = require('gulp-pug');
const jsSources = ['assets/js/scripts/*.js'],
sassSources = ['assets/sass/app.sass'],
cssSources = ['assets/css/stylesheets/*.css'],
htmlSources = ['views/main/index.html'],
pugSources = ['views/main/pug/*.pug'];
gulp.task('log', function() {
gutil.log('hello world')
});
gulp.task('html', function() {
gulp.src(htmlSources)
.pipe(connect.reload())
});
gulp.task('pug', function() {
gulp.src(pugSources)
.pipe(pug({pretty: true}))
.pipe(gulp.dest('views/main'))
.pipe(connect.reload())
});
gulp.task('sass', function() {
gulp.src(sassSources)
.pipe(sass({outputStyle: 'extended'}))
.on('error', gutil.log)
.pipe(autoprefixer({browsers: ['last 4 versions'], cascade: false}))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename('app.min.css'))
.pipe(gulp.dest('assets/css'))
.pipe(connect.reload())
});
gulp.task('js', function() {
gulp.src(jsSources)
.pipe(babel({presets: ['es2015']}))
.pipe(uglify())
.pipe(concat('script.min.js'))
.pipe(gulp.dest('assets/js'))
.pipe(connect.reload())
});
gulp.task('watch', function() {
gulp.watch(htmlSources, ['html']);
gulp.watch(pugSources, ['pug']);
gulp.watch('views/main/pug/partials/*.pug', ['pug']);
gulp.watch('views/main/pug/partials/**/*.pug', ['pug']);
gulp.watch(sassSources, ['sass']);
gulp.watch('assets/sass/**/*.sass', ['sass']);
gulp.watch(jsSources, ['js']);
});
gulp.task('connect', function() {
connect.server({
root: '.',
livereload: true
})
});
gulp.task('default', ['html', 'pug', 'sass', 'js', 'connect', 'watch']);