-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (83 loc) · 2 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
const buildFolder = 'dist';
const sourceFolder = 'src';
const path = {
build: {
html: `${buildFolder}/`,
styles: `${buildFolder}/`,
scripts: `${buildFolder}/`,
img: `${buildFolder}/img/`
},
source: {
html: `${sourceFolder}/*.html`,
styles: `${sourceFolder}/*.less`,
scripts: `${sourceFolder}/*.js`,
img: `${sourceFolder}/img/*`
},
clean: `./${buildFolder}/`
};
const gulp = require('gulp');
const { src, dest } = require('gulp');
const less = require('gulp-less');
const minifyCSS = require('gulp-clean-css');
const browserSync = require('browser-sync').create();
const del = require('del');
function copyHTML() {
return src( path.source.html )
.pipe( dest( path.build.html ) )
.pipe( browserSync.stream() );
}
function transformStyles() {
return src( path.source.styles )
.pipe( less() )
.pipe( minifyCSS({ format: 'beautify' }) )
.pipe( dest( path.build.styles ) )
.pipe( browserSync.stream() );
}
function copyScripts() {
return src( path.source.scripts )
.pipe( dest( path.build.scripts ) );
}
function copyImg() {
return src( path.source.img )
.pipe( dest( path.build.img ) );
}
function initBrowserSync() {
browserSync.init({
server: {
baseDir: `./${buildFolder}/`
},
port: 2000,
notify: false
});
}
function watchFiles() {
gulp.watch( path.source.html, copyHTML );
gulp.watch( path.source.styles, transformStyles );
gulp.watch( path.source.scripts, copyScripts );
}
function clean() {
return del( path.clean );
}
const build = gulp.series(
clean,
gulp.parallel(
copyHTML,
transformStyles,
copyScripts,
copyImg,
)
);
const watch = gulp.parallel(
build,
watchFiles,
initBrowserSync
);
module.exports = {
default: build,
build,
watch,
copyHTML,
transformStyles,
copyScripts,
copyImg
};