/
gulpfile.js
72 lines (59 loc) · 1.85 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');
const pug = require('gulp-pug');
const sass = require('gulp-sass');
const del = require('del');
const browserSync = require('browser-sync');
const rename = require('gulp-rename');
const cssmin = require('gulp-cssmin');
const plumber = require('gulp-plumber');
const notify = require('gulp-notify');
const imagemin = require('gulp-imagemin');
const paths = {
src: process.cwd() + '/src/**/*.*',
html: process.cwd() + '/src/templates/pages/*.pug',
css: process.cwd() + '/src/styles/main.sass',
images: process.cwd() + '/src/images/*.*',
dist: process.cwd() + '/dist/'
};
gulp.task('html', function() {
gulp.src(paths.html)
.pipe(plumber({
errorHandler: notify.onError("Error: <%= error.message %>")
}))
.pipe(pug({
pretty: false
}))
.pipe(gulp.dest(paths.dist))
//.pipe(browserSync.stream());
});
gulp.task('css', function() {
gulp.src(paths.css)
.pipe(plumber({
errorHandler: notify.onError("Error: <%= error.message %>")
}))
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dist + 'styles/'))
.pipe(browserSync.stream());
});
gulp.task('images', function() {
gulp.src(paths.images)
.pipe(imagemin())
.pipe(gulp.dest(paths.dist + 'images/'));
});
gulp.task('clean', function() {
del([paths.dist + '*']);
});
gulp.task('build', ['html', 'css']);
gulp.task('serve', ['html', 'css'], function() {
browserSync.init({
server: "dist/"
});
gulp.watch("src/templates/**/*.pug", ['html']);
gulp.watch("src/styles/**/*.*", ['css']);
gulp.watch("./dist/**/*.*").on('change', browserSync.reload);
});
gulp.task('default', ['serve']);