forked from wevote/WebApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
145 lines (126 loc) · 3.89 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// dependencies
const gulp = require("gulp");
const sass = require("gulp-sass");
const autoprefixer = require('gulp-autoprefixer');
const uglify = require("gulp-uglify");
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require("browser-sync").create();
const browserify = require("browserify");
const babelify = require("babelify");
const source = require("vinyl-source-stream");
const buffer = require("vinyl-buffer");
const del = require("del");
const server = require("./server");
const config = {
bootstrapDir: './node_modules/bootstrap-sass'
};
const PRODUCTION = process.env.NODE_ENV === "production";
gulp.task("browserify", function () {
const ops = {
debug: !PRODUCTION,
entries: "js/index.js",
extensions: [".js", ".jsx"],
basedir: "./src",
transform: [babelify]
};
function err (e){
console.error(e.toString());
this.emit("end");
}
return PRODUCTION ?
// production build with minification
browserify(ops)
.bundle()
.on("error", err)
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(uglify({ preserveComments: false, mangle: false }))
.pipe(gulp.dest("./build/js")) :
// development build... no minification
browserify(ops)
.bundle()
.on("error", err)
.pipe(source("bundle.js"))
.pipe(gulp.dest("./build/js"))
.pipe(browserSync.stream());
});
// Run server
gulp.task("server", PRODUCTION ? () => server(PRODUCTION) : function () {
server();
// only start browserSync when this is development
browserSync.init({
proxy: "localhost:3003",
open: false,
ghostMode: {
clicks: true,
forms: true,
scroll: true
},
logPrefix: `${new Date().toString().split(" ")[4]} - We Vote USA`
});
});
// Compile Bootstrap allowing for custom variables and selective imports
gulp.task('compile-bootstrap', function() {
return gulp.src('./src/sass/bootstrap.scss')
.pipe(sass({
includePaths: [config.bootstrapDir + '/assets/stylesheets'],
}))
.pipe(gulp.dest("./build/css/"));
});
// Compile main stylesheet and copy to Build directory
gulp.task("sass", function () {
return gulp.src("./src/sass/main.scss")
.pipe(sourcemaps.init())
.on("error", function (err) { console.error(err); })
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version'))
.pipe(sourcemaps.write())
.pipe(gulp.dest("./build/css"))
.pipe(browserSync.stream());
});
// Clean out Build directory
gulp.task("clean:build", function () {
return del.sync(["./build/**"]);
});
// Copy font files to Build directory
gulp.task("copy-fonts", function () {
gulp.src("./src/sass/base/fonts/**")
.pipe(gulp.dest("./build/fonts"))
.pipe(browserSync.stream());
});
// Copy Index page to Build directory
gulp.task("copy-index", function () {
gulp.src("./src/index.html")
.pipe(gulp.dest("./build"))
.pipe(browserSync.stream());
});
// Copy CSS files to Build directory
gulp.task("copy-css", function () {
return gulp.src("./src/css/**/*.css")
.pipe(gulp.dest("./build/css"))
.pipe(browserSync.stream());
});
// Copy image files to Build directory
gulp.task("copy-img", function () {
return gulp.src("./src/img/**/*")
.pipe(gulp.dest("./build/img"))
.pipe(browserSync.stream());
});
// Build tasks
gulp.task("build", ["copy-fonts", "copy-index", "compile-bootstrap", "copy-css", "copy-img", "browserify", "sass"]);
// Watch tasks
gulp.task("watch", ["build"], PRODUCTION ? ()=>{} : function () {
gulp.watch(["./src/index.html"], ["copy-index"]);
gulp.watch(["./src/sass/base/base/fonts/**"], ["copy-fonts"]);
gulp.watch(["./src/sass/bootstrap/**"], ["compile-bootstrap"]);
gulp.watch(["./src/css/**/*.css"], ["copy-css"]);
gulp.watch(["./src/img/**/*"], ["copy-img"]);
gulp.watch(["./src/sass/**/*.scss"], ["sass"]);
gulp.watch(["./src/js/**/*.js?(x)"], ["browserify"]);
});
// Default
gulp.task("default", [
"clean:build",
"watch",
"server"
]);