-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
73 lines (64 loc) · 2.02 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
"use strict";
const gulp = require("gulp"),
browserSync = require("browser-sync").create(),
browserify = require("browserify"),
babel = require("babelify"),
runSequence = require("run-sequence"),
sass = require("gulp-sass"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
uglify = require("gulp-uglify"),
autoprefixer = require("gulp-autoprefixer");
// Paths
var resourcePath = "./src/",
compiledPath = "./htdocs/public/",
sassPath = resourcePath + "scss/",
jsPath = resourcePath + "js/";
// Transpile ES6 JS into JS compatible with older browsers and auto-inject into browsers
// Also minify the code to make it load faster in productions
gulp.task("build:js", () => {
return browserify({
entries: jsPath + "main.js"
})
.transform(babel, {presets: ["env"]})
.bundle()
.pipe(source("main.js"))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(compiledPath + "js/"))
.pipe(browserSync.stream());
});
// Compile sass into CSS and auto-inject into browsers
gulp.task("build:sass", () => {
return gulp.src(sassPath + "main.scss")
.pipe(sass())
.pipe(autoprefixer({
browsers: [
"Chrome >= 35",
"Safari >= 7",
"Firefox >= 29",
"ie > 9"
],
cascade: false
}))
.pipe(gulp.dest(compiledPath + "css/"))
.pipe(browserSync.stream());
});
// Serve the project using Browser-sync, allowing for hot reloading on file changes
gulp.task("serve", ["build:js", "build:sass"], () => {
browserSync.init({
server: "./htdocs"
});
gulp.watch("src/scss/**/*.scss", ["build:sass"]);
gulp.watch("src/js/**/*.js", ["build:js"]);
gulp.watch("htdocs/*.html").on("change", browserSync.reload);
});
// Compile all assets
gulp.task("build", () => {
runSequence(
"build:js",
"build:sass"
);
});
// Default task is build
gulp.task("default", ["build"]);