-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
76 lines (62 loc) · 1.73 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
"use strict";
// Import dependencies.
import gulp from "gulp";
import connect from "gulp-connect";
import watch from "gulp-watch";
import sass from "gulp-sass";
import imagemin from "gulp-imagemin";
import cache from "gulp-cache";
import browserify from "browserify";
import source from "vinyl-source-stream";
// Browser Sync
const browserSync = require("browser-sync").create();
// Sources
const JS_SOURCES = ['app/js/*.js'];
const HTML_SOURCES = ['app/*.html']
const SASS_SOURCES = ['app/sass/**/*.sass']
//////////// Tasks ////////////
// Watch
gulp.task('watch', ['browserSync', 'sass'], () => {
gulp.watch(JS_SOURCES, ['babel']);
gulp.watch(HTML_SOURCES, browserSync.reload);
gulp.watch(SASS_SOURCES, ['sass']);
});
// Babel
gulp.task('babel', () => {
return browserify("app/js/app.js")
.transform("babelify")
.bundle()
.pipe(source("bundle.js"))
.pipe(gulp.dest("app/js"))
.pipe(browserSync.reload({
stream: true
}));
});
// Sass
gulp.task('sass', () => {
return gulp.src(SASS_SOURCES)
.pipe(sass({outputStyle: 'compact', indentedSyntax: true, sourceComments: true}).on('error', sass.logError))
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({
stream: true
}));
});
// BrowserSync
gulp.task('browserSync', () => {
browserSync.init({
server: {
baseDir: 'app'
},
});
});
// Imagemin
gulp.task('images', () => {
return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('dist/images'));
});
// Default Task
gulp.task("default", ['babel', 'watch', 'sass']);
// Left off on https://css-tricks.com/gulp-for-beginners/#article-header-id-12