forked from beeblebrox3/star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·117 lines (97 loc) · 2.66 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var gulp = require("gulp");
var browserify = require("browserify");
var source = require("vinyl-source-stream");
var reactify = require("reactify");
var notify = require("gulp-notify");
var sass = require("gulp-sass");
var cssShrink = require("gulp-cssshrink");
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
var buffer = require("vinyl-buffer");
var concat = require('gulp-concat');
var browsersync = require("browser-sync").create();
var aliasify = require("aliasify");
var aliasifyConfig = {
aliases: {
".env.js": "./.env.js"
},
verbose: true
};
var environment = "dev";
var errorHandler = function (e) {
"use strict";
console.log(e);
notify("ops!");
this.emit("end");
};
gulp.task("browsersync", function () {
"use strict";
browsersync.init({
server: "./web",
host: "0.0.0.0",
open: false
});
gulp.watch([
"web/*.html",
"web/js/*.js"
]).on("change", browsersync.reload);
});
gulp.task("browserify", function () {
"use strict";
var bundle = browserify({
standalone: "App",
paths: ["./src/js"],
debug: false,
insertGlobalVars: true
})
.transform(reactify)
.transform(aliasify, aliasifyConfig)
.on("error", errorHandler)
.add("./src/js/bootstrap.js")
.bundle()
.on("error", errorHandler)
.pipe(source("bundle.js"))
.pipe(buffer());
if (environment === "prod") {
bundle.pipe(uglify());
}
bundle.pipe(gulp.dest("./web/js"))
.pipe(notify("bundle updated"));
return bundle;
});
gulp.task("sass", function () {
"use strict";
return gulp.src([
"./src/css/main.scss"
])
.pipe(sass())
.on("error", errorHandler)
.pipe(rename("bundle.css"))
.pipe(gulp.dest("./web/css"));
});
gulp.task("css", ["sass"], function () {
"use strict";
var bundle = gulp.src([
"web/libs/uikit/css/uikit.min.css",
"web/css/bundle.css"
])
.pipe(concat('bundle.min.css'))
if (environment === "prod") {
bundle.pipe(cssShrink())
}
return bundle.pipe(gulp.dest("./web/css"))
.pipe(browsersync.stream());
});
gulp.task("dev", ["browserify", "css", "browsersync"], function () {
"use strict";
gulp.watch(["src/js/**/*.js", "src/js/**/*.jsx"], ["browserify"]);
gulp.watch("src/css/**/*.scss", ["css"]);
});
gulp.task("default", ["browserify", "css"]);
gulp.task("prod", function () {
"use strict";
aliasifyConfig.aliases[".env.js"] = "./.env.prod.js";
environment = "prod";
process.env.NODE_ENV = "production";
gulp.start("browserify", "css");
});