forked from wevote/WebApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
218 lines (188 loc) · 6.38 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// 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 cssmin = require("gulp-cssnano");
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],
};
// 2017-04-05 Watchify is causing too many problems, so we are turning it off until we can resolve Issue 757
// var opsWatchify = assign({ cache: {}, packageCache: {} }, watchify.args, ops);
// var browserifyWithWatchify = watchify(browserify(opsWatchify));
function err (e) {
console.error(e.toString());
this.emit("end");
}
return PRODUCTION ?
// production build with minification
browserify(ops)
.transform('uglifyify', { global: true })
.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
// browserifyWithWatchify
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`,
});
});
// October 2018: bootstrap-sccs is styling for bootstrap 3, so we no longer use it.
// Pull all bootstrap styling from the node_modules package bootstrap (v4)
gulp.task("compile-bootstrap", function () {
return gulp.src("./node_modules/bootstrap/scss/bootstrap.scss")
.pipe(sourcemaps.init())
.on("error", function (err) { console.error(err); })
.pipe(sass({ style: "expanded",
includePaths: [
"./node_modules/bootstrap/sccs",
"./node_modules/bootstrap/sccs/utilities",
"./node_modules/bootstrap/sccs/mixins",
], }))
.pipe(autoprefixer("last 2 version"))
.pipe(cssmin())
.pipe(sourcemaps.write(".")) // --> working directory is /build/css
.pipe(gulp.dest("./build/css"))
.pipe(browserSync.stream());
});
// Compile main and loading-screen, then copy them to the /build/css directory
gulp.task("sass", function () {
return gulp.src(["./src/sass/main.scss",
"./src/sass/loading-screen.scss",
])
.pipe(sourcemaps.init())
.on("error", function (err) { console.error(err); })
.pipe(sass({ style: "expanded" }))
.pipe(autoprefixer("last 2 version"))
.pipe(cssmin())
.pipe(sourcemaps.write(".")) // --> working directory is /build/css
.pipe(gulp.dest("./build/css"))
.pipe(browserSync.stream());
});
gulp.task("lint-css", function () {
const gulpStylelint = require("gulp-stylelint");
return gulp
.src("./src/sass/**/*.scss")
.pipe(gulpStylelint({
failAfterError: false,
reporters: [
{ formatter: "string", console: true },
],
}));
});
// Clean out Build directory
gulp.task("clean:build", function (done) {
return del(["./build/**"], done);
});
// Copy font files to Build directory
gulp.task("copy-fonts", function (done) {
gulp.src("./src/sass/base/fonts/**")
.pipe(gulp.dest("./build/fonts"))
.pipe(browserSync.stream());
done();
});
// Copy Index page to Build directory
gulp.task("copy-index", function (done) {
gulp.src("./src/*.html")
.pipe(gulp.dest("./build"))
.pipe(browserSync.stream());
done();
});
// Copy CSS files to Build directory
gulp.task("copy-css", function () {
return gulp.src("./src/css/**/*.scss")
.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());
});
// Copy javascript files to Build directory
gulp.task("copy-javascript", function () {
return gulp.src("./src/javascript/*")
.pipe(gulp.dest("./build/javascript"))
.pipe(browserSync.stream());
});
// Build tasks
gulp.task("build", gulp.series("copy-fonts", "copy-index", "compile-bootstrap", "copy-css", "copy-img", "copy-javascript", "browserify", "sass"));
// Watch tasks
gulp.task("watch", PRODUCTION ? ()=> {} : function (done) {
gulp.watch("./src/index.html", gulp.parallel("copy-index")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/sass/base/base/fonts/**", gulp.parallel("copy-fonts")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/sass/bootstrap/**", gulp.parallel("compile-bootstrap")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/css/**/*.scss", gulp.parallel("copy-css", "lint-css")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/img/**/*", gulp.parallel("copy-img")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/sass/**/*.scss", gulp.parallel("sass")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/javascript/*.js", gulp.parallel("copy-javascript")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
gulp.watch("./src/js/**/*.js?(x)", gulp.parallel("browserify")).on("change", function (path) {
console.log("Watcher: " + path + " was changed.");
done();
});
done();
});
// Default
gulp.task("default", gulp.series(
"clean:build",
"build",
"watch",
"server"
));