-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
91 lines (74 loc) · 2.31 KB
/
gulpfile.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
//Include required modules
var gulp = require("gulp"),
babelify = require("babelify"),
browserify = require("browserify"),
connect = require("gulp-connect"),
source = require("vinyl-source-stream")
buffer = require("vinyl-buffer")
sass = require("gulp-sass")
minifyCSS = require("gulp-minify-css")
minifyJS = require("gulp-uglify")
merge = require("merge-stream")
;
// Static files handler
gulp.task("staticFiles", function() {
// Videos
var videoFiles = gulp.src("./vids/*.*")
.pipe(gulp.dest("./dist/vids"));
// HTML Files
var htmlFiles = gulp.src("./src/html/*.*")
.pipe(gulp.dest("./dist"));
// CSS
var css = gulp.src("./src/scss/*.css")
.pipe(gulp.dest("./dist/css"));
// Fonts
var fonts = gulp.src("./src/scss/fonts/*.*")
.pipe(gulp.dest("./dist/fonts"));
// Images
var imgs = gulp.src("./src/img/*.*")
.pipe(gulp.dest("./dist/img"));
// JSON copy (just for the test purposes)
var json = gulp.src("./src/js/playlist.json")
.pipe(gulp.dest("./dist/json"))
return merge(videoFiles, htmlFiles, json, imgs, css, fonts);
});
//Convert ES6 in all js files in src/js folder and copy to
//build folder as bundle.js
gulp.task("js", function(){
return browserify({
entries: ["./src/js/index.js"]
})
.transform(babelify.configure({
presets : ["es2015"]
}))
.bundle()
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(minifyJS())
.pipe(gulp.dest("./dist/js"));
});
// Convert SCSS files to plain css
gulp.task("scss", function() {
gulp.src("./src/scss/*.scss")
.pipe(sass().on("error", sass.logError))
.pipe(minifyCSS())
.pipe(gulp.dest("./dist/css"));
});
//Default task
gulp.task("default", function() {
// We watch for changes in those files and rebundle them if needed
gulp.watch("./src/html/*.html", ["staticFiles"]);
gulp.watch("./src/scss/*.scss",["scss"]);
gulp.watch("./src/js/*.js", ["js"]);
// On init - we do everything
gulp.start(["js", "scss", "staticFiles", "startServer"]);
});
//Start a test server with doc root at build folder and
//listening to 9001 port. Home page = http://localhost:9001
gulp.task("startServer", function(){
connect.server({
root : "./dist",
livereload : true,
port : 9001
});
});