-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
127 lines (109 loc) · 3.3 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
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/lib/**.js', 'src/js/game.js'],
sfx: 'src/sfx/**',
images: 'src/img/**'
},
dist: {
dir: 'dist',
css: 'style.min.css',
js: 'script.min.js',
sfx: 'dist/sfx',
images: 'dist/img'
}
};
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('copySounds', () => {
return gulp.src(paths.src.sfx)
.pipe(gulp.dest(paths.dist.sfx));
});
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', 'copySounds', '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.sfx, gulp.series('copySounds', 'zip'));
gulp.watch(paths.src.images, gulp.series('optimizeImages', 'zip'));
});
gulp.task('default', gulp.series(
'build',
'watch'
));