This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
210 lines (192 loc) · 5.63 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
let projectFolder = require("path").basename(__dirname);
let sourceFolder = "#src";
let path = {
build: {
html: `${projectFolder}/`,
css: `${projectFolder}/css/`,
js: `${projectFolder}/js/`,
img: `${projectFolder}/img/`,
fonts: `${projectFolder}/fonts/`,
},
src: {
html: [`${sourceFolder}/*.html`, "!" + sourceFolder + "/_*.html"],
css: `${sourceFolder}/scss/style.scss`,
grid: `${sourceFolder}/grid/bootstrap-grid.min.css`,
js: `${sourceFolder}/js/script.js`,
img: `${sourceFolder}/img/**/*.+(png|jpg|gif|ico|svg|webp)`,
fonts: `${sourceFolder}/fonts/*.ttf`,
},
watch: {
html: `${sourceFolder}/**/*.html`,
css: `${sourceFolder}/scss/**/*.scss`,
js: `${sourceFolder}/js/**/*.`,
img: `${sourceFolder}/img/**/*.+(png|jpg|gif|ico|svg|webp)`
},
clean: `./${projectFolder}/`
}
let { src, dest } = require('gulp');
let gulp = require('gulp');
let browsersync = require('browser-sync').create();
let fileinclude = require('gulp-file-include');
let del = require('del');
let scss = require('gulp-sass');
let autoprefixer = require('gulp-autoprefixer');
let groupmedia = require('gulp-group-css-media-queries');
let cleancss = require('gulp-clean-css');
let rename = require('gulp-rename');
let uglify = require('gulp-uglify-es').default;
let imagemin = require('gulp-imagemin');
let webp = require('gulp-webp');
let webphtml = require('gulp-webp-html');
let webpcss = require('gulp-webpcss');
let svgSprite = require('gulp-svg-sprite');
let ttf2woff = require('gulp-ttf2woff');
let ttf2woff2 = require('gulp-ttf2woff2');
let fonter = require('gulp-fonter');
let fs = require('fs')
function browserSync(params) {
browsersync.init({
server: {
baseDir: `./${projectFolder}/`,
port: 3000,
notify: false
}
})
}
function html() {
return src(path.src.html)
.pipe(fileinclude())
.pipe(webphtml())
.pipe(dest(path.build.html))
.pipe(browsersync.stream())
}
function css() {
return src(path.src.css)
.pipe(
scss({
outputStyle: "expanded"
})
)
.pipe(groupmedia())
.pipe(
autoprefixer({
overrideBrowserslist: ["last 5 versions"],
cascade: true
})
)
.pipe(webpcss())
.pipe(dest(path.build.css))
.pipe(cleancss())
.pipe(rename({
extname: ".min.css"
}))
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}
function grid() {
return src(path.src.grid)
.pipe(dest(path.build.css))
}
function js() {
return src(path.src.js)
.pipe(fileinclude())
.pipe(dest(path.build.js))
.pipe(uglify())
.pipe(
rename({
extname: ".min.js"
})
)
.pipe(dest(path.build.js))
.pipe(browsersync.stream())
}
function images(params) {
return src(path.src.img)
.pipe(
webp({
quality: 70
})
)
.pipe(dest(path.build.img))
.pipe(src(path.src.img))
.pipe(
imagemin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
interlaced: true,
optimizationLevel: 3
})
)
.pipe(dest(path.build.img))
.pipe(browsersync.stream())
}
function fonts(params) {
src(path.src.fonts)
.pipe(ttf2woff())
.pipe(dest(path.build.fonts))
return src(path.src.fonts)
.pipe(ttf2woff2())
.pipe(dest(path.build.fonts))
}
function fontsStyle(params) {
let file_content = fs.readFileSync(sourceFolder + '/scss/fonts.scss');
if (file_content == '') {
fs.writeFile(sourceFolder + '/scss/fonts.scss', '', cb);
return fs.readdir(path.build.fonts, function (err, items) {
if (items) {
let c_fontname;
for (var i = 0; i < items.length; i++) {
let fontname = items[i].split('.');
fontname = fontname[0];
if (c_fontname != fontname) {
fs.appendFile(sourceFolder + '/scss/fonts.scss', '@include font("' + fontname + '", "' + fontname + '", "400", "normal");\r\n', cb);
}
c_fontname = fontname;
}
}
})
}
}
function cb() {
}
gulp.task('svgSprite', function () {
return gulp.src([`${sourceFolder}/iconsprite/*.svg`])
.pipe(svgSprite({
mode: {
stack: {
sprite: "../icons/icons.svg",
example: true
}
}
}
))
.pipe(dest(path.build.img))
});
gulp.task('otf2ttf', function () {
return gulp.src([`${sourceFolder}/fonts/*.otf`])
.pipe(fonter({
formats: ["ttf"]
}))
.pipe(dest(`${sourceFolder}/fonts/`))
});
function watchFiles(params) {
gulp.watch([path.watch.html], html);
gulp.watch([path.watch.css], css);
gulp.watch([path.watch.js], js);
gulp.watch([path.watch.img], images);
}
function clean(params) {
return del([path.clean])
}
let build = gulp.series(clean, gulp.parallel(js, css, html, images, fonts, grid), fontsStyle);
let watch = gulp.parallel(build, watchFiles, browserSync);
exports.grid = grid;
exports.fontsStyle = fontsStyle;
exports.fonts = fonts;
exports.images = images;
exports.js = js;
exports.css = css;
exports.html = html;
exports.build = build;
exports.watch = watch;
exports.default = watch;