-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
107 lines (88 loc) · 2.58 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
const { dest } = require('gulp');
var gulp = require('gulp'),
del = require('del'),
sass = require('gulp-sass'),
rename = require("gulp-rename"),
svgSprite = require('gulp-svg-sprite'),
inject = require('gulp-inject-string'),
browsersync = require('browser-sync').create(),
fs = require('fs');
// file paths
// -------------------------------------------------------------------------
var paths = {
styles: {
src: 'src/scss/**/main.scss',
dest: 'dist/css/'
},
icons: {
src: 'src/icons/**/*.svg',
dest: 'dist/icons/'
},
html: {
src: 'src/*.html',
dest: 'dist/'
},
};
// clean up folders
// -------------------------------------------------------------------------
function clean() {
return del([
'.temp',
'dist/*',
]);
}
// rename icons (if material icons/google icons) & copy to .temp folder
// -------------------------------------------------------------------------
function copyicons() {
return gulp.src(paths.icons.src)
.pipe(rename(function(opt) {
opt.basename = opt.basename.replace(/_black/, '');
opt.basename = opt.basename.replace(/_24dp/, '');
return opt;
}))
.pipe(gulp.dest('.temp/icons/'));
}
// compile the SVG sprite
function sprite() {
return gulp.src('.temp/icons/**/*.svg',)
.pipe(svgSprite({
mode: {
symbol: {
// inline: true,
// prefix: '#Icon-XYZ',
example: false,
sprite: 'sprite.svg',
dest: ''
}
}
}))
.pipe(gulp.dest(paths.icons.dest));
}
// inject sprite.svg to index.html
function injectsprite() {
return gulp.src('./src/index.html')
.pipe(inject.replace("%%INJECT_SPRITE%%", fs.readFileSync('./dist/icons/sprite.svg')))
.pipe(gulp.dest(paths.html.dest));
}
// css tasks: compile scss to css
// -------------------------------------------------------------------------
function styles() {
return gulp.src(paths.styles.src)
.pipe(sass())
.pipe(gulp.dest(paths.styles.dest))
}
// watch & browser sync
// -------------------------------------------------------------------------
function watch() {
browsersync.init({
server: './dist'
});
gulp.watch(paths.icons.src, build).on('change', browsersync.reload)
gulp.watch(paths.styles.src, styles).on('change', browsersync.reload)
gulp.watch(paths.html.src).on('change', browsersync.reload)
}
// build
// -------------------------------------------------------------------------
var build = gulp.series(clean, copyicons, gulp.parallel(sprite, styles), injectsprite);
gulp.task("build", build);
gulp.task("watch", watch);