This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
90 lines (78 loc) · 2.43 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 path = require('path');
const gulp = require('gulp');
const sass = require('gulp-sass');
const svg2png = require('gulp-svg2png');
const rename = require('gulp-rename');
const webpack = require('webpack-stream');
const webpackConfig = require('./webpack.config.js');
const paths = {
src: {
dir: './src'
},
dist: {
dir: './dist'
},
}
// Source paths
paths.src.fonts = path.join(paths.src.dir, 'fonts');
paths.src.html = path.join(paths.src.dir, 'html');
paths.src.imgs = path.join(paths.src.dir, 'imgs');
paths.src.scripts = path.join(paths.src.dir, 'scripts');
paths.src.styles = path.join(paths.src.dir, 'styles');
// Distribution paths
paths.dist.fonts = path.join(paths.dist.dir, 'fonts');
paths.dist.html = path.join(paths.dist.dir, 'html');
paths.dist.imgs = path.join(paths.dist.dir, 'imgs');
paths.dist.scripts = path.join(paths.dist.dir, 'scripts');
paths.dist.styles = path.join(paths.dist.dir, 'styles');
// HTML build task
gulp.task('html', () => {
return gulp.src(`${paths.src.html}/*.html`)
.pipe(gulp.dest(paths.dist.html));
});
const iconSizes = [128, 48, 32, 24, 16];
// Icon build task
gulp.task('icons', () => {
return iconSizes.forEach((size) => {
gulp.src(`${paths.src.imgs}/icon.svg`)
.pipe(svg2png({
height: size,
width: size
}))
.pipe(rename({
suffix: `_${size}`,
}))
.pipe(gulp.dest(paths.dist.imgs));
})
});
// Manifest build task
gulp.task('manifest', () => {
return gulp.src('./manifest.json')
.pipe(gulp.dest(paths.dist.dir));
});
// Manifest build task
gulp.task('fonts', () => {
return gulp.src(`${paths.src.fonts}/*`)
.pipe(gulp.dest(paths.dist.fonts));
});
// Javascript build task
gulp.task('scripts', () => {
return gulp.src(`${paths.src.scripts}/*.js`)
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(paths.dist.scripts));
});
// Sass build task
gulp.task('styles', () => {
return gulp.src(`${paths.src.styles}/*.scss`)
.pipe(sass())
.pipe(gulp.dest(paths.dist.styles));
});
gulp.task('build', ['html', 'icons', 'manifest', 'fonts', 'scripts', 'styles']);
gulp.task('default', ['build'], () => {
gulp.watch(`${paths.src.html}/**/*.html`, ['html']);
gulp.watch(`${paths.src.imgs}/icon.svg`, ['icons']);
gulp.watch('./manifest.json', ['manifest']);
gulp.watch(`${paths.src.fonts}/*`, ['fonts']);
gulp.watch(`${paths.src.scripts}/**/*.js`, ['scripts']);
gulp.watch(`${paths.src.styles}/**/*.scss`, ['styles']);
});