-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
97 lines (87 loc) · 1.93 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
95
96
97
const gulp = require('gulp');
const browserify = require('gulp-browserify');
const babel = require('gulp-babel');
const connect = require('gulp-connect');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const plumber = require('gulp-plumber');
const notify = require("gulp-notify");
const sourcemaps = require("gulp-sourcemaps");
const gulpIf = require("gulp-if");
const autoprefixer = require("gulp-autoprefixer");
var isDev = !(process.env.DEV == 'production');
var path = {
root: './',
build: {
js: 'dist',
css: 'dist/css',
img: 'dist/img'
},
src: {
js: 'src/js/app.js',
css: 'src/css/*.css',
img: 'src/img/**/*.*'
},
watch: {
js: 'src/js/**/*.js',
css: 'src/css/**/*.css',
img: 'src/img/**/*.*'
}
};
var errorMessage = () => {
return plumber({errorHandler: notify.onError((err) => {
return {
title: err.name,
message: err.message
}
})})
}
// server
gulp.task('server', () => {
return connect.server({
port: 1338,
livereload: true,
root: path.root
});
});
// JavaScript, using Babel and uglifyJS
gulp.task('js', () => {
return gulp.src(path.src.js)
.pipe(errorMessage())
.pipe(browserify({
debug: isDev
}))
.pipe(
gulpIf(!isDev,
babel({
presets: ['es2015']
})
)
)
.pipe(gulpIf(!isDev, uglify()))
.pipe(gulp.dest(path.build.js))
.pipe(connect.reload());
});
// images min
gulp.task('images', function () {
gulp.src(path.src.img)
.pipe(errorMessage())
.pipe(imagemin())
.pipe(gulp.dest(path.build.img))
.pipe(connect.reload());
});
gulp.task('css', function () {
gulp.src(path.src.css)
.pipe(errorMessage())
.pipe(autoprefixer())
.pipe(gulp.dest(path.build.css))
.pipe(connect.reload());
});
// Watch files
gulp.task('watch', function() {
gulp.watch(path.watch.js, ['js']);
gulp.watch(path.watch.img, ['images']);
gulp.watch(path.watch.css, ['css']);
});
// Tasks
gulp.task('default', ['js', 'css', 'images', 'server', 'watch']);