-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
104 lines (91 loc) · 3.04 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
'use-strict'
//Gulp functions
const { series, src, dest, watch, parallel } = require('gulp');
//Plugins
const del = require('del'),
imagemin = require('gulp-imagemin'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
uglify = require('gulp-uglify'),
usemin = require('gulp-usemin'),
rev = require('gulp-rev'),
cleanCss = require('gulp-clean-css'),
flatmap = require('gulp-flatmap'),
htmlmin = require('gulp-htmlmin');
//Compile scss files
function sassC(){
return src('./src/css/*.scss')
.pipe(sass().on('error',sass.logError))
.pipe(dest("./src/css"))
};
//Auto compile scss files on save
function watchSass(){
watch('./src/css/*.scss', sassC);
};
//Auto reload browser on save
function browsersync(){
var files = [
"./src/*.html",
"./src/css/*.css",
"./src/img/*.{png, jpg, gif}",
"./src/js/*.js",
"./*.*"
];
browserSync.init(files, {
server: {
baseDir: "./"
},
startPath: "./src/index.html"
});
};
//Deletes dist directory
function clean(){
return del(['dist']);
};
//Copy fontawesome fonts
function copyFonts(){
return src('node_modules/@fortawesome/fontawesome-free/webfonts/*.{ttf,woff,eof,svg}*')
.pipe(dest('./dist/fonts'));
}
//Compress images. Output saved to dist directory
function imageMin(){
return src('src/img/*.{png, jpg, gif}')
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(dest('dist/img'));
};
//Minify html, css, js and concatenate each. Output saved to dist directory with each version code.
function useMin(){
return src('./src/*.html')
.pipe(flatmap(function(stream, file){
return stream
.pipe(usemin({
css: [ rev()],
html: [function()
{
return htmlmin({
collapseWhitespace: true
})
}],
js: [
uglify(),
rev()
],
inlinejs: [
uglify()
],
inlinecss: [
cleanCss(),
'concat'
]
}))
}))
.pipe(dest('dist/'));
};
//Gulp commands
exports.sassCompile = sassC; //Compile scss
exports.build = series(clean, copyFonts, imageMin, useMin); //Recreate dist directory for deployment
exports.default = parallel(browsersync,watchSass); //Auto reload and compile on save while development