-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
77 lines (67 loc) · 1.86 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
var gulp = require('gulp'),
connect = require('gulp-connect'),
minifyCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
useref = require('gulp-useref'),
uglify = require('gulp-uglify'),
gulpIf = require('gulp-if'),
babel = require('gulp-babel'),
del = require('del');
var paths = {
src: 'src',
dist: 'dist'
};
gulp.task('js', function() {
del.sync(paths.dist + '/js/*');
return gulp.src(paths.src + '/index.html')
.pipe(useref())
.pipe(gulpIf('**/script.min.js', babel({
presets: ['es2015']
})))
.pipe(gulpIf('*.js', uglify()))
.pipe(gulp.dest(paths.dist))
.pipe(connect.reload());
});
gulp.task('css', function() {
del.sync(paths.dist + '/css');
return gulp.src(paths.src + '/css/**/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(minifyCSS())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.dist + '/css'))
.pipe(connect.reload());
});
gulp.task('data', function() {
del.sync(paths.dist + '/data');
return gulp.src(paths.src + '/data/**')
.pipe(gulp.dest(paths.dist + '/data'))
.pipe(connect.reload());
});
gulp.task('img', function() {
del.sync(paths.dist + '/img');
return gulp.src(paths.src + '/img/**')
.pipe(gulp.dest(paths.dist + '/img'))
.pipe(connect.reload());
});
gulp.task('connect', function() {
connect.server({
port: 8888,
root: [paths.dist],
livereload: true
});
});
gulp.task('watch', function() {
gulp.watch([paths.src + '/index.html', paths.src + '/js/**/*.js'], ['js']);
gulp.watch(paths.src + '/css/**/*.css', ['css']);
gulp.watch(paths.src + '/data/**', ['data']);
gulp.watch(paths.src + '/img/**', ['img']);
});
gulp.task('start', ['connect', 'watch']);
gulp.task('default', function() {
gulp.start('start');
});