This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.babel.js
93 lines (84 loc) · 2.34 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
"use strict";
import gulp from "gulp";
import babel from "gulp-babel";
import uglify from "gulp-uglify";
import browserSync from "browser-sync";
import sass from "gulp-sass";
import autoprefixer from "autoprefixer";
import postcss from "gulp-postcss";
import sourcemaps from "gulp-sourcemaps";
import notify from "gulp-notify";
import plumber from "gulp-plumber";
import webpack from 'webpack';
import webpackConfig from './webpack.config.js';
import webpackStream from 'webpack-stream';
sass.compiler = require("node-sass");
const errorHandler = (err) => {
notify.onError({
title: `Gulp error in ${err.plugin}`,
message: err.toString()
})(err);
}
gulp.task("assets", function() {
return gulp.src("./src/assets/**/*").pipe(gulp.dest("./dist/assets/"));
});
gulp.task("html", function() {
return gulp
.src("./src/content/**/*.html")
.pipe(
plumber(errorHandler)
)
.pipe(gulp.dest("./dist/"));
});
gulp.task("js", function() {
return gulp
.src("src/js/main.js")
.pipe(
plumber(errorHandler)
)
.pipe(webpackStream(webpackConfig), webpack)
.pipe(uglify())
.on('error', errorHandler)
.pipe(gulp.dest("dist/js"));
});
gulp.task("sass", () => {
return gulp
.src("./src/scss/main.scss")
.pipe(
plumber({
errorHandler: function(err) {
notify.onError({
title: `Gulp error in ${err.plugin}`,
message: err.toString()
})(err);
}
})
)
.pipe(sourcemaps.init())
.pipe(sass())
.on("error", sass.logError)
.pipe(
postcss([
autoprefixer({ grid: true, browsers: ["> 5%", "last 4 versions"] })
])
)
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("./dist/css"))
.pipe(browserSync.stream());
});
gulp.task(
"serve",
gulp.series("sass", "html", "js", "assets", function() {
browserSync.init({
server: "./dist",
open: true // set to false to disable browser autostart
});
gulp.watch("src/scss/**/*", gulp.series("sass"));
gulp.watch("src/content/**/*.html", gulp.series("html"));
gulp.watch("src/js/*.js", gulp.series("js"));
gulp.watch("src/assets/**/*", gulp.series("assets"));
gulp.watch("dist/**/*").on("change", browserSync.reload);
})
);
gulp.task("build", gulp.series("sass", "html", "js", "assets"));
gulp.task("default", gulp.series("serve"));