-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
118 lines (103 loc) · 2.25 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
/*global require*/
"use strict";
const gulp = require('gulp'),
path = require('path'),
pug = require('gulp-pug'),
prefix = require('gulp-autoprefixer'),
sass = require('gulp-sass')(require('sass')),
browserSync = require('browser-sync');
/*
* Directories here
*/
const paths = {
dist: './dist/',
sass: './src/sass/',
css: './dist/css/',
images: './dist/images/',
jsfiles: './dist/js/',
};
/**
* Compile .pug files
*/
function buildHtml () {
return gulp.src('./src/*.pug')
.pipe(pug())
.on('error', (err) => {
console.log(err.message);
})
.pipe(gulp.dest(paths.dist));
}
/**
* Compile .scss files into dist css directory With autoprefixer no
* need for vendor prefixes then live reload the browser.
*/
function buildCss () {
return gulp.src(paths.sass + '*.scss')
.pipe(sass({
includePaths: [paths.sass],
outputStyle: 'compressed'
}))
.on('error', sass.logError)
.pipe(prefix(['last 15 versions', '> 1%'], {
cascade: true
}))
.pipe(gulp.dest(paths.css))
.pipe(browserSync.reload({
stream: true
}));
}
/** Copy images to dist **/
function copyImages() {
return gulp.src('./src/images/**/*.{jpg,gif,png,svg}')
.pipe(gulp.dest(paths.images));
}
/** Copy js to dist **/
function copyJs() {
return gulp.src('./src/js/**/*')
.pipe(gulp.dest(paths.jsfiles));
}
/** Start browser-sync Server **/
function browserSyncServer(cb) {
gulp.parallel(buildCss, buildHtml, copyImages, copyJs);
browserSync({
server: {
baseDir: paths.dist
},
notify: false
});
cb();
}
/** Reload browser-sync **/
function browserSyncReload(cb){
browserSync.reload();
cb();
}
/**
* Watch .scss files for changes & recompile
* Watch .pug files for changes & recompile
*/
function watch () {
gulp.watch(
paths.sass + '**/*.scss',
gulp.series(buildCss, browserSyncReload)
);
gulp.watch(
'./src/**/*.pug',
gulp.series(buildHtml, browserSyncReload)
);
}
// Build task compile sass and pug and copy images and css.
const build = gulp.parallel(
buildCss,
buildHtml,
copyImages,
copyJs
);
// Serve (for developers)
const serve = gulp.series(
build,
browserSyncServer,
watch
);
exports.build = build;
exports.default = serve;