-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.babel.js
94 lines (82 loc) · 2.1 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
'use strict';
import gulp from 'gulp';
import babel from 'gulp-babel';
import browserSync from 'browser-sync';
import ghPages from 'gulp-gh-pages';
import postcss from 'gulp-postcss';
import sourcemaps from 'gulp-sourcemaps';
import csswring from 'csswring';
import autoprefixer from 'autoprefixer';
import plumber from 'gulp-plumber';
import uglify from 'gulp-uglify';
import svgmin from 'gulp-svgmin';
let reload = browserSync.reload;
let APP_PATH = 'app/';
let BUILD_PATH = '_public/';
function swallowError (error) {
console.log(error.toString());
this.emit('end');
}
gulp.task('image', () => {
return gulp.src(`${APP_PATH}*.svg`)
.pipe(svgmin({
plugins: [
{cleanupIDs: false },
{sortAttrs: true }
]
}))
.pipe(gulp.dest(BUILD_PATH));
});
gulp.task('css', () => {
let processors = [
autoprefixer,
csswring
];
return gulp.src(`${APP_PATH}*.css`)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.on('error', swallowError)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(BUILD_PATH));
});
gulp.task('index', () => {
return gulp.src(`${APP_PATH}index.html`)
.pipe(gulp.dest(BUILD_PATH));
});
gulp.task('js', () => {
return gulp.src(`${APP_PATH}*.js`)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(BUILD_PATH));
});
gulp.task('serve', ['build'], () => {
browserSync({
open: 'external',
browser: 'google-chrome',
notify: false,
ghostMode: {
clicks: false,
scroll: false,
forms: false
},
scrollThrottle: 500,
startPath: BUILD_PATH,
server: ''
});
});
// Watch Files For Changes & Reload
gulp.task('dev', ['serve'], () => {
gulp.watch([`${APP_PATH}*.js`], ['js', reload]);
gulp.watch([`${APP_PATH}*.css`], ['css', reload]);
gulp.watch([`${APP_PATH}index.html`], ['index', reload]);
});
gulp.task('build', ['js', 'index', 'css', 'image']);
gulp.task('default', ['build']);
gulp.task('deploy', ['build'], () => {
return gulp.src(BUILD_PATH + '*/')
.pipe(ghPages());
});