-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathgulpfile.js
192 lines (162 loc) · 4.62 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
"use strict";
// Include Gulp and other build automation tools and utilities
// See: https://github.com/gulpjs/gulp/blob/master/docs/API.md
var gulp = require("gulp");
var $ = require("gulp-load-plugins")();
var del = require("del");
var path = require("path");
var runSequence = require("run-sequence");
var webpack = require("webpack");
var argv = require("minimist")(process.argv.slice(2));
// Settings
var DEST = "./build"; // The build output folder
var RELEASE = !!argv.release; // Minimize and optimize during a build?
var AUTOPREFIXER_BROWSERS = [ // https://github.com/ai/autoprefixer
"ie >= 8",
"ie_mob >= 10",
"ff >= 24",
"chrome >= 20",
"safari >= 6",
"opera >= 12",
"ios >= 6",
"bb >= 10",
"Android 2.3",
"Android >= 4"
];
// Gulp src wrapper, see: https://gist.github.com/floatdrop/8269868
gulp.plumbedSrc = function () {
return gulp.src.apply(gulp, Array.prototype.slice.call(arguments))
.pipe($.plumber());
};
var src = {};
var watch = false;
// The default task
gulp.task("default", ["watch"]);
// Clean up
gulp.task("clean", del.bind(null, [DEST]));
// Static files
gulp.task("assets", function () {
src.assets = "client/assets/**";
return gulp.src(src.assets)
.pipe($.changed(DEST))
.pipe(gulp.dest(DEST))
.pipe($.size({title: "assets"}));
});
gulp.task("libraries", function() {
var src = [
"bower_components/jquery/dist/jquery.min.js",
"bower_components/foundation/js/foundation.min.js",
"bower_components/modernizr/modernizr.js",
"bower_components/fastclick/lib/fastclick.js",
"./client/vendor/zxcvbn.js"
];
return gulp.src(src)
.pipe(gulp.dest("build/js/vendor"));
});
gulp.task("fonts", function() {
// Move and minify font css
gulp.src("bower_components/mdi/css/materialdesignicons.css")
.pipe($.if(RELEASE, $.minifyCss()))
.pipe(gulp.dest("build/css"));
// Move font files
gulp.src("bower_components/mdi/fonts/*.*")
.pipe(gulp.dest("build/fonts"));
});
gulp.task("vendor", ["libraries", "fonts"]);
gulp.task("styles", ["sass-styles", "mui-styles"]);
// Combine language bundles
gulp.task("languageBundles", ["language_en"]);
gulp.task("language_en", function() {
gulp.src("./client/src/**/locale_en.json")
.pipe($.extend("app.json"))
.pipe(gulp.dest("build/locales/en/"));
});
// CSS style sheets
gulp.task("sass-styles", function () {
// Source files
src.styles = ["client/styles/style.sass"];
// Process
return gulp.plumbedSrc(src.styles)
// Process sass files
.pipe($.sass({
sourceMap: !RELEASE,
sourceMapBasepath: __dirname
}))
// Auto prefix, concat and format
.pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
.pipe($.concat("style.css"))
.pipe($.csscomb())
// If in release mode, minify the css
.pipe($.if(RELEASE, $.minifyCss()))
// Write resulting css file to disk
.pipe(gulp.dest(DEST + "/css"))
.pipe($.size({title: "style"}));
});
gulp.task("mui-styles", function () {
src.styles = [
"client/styles/material-ui.less"
];
return gulp.plumbedSrc(src.styles)
.pipe($.less({
strictMath: true,
sourceMap: !RELEASE,
sourceMapBasepath: __dirname
}))
.pipe($.if(RELEASE, $.minifyCss()))
.pipe(gulp.dest(DEST + "/css"))
.pipe($.size({title: "style"}));
});
// Bundle
gulp.task("bundle", function (cb) {
var started = false;
var config = require("./config/webpack.js")(RELEASE);
var bundler = webpack(config);
function bundle(err, stats) {
if (err) {
throw new $.util.PluginError("webpack", err);
}
var verbose = true;//!!argv.verbose;
if (verbose) {
$.util.log("[webpack]", stats.toString({colors: true}));
}
if (!started) {
started = true;
return cb();
}
}
if (watch) {
bundler.watch(200, bundle);
} else {
bundler.run(bundle);
}
});
// Build the app from source code
gulp.task("build", ["clean"], function (cb) {
runSequence(["assets", "styles", "bundle", "vendor", "languageBundles"], cb);
});
// Setup live reload
var tinylr;
gulp.task("livereload", function(cb) {
tinylr = require("tiny-lr")();
tinylr.listen(35729);
cb();
});
function notifyLiveReload(fileName) {
tinylr.changed({
body: {
files: [fileName]
}
});
}
gulp.task("watch", function (cb) {
watch = true;
runSequence("build", "livereload", function () {
gulp.watch(src.assets, ["assets"]);
gulp.watch(["client/styles/**.*"], ["styles"]);
gulp.watch(DEST + "/**/*.*", function (file) {
var fileName = path.relative(__dirname, file.path);
notifyLiveReload(fileName);
});
cb();
});
});