-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
166 lines (152 loc) · 3.78 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"use strict";
/* paths configuration */
var path = {
build: {
html: "./dist/",
js: "./dist/js/",
css: "./dist/css/",
img: "./dist/img/",
fonts: "./dist/fonts/",
fontIcons: "./dist/fonts/",
},
src: {
html: "./src/*.html",
js: "./src/js/main.js",
style: "./src/style/main.scss",
fontIcons: "./src/font_icons/icons/*.svg",
img: [
"./src/img/**/*.*",
],
fonts: [
"./src/fonts/**/*.*",
]
},
watch: {
html: "./src/**/*.html",
js: "./src/js/**/*.js",
css: "./src/style/**/*.scss",
img: "./src/img/**/*.*",
fonts: "./srs/fonts/**/*.*",
fontIcons: "./src/font_icons/icons/*.svg",
static: [
"./src/style/**/*.scss",
"./src/js/**/*.js",
"./srs/fonts/**/*.*",
"./src/font_icons/icons/*.svg",
"!./src/style/theme/_icons.scss"
]
},
clean: "./dist/*",
};
/* Web server config */
var config = {
server: {
baseDir: "./dist",
},
notify: false,
};
/* Gulp config */
const sass = require('gulp-sass')(require('sass'));
var gulp = require("gulp"),
minify = require("gulp-minify"),
webserver = require("browser-sync"),
plumber = require("gulp-plumber"),
rigger = require("gulp-rigger"),
sourcemaps = require("gulp-sourcemaps"),
autoprefixer = require("gulp-autoprefixer"),
cleanCSS = require("gulp-clean-css"),
cache = require("gulp-cache"),
imagemin = require("gulp-imagemin"),
jpegrecompress = require("imagemin-jpeg-recompress"),
pngquant = require("imagemin-pngquant"),
rimraf = require("gulp-rimraf"),
iconfont = require('gulp-iconfont'),
iconfontCss = require('gulp-iconfont-css'),
rename = require("gulp-rename"),
webpack = require('webpack-stream');
/* Main tasks */
/**
* Start a web server
*/
gulp.task("webserver", function() {
webserver(config);
});
/**
* Build html
*/
gulp.task("html:build", function() {
return gulp
.src(path.src.html)
.pipe(plumber())
.pipe(rigger())
.pipe(gulp.dest(path.build.html))
.pipe(webserver.reload({ stream: true }));
});
/**
* Process images
*/
gulp.task("image:build", function() {
return gulp
.src(path.src.img)
.pipe(
cache(
imagemin([
imagemin.gifsicle({ interlaced: true }),
jpegrecompress({
progressive: true,
max: 90,
min: 80,
}),
pngquant(),
imagemin.svgo({ plugins: [{ removeViewBox: false }] }),
])
)
)
.pipe(gulp.dest(path.build.img));
});
/**
* Clean build
*/
gulp.task("clean:build", function() {
return gulp.src(path.clean, { read: false }).pipe(rimraf());
});
/**
* Clean the cache
*/
gulp.task("cache:clear", function() {
cache.clearAll();
});
/**
* Builds assets using webpack
*/
gulp.task('assets:build', function() {
return gulp.src(path.src.js)
.pipe(webpack(require('./webpack.config.js')))
.pipe(gulp.dest('dist/assets/'));
});
/**
* Main build task
*/
gulp.task(
"build",
gulp.series(
"clean:build",
gulp.parallel(
"html:build",
"assets:build",
"image:build",
)
)
);
/**
* Watch task
*/
gulp.task("watch", function() {
gulp.watch(path.watch.html, gulp.series("html:build"));
gulp.watch(path.watch.static, gulp.series("assets:build"));
gulp.watch(path.watch.img, gulp.series("image:build"));
});
/**
* Default task
*/
gulp.task("default", gulp.series("build", gulp.parallel("webserver", "watch")));