-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
150 lines (132 loc) · 3.45 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
'use strict';
const gulp = require('gulp');
const merge = require('merge-stream');
const prepend = require('gulp-prepend');
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const cleanCss = require('gulp-clean-css');
const svgstore = require('gulp-svgstore');
const svgmin = require('gulp-svgmin');
const connect = require('gulp-connect');
const imagemin = require('gulp-imagemin');
const uglify = require('gulp-uglify');
const del = require('del');
const pkg = require('./package.json');
const allSrc = ['src/**'];
const clean = (cb) => {
del.sync(['dist/**']);
cb();
};
const copy = () => {
const html = gulp.src('src/**/*.html')
.pipe(gulp.dest('dist'))
.pipe(connect.reload());
const manifest = gulp.src('src/manifest.json')
.pipe(gulp.dest('dist/'));
const favicon = gulp.src('src/favicon.ico')
.pipe(gulp.dest('dist'));
const fonts = gulp.src('src/fonts/*', { base: 'src' })
.pipe(gulp.dest('dist'));
return merge(html, manifest, favicon, fonts);
};
const styles = () => {
const banner = ['/*!',
` * ${pkg.name} - ${pkg.description}`,
` * @version v${pkg.version}`,
` * @link ${pkg.homepage}`,
'*/',
''].join('\n');
return gulp.src('src/css/core.scss')
.pipe(sass())
.pipe(cleanCss())
.pipe(prepend(banner))
.pipe(rename('style.min.css'))
.pipe(gulp.dest('dist/css'))
.pipe(connect.reload());
};
const compress = () => {
return gulp.src('src/js/*.js')
.pipe(uglify({
mangle: false
}))
.pipe(gulp.dest('dist/js'));
};
const images = () => {
return gulp.src('src/img/*')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest('dist/img'));
};
const appIcons = () => {
return gulp.src('src/img/icons/**/*')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest('dist/img/icons'));
};
const icons = () => {
return gulp.src('src/icons/*.svg')
.pipe(svgmin({
plugins: [
{
removePrefixedAttributes: {
type: 'perItem',
fn: (item) => {
item.eachAttr((attr) => {
if (attr.prefix && attr.local) {
item.removeAttr(attr.name);
}
});
}
}
},
{
removeAttrs: {
attrs: '(xmlns)'
}
}
]
}))
.pipe(gulp.dest('dist/icons'))
.pipe(svgstore())
.pipe(gulp.dest('dist/img'));
};
const svgs = () => {
return gulp.src('src/img/**/*.svg')
.pipe(svgmin({
plugins: [
{
removePrefixedAttributes: {
type: 'perItem',
fn: (item) => {
item.eachAttr((attr) => {
if (attr.prefix && attr.local) {
item.removeAttr(attr.name);
}
});
}
}
},
{
removeAttrs: {
attrs: '(xmlns)'
}
}
]
}))
.pipe(gulp.dest('dist/img'));
};
const serverConnect = () => {
return connect.server({
root: 'dist',
port: 7777,
livereload: true
});
};
const watch = () => {
return gulp.watch(allSrc, ['copy', 'styles', 'icons', 'appIcons', 'images', 'compress']);
};
module.exports.dev = gulp.series(clean, copy, styles, icons, appIcons, svgs, images, compress, serverConnect, watch);
const defaultTasks = gulp.series(clean, copy, styles, icons, appIcons, svgs, images, compress);
module.exports.default = defaultTasks;