-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
94 lines (84 loc) · 2.19 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
88
89
90
91
92
93
94
/*
* Plugins
*/
import fs from 'fs'
import del from 'del'
import plumber from 'gulp-plumber'
import runSequence from 'run-sequence'
import htmlmin from 'html-minifier'
import cssmin from 'cssmin'
import gulp from 'gulp'
import babel from 'gulp-babel'
import uglify from 'gulp-uglify'
import replace from 'gulp-replace-task'
import bookmarkify from 'gulp-bookmarkify'
import eslint from 'gulp-eslint'
/**
* Tasks
*/
gulp.task('build', function (callback) {
runSequence(
'eslint',
'build.js01',
'build.js02',
'build.html',
'clean',
callback
);
});
gulp.task('eslint', () => {
return gulp.src('./src/js/*.js')
.pipe(plumber())
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('build.js01', () => {
return gulp.src('src/js/browsync.js')
.pipe(plumber())
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('build.js02', () => {
return gulp.src('src/js/main.js')
.pipe(plumber())
.pipe(babel())
.pipe(replace({
patterns: [
{
match: 'style',
replacement: cssmin(fs.readFileSync('./src/css/style.css', 'utf8'))
},
{
match: 'html',
replacement: htmlmin.minify(fs.readFileSync('./src/view/browsync.html', 'utf8'), {collapseWhitespace: true})
},
{
match: 'script',
replacement: fs.readFileSync('./dist/browsync.js', 'utf8')
}
]
}))
.pipe(bookmarkify())
.pipe(gulp.dest('dist'));
});
gulp.task('build.html', () => {
return gulp.src('src/view/index.html')
.pipe(plumber())
.pipe(replace({
patterns: [
{
match: 'script',
replacement: fs.readFileSync('./dist/main.js', 'utf8')
}
]
}))
.pipe(gulp.dest('build'));
});
gulp.task('clean', () => {
del(['dist']);
});
gulp.task('watch', () => {
gulp.watch('src/**/**', ['build']);
});
gulp.task('default', ['watch']);