-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
69 lines (57 loc) · 1.71 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
/* eslint-disable import/no-extraneous-dependencies, arrow-body-style */
// common
import gulp from 'gulp';
import plumber from 'gulp-plumber';
import plumberErrorHandler from 'gulp-plumber-error-handler';
import sourcemaps from 'gulp-sourcemaps';
import changed from 'gulp-changed';
import browserSync from 'browser-sync';
// styles
import sass from 'gulp-sass';
// scripts
import webpack from 'webpack-stream';
import webpackConfig from './webpack.config.babel';
const SOURCE = './source';
const OUT = './build';
const bsync = browserSync.create();
function errorHandler(taskName) {
return {
errorHandler: plumberErrorHandler(`Error in ${taskName} task`),
};
}
gulp.task('compile-styles', () => {
return gulp
.src(`${SOURCE}/styles/**/*.sass`)
.pipe(plumber(errorHandler('compile-styles')))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${OUT}/styles`));
});
gulp.task('compile-scripts', () => {
return gulp
.src(`${SOURCE}/scripts/index.jsx`)
.pipe(plumber(errorHandler('compile-scripts')))
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(`${OUT}/scripts`));
});
gulp.task('copy-markup', () => {
return gulp
.src(`${SOURCE}/*.html`)
.pipe(plumber(errorHandler('copy-markup')))
.pipe(changed(`${OUT}/static`))
.pipe(gulp.dest(OUT));
});
gulp.task('default', [
'copy-markup',
'compile-styles',
'compile-scripts',
], () => {
bsync.init({
server: OUT,
port: 5000,
});
gulp.watch(`${SOURCE}/styles/**/*.sass`, ['compile-styles']).on('change', bsync.reload);
gulp.watch(`${SOURCE}/scripts/**/*.{js,jsx}`, ['compile-scripts']).on('change', bsync.reload);
gulp.watch(`${SOURCE}/*.html`, ['copy-markup']).on('change', bsync.reload);
});