-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (104 loc) · 2.58 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const gulp = require('gulp');
const pug = require('gulp-pug');
const path = require('path');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const del = require('del');
const paths = {
root: './build',
templates: {
pages: 'src/templates/pages/*.pug',
src: 'src/templates/**/*.pug'
},
styles: {
src: 'src/styles/**/*.scss',
dest: 'build/'
},
scripts: {
src: 'src/scripts/**/*.js',
dest: 'build/'
},
images: {
src: 'src/images/**/*.*',
dest: 'build/assets/images/'
},
fonts: {
src: 'src/fonts/**/*.*',
dest: 'build/assets/fonts/'
}
};
// pug
function templates() {
return gulp
.src(paths.templates.pages)
.pipe(pug({ pretty: true }))
.pipe(gulp.dest(paths.root));
}
// scss
function styles() {
return gulp
.src('./src/styles/styles.scss')
.pipe(
sass({
outputStyle: 'compressed',
includePaths: require('node-normalize-scss').includePaths
}).on('error', function(error) {
console.log(error);
})
)
.pipe(
autoprefixer({
browsers: ['last 2 versions'],
cascade: false
})
)
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.styles.dest));
}
// очистка
function clean() {
return del(paths.root);
}
// галповский вотчер
function watch() {
gulp.watch(paths.templates.src, templates);
gulp.watch(paths.styles.src, styles);
gulp.watch(paths.images.src, images);
gulp.watch(paths.scripts.src, scripts);
}
// локальный сервер + livereload (встроенный)
function server() {
browserSync.init({
server: paths.root
});
browserSync.watch(paths.root + '/**/*.*', browserSync.reload);
}
// просто переносим картинки
function images() {
return gulp.src(paths.images.src).pipe(gulp.dest(paths.images.dest));
}
// просто переносим скрипты
function scripts() {
return gulp.src(paths.scripts.src).pipe(gulp.dest(paths.scripts.dest));
}
// просто переносим шрифты
function fonts() {
return gulp.src(paths.fonts.src).pipe(gulp.dest(paths.fonts.dest));
}
exports.templates = templates;
exports.styles = styles;
exports.fonts = fonts;
exports.clean = clean;
exports.images = images;
exports.scripts = scripts;
gulp.task('css', gulp.series(clean, styles));
gulp.task(
'default',
gulp.series(
clean,
gulp.parallel(styles, templates, fonts, images, scripts),
gulp.parallel(watch, server)
)
);