-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
66 lines (59 loc) · 1.62 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
/**
* Create by Checkson on 2019-12-03
* Gulp Settings
*/
// import dependencies
const { src, dest, parallel, watch } = require('gulp');
const notify = require('gulp-notify');
const livereload = require('gulp-livereload');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const connect = require('gulp-connect');
// uglify JavaScript task
const uglifyJsTask = () => {
return src(['src/*.js', 'src/**/*.js'])
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(dest('dist/'))
.pipe(connect.reload())
.pipe(notify({
message: 'Uglify JavaScript task has finished!'
}));
};
// parse sass and minify css
const parseSassAndMinifyCssTask = () => {
return src('src/**/*.scss')
.pipe(sass())
.pipe(cleanCSS())
.pipe(rename({ extname: '.min.css' }))
.pipe(dest('dist'))
.pipe(connect.reload())
.pipe(notify({
message: 'Parse scss and minify css task has finished!'
}));
};
// start web server task
const startWebServerTask = (cb) => {
connect.server({
port: 8080,
livereload: true
});
cb();
};
// watch task
const watchTask = (cb) => {
watch('src/**/*.scss', parseSassAndMinifyCssTask);
watch(['src/*.js', 'src/**/*.js'], uglifyJsTask);
livereload.listen();
watch(['dist/**', 'themes/**']).on('change', livereload.changed);
startWebServerTask(cb);
cb();
};
// default task
const defaultTask = parallel(uglifyJsTask, parseSassAndMinifyCssTask);
// export watch task
exports.watch = watchTask;
// export default task
exports.default = defaultTask;