-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (81 loc) · 1.85 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
/* eslint-disable */
const gulp = require('gulp');
const del = require('del');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const browserify = require('browserify');
const tsify = require('tsify');
const eslint = require('gulp-eslint');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync').create();
function clean() {
return del(['dist']);
}
function build(done) {
gulp.series(
clean,
combine,
linter,
ts,
scss,
assets,
)(done);
}
function serve(done) {
browserSync.init({
server: {
baseDir: './dist',
},
});
done();
}
function reload(done) {
browserSync.reload();
done();
}
function run(done) {
gulp.series(
build,
serve,
watchers,
)(done);
}
function watchers() {
gulp.watch('./src/**/*.ts', gulp.series(linter, ts, assets, reload));
gulp.watch('./src/**/*.scss', gulp.series(scss, assets, reload));
}
function scss() {
return gulp.src('./src/**/*.scss')
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(concat('app.css'))
.pipe(gulp.dest('./dist'));
}
function assets() {
return gulp.src('./src/assets/images/**/*')
.pipe(gulp.dest('./dist/static'));
}
function linter() {
return gulp.src('./src/**/*.ts')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function ts() {
return browserify().add('./src/index.ts')
.plugin(tsify)
.bundle().on('error', function (error) {
console.error(error.toString());
})
.pipe(source('app.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./dist'));
}
function combine() {
return gulp.src('./public/index.html')
.pipe(gulp.dest('./dist'));
}
gulp.task('build', build);
gulp.task('default', run);