-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
87 lines (75 loc) · 2.13 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import connect from 'gulp-connect';
import util from 'gulp-util';
import path from 'path';
import cache from 'gulp-cached';
import eslint from 'gulp-eslint';
import rename from 'gulp-rename';
import replace from 'gulp-replace';
import jspm from 'gulp-jspm';
import htmlMin from 'gulp-htmlmin';
import imagemin from 'gulp-imagemin';
import pngquant from 'imagemin-pngquant';
import runSeq from 'run-sequence';
import del from 'del';
const paths = {
dist: './dist',
html: './src/*.html',
img: './src/images/*',
js: './src/**/*.js',
src: './src',
audio: './src/audio/**',
};
gulp.task('connect', () => {
connect.server({
root: paths.src,
livereload: false,
});
});
function logChanges(event) {
util.log(
util.colors.green(`File ${event.type}: `) +
util.colors.magenta(path.basename(event.path))
);
}
gulp.task('lintjs', () => gulp.src(paths.js)
.pipe(cache('lintjs'))
.pipe(eslint())
.pipe(eslint.format()));
gulp.task('watch', () => {
gulp.watch([paths.js], ['lintjs']).on('change', logChanges);
});
gulp.task('default', ['connect', 'watch']);
gulp.task('buildjs', () =>
gulp.src('./src/main.js')
.pipe(jspm({
selfExecutingBundle: true,
// minify: true,
skipSourceMaps: true,
}))
.pipe(rename('app.min.js'))
.pipe(gulp.dest(paths.dist)));
gulp.task('buildhtml', () =>
gulp.src(paths.html)
.pipe(replace('lib/system.js', 'app.min.js'))
.pipe(replace('<script src="config.js"></script>', ''))
.pipe(replace("<script>System.import('main');</script>", ''))
.pipe(htmlMin({ collapseWhitespace: true }))
.pipe(gulp.dest(paths.dist)));
gulp.task('buildimg', () =>
gulp.src(paths.img)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
use: [pngquant()],
}))
.pipe(gulp.dest(path.join(paths.dist, 'images'))));
gulp.task('copy-audio', () => {
gulp.src(paths.audio)
.pipe(gulp.dest(path.join(paths.dist, 'audio')));
});
gulp.task('clean', () =>
del(path.join(paths.dist, '*')));
gulp.task('build', (done) => {
runSeq('clean', ['buildimg', 'buildjs', 'buildhtml', 'copy-audio'], done);
});