-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
105 lines (93 loc) · 2.28 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
const gulp = require('gulp');
const del = require('del');
const cleanCSS = require('gulp-clean-css');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const paths = {
styles: {
src: 'src/styles/**/*.{pcss,css}',
dest: 'dist/styles/'
},
scripts: {
src: 'src/scripts/**/*.js',
dest: 'dist/scripts/'
},
images: {
src: 'src/images/**/*',
dest: 'dist/images/'
},
sw: {
src: 'src/sw.js',
dest: 'dist'
},
otherFiles: {
src: [
'src/*.html',
'src/*.mp3',
'src/*.json',
'src/*.ico'
],
dest: 'dist'
}
}
function sw() {
return gulp.src(paths.sw.src, { since: gulp.lastRun(sw) })
.pipe(gulp.dest(paths.sw.dest));
}
function images() {
return gulp.src(paths.images.src, { since: gulp.lastRun(images) })
.pipe(gulp.dest(paths.images.dest));
}
function clean() {
return del(['dist']);
}
function styles() {
return gulp.src(paths.styles.src, { since: gulp.lastRun(styles) })
.pipe(sourcemaps.init())
.pipe(
postcss([
require('precss'),
require('autoprefixer')
])
)
.pipe(cleanCSS())
.pipe(
rename((path) => {
path.extname = '.css'
})
)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest));
}
function scripts() {
return gulp.src(paths.scripts.src, { sourcemaps: true, since: gulp.lastRun(scripts) })
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.scripts.dest));
}
function otherFiles() {
return gulp.src(paths.otherFiles.src)
.pipe(gulp.dest(paths.otherFiles.dest));
}
function watch() {
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.styles.src, styles);
gulp.watch(paths.images.src, images);
gulp.watch(paths.otherFiles.src, otherFiles);
gulp.watch(paths.sw.src, sw);
}
const build = gulp.series(clean, gulp.parallel(styles, scripts, images, otherFiles, sw));
exports.clean = clean;
exports.styles = styles;
exports.scripts = scripts;
exports.images = images;
exports.otherFiles = otherFiles;
exports.sw = sw;
exports.watch = watch;
exports.build = build;
exports.default = build;