This repository has been archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
119 lines (102 loc) · 2.93 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
const gulp = require('gulp');
const lintHTML = require('gulp-htmllint');
const lintCSS = require('gulp-stylelint');
const lintJS = require('gulp-eslint');
const deleteFiles = require('gulp-rimraf');
const minifyHTML = require('gulp-minify-html');
const minifyCSS = require('gulp-clean-css');
const minifyJS = require('gulp-terser');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const replaceHTML = require('gulp-html-replace');
const imagemin = require('gulp-imagemin');
const zip = require('gulp-zip');
const checkFileSize = require('gulp-check-filesize');
const paths = {
src: {
html: 'src/**.html',
css: 'src/css/**.css',
js: 'src/js/**.js',
images: 'src/images/**'
},
dist: {
dir: 'dist',
css: 'style.min.css',
js: 'script.min.js',
images: 'dist/images'
}
};
gulp.task('lintHTML', () => {
return gulp.src('src/**.html')
.pipe(lintHTML());
});
gulp.task('lintCSS', () => {
return gulp.src(paths.src.css)
.pipe(lintCSS({
reporters: [{ formatter: 'string', console: true }]
}));
});
gulp.task('lintJS', () => {
return gulp.src(paths.src.js)
.pipe(lintJS())
.pipe(lintJS.failAfterError());
});
gulp.task('cleanDist', () => {
return gulp.src('dist/**/*', { read: false })
.pipe(deleteFiles());
});
gulp.task('buildHTML', () => {
return gulp.src(paths.src.html)
.pipe(replaceHTML({
css: paths.dist.css,
js: paths.dist.js
}))
.pipe(minifyHTML())
.pipe(gulp.dest(paths.dist.dir));
});
gulp.task('buildCSS', () => {
return gulp.src(paths.src.css)
.pipe(concat(paths.dist.css))
.pipe(minifyCSS())
.pipe(gulp.dest(paths.dist.dir));
});
gulp.task('buildJS', () => {
return gulp.src(paths.src.js)
.pipe(concat(paths.dist.js))
.pipe(minifyJS())
.pipe(gulp.dest(paths.dist.dir));
});
gulp.task('optimizeImages', () => {
return gulp.src(paths.src.images)
.pipe(imagemin())
.pipe(gulp.dest(paths.dist.images));
});
gulp.task('zip', () => {
const thirteenKb = 13 * 1024;
gulp.src('zip/*')
.pipe(deleteFiles());
return gulp.src(`${paths.dist.dir}/**`)
.pipe(zip('game.zip'))
.pipe(gulp.dest('zip'))
.pipe(checkFileSize({ fileSizeLimit: thirteenKb }));
});
gulp.task('test', gulp.parallel(
'lintHTML',
'lintCSS',
'lintJS'
));
gulp.task('build', gulp.series(
'cleanDist',
gulp.parallel('buildHTML', 'buildCSS', 'buildJS', 'optimizeImages'),
'zip'
));
gulp.task('watch', () => {
gulp.watch(paths.src.html, gulp.series('buildHTML', 'zip'));
gulp.watch(paths.src.css, gulp.series('buildCSS', 'zip'));
gulp.watch(paths.src.js, gulp.series('buildJS', 'zip'));
gulp.watch(paths.src.images, gulp.series('optimizeImages', 'zip'));
});
gulp.task('default', gulp.series(
'build',
'watch'
));