-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
90 lines (79 loc) · 2.17 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
const gulp = require('gulp');
const { src, dest, watch, series, parallel } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const imagemin = require('gulp-imagemin');
const connect = require('gulp-connect');
const liveServer = require("live-server");
const del = require('del');
const fileinclude = require('gulp-file-include');
function clean() {
return del(['dist']);
}
function html() {
return src([
'src/**/*.html',
// Ignore uk html files
'!src/header.html',
'!src/main.html',
'!src/footer.html',
// Ignore ru html files
'!src/ru/header.html',
'!src/ru/main.html',
'!src/ru/footer.html',
])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(dest('dist'))
.pipe(connect.reload());
}
function robots() {
return src('src/robots.txt')
.pipe(dest('dist'))
}
function normalize() {
return src('vendor/normalize/normalize.css')
.pipe(dest('dist/css'));
}
function css() {
return src('src/scss/index.scss')
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' })
.on('error', sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(dest('dist/css'))
.pipe(connect.reload());
}
function img() {
return src('src/assets/**/*.{png,jpg,gif,svg}')
.pipe(imagemin())
.pipe(dest('dist/assets'))
.pipe(connect.reload());
}
function js() {
return src('src/js/**/*.js')
.pipe(dest('dist/js'))
.pipe(connect.reload());
}
function watchFiles() {
watch('src/**/*.html', html);
watch('src/scss/**/*.scss', css);
watch('src/js/**/*.js', js);
watch('src/assets/**/*.{png,jpg,svg}', img);
}
function server() {
const params = {
port: 8080,
root: 'dist',
};
liveServer.start(params);
}
/* see npm scripts in package.json */
exports.default = series(clean, parallel(html, robots, normalize, css, img, js, watchFiles, server));
exports.build = series(clean, parallel(html, robots, normalize, css, img, js));
exports.clean = clean;
exports.serve = series(clean, parallel(html, robots, normalize, css, img, js), server);