aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.js
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-06-13 16:43:42 +0100
committerGravatar Gareth Coles <[email protected]>2018-06-13 16:43:42 +0100
commitbe2bbe35cf49763ad0258c005f3cbdddd7a21d75 (patch)
tree962d5e52f4bb57c397c068ae6a11b57952cfc459 /gulpfile.js
parent[DB] Attempt reconnection if current connection was lost (diff)
Compile as much JS with Gulp as possible
This will concatenate ALL of our JS, and minify it - thus leaving us with a single file to be loaded. There's a few libraries we can't do this with, unfortunately - these are now added in fouc.js: * Ace Editor * Flatpickr * Font-Awesome
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/gulpfile.js b/gulpfile.js
new file mode 100644
index 00000000..00a5549a
--- /dev/null
+++ b/gulpfile.js
@@ -0,0 +1,49 @@
+"use strict";
+/* global require */
+
+const del = require("del");
+const gulp = require("gulp");
+const run_sequence = require("run-sequence");
+
+// Gulp plugins
+const concat = require("gulp-concat");
+const rename = require("gulp-rename");
+const sourcemaps = require("gulp-sourcemaps");
+
+// Set up Uglify plugin with ES6-compatible Uglify tool
+const uglify_es = require("uglify-es");
+const uglify_compose = require("gulp-uglify/composer");
+const uglify = uglify_compose(uglify_es, console);
+
+const BASE_DIR = "./js";
+const BUILD_DIR = `${BASE_DIR}/build`;
+
+const SRC_DIR = `${BASE_DIR}/src`;
+const SRC_PATTERN = `${SRC_DIR}/**/*.js`;
+
+const VENDOR_DIR = `${BASE_DIR}/vendor`;
+const VENDOR_PATTERN = `${VENDOR_DIR}/**/*.js`;
+
+const OUTPUT_DIR = "./static/js";
+
+gulp.task("build:js", () => {
+ return gulp.src([ // Set source directories
+ SRC_PATTERN,
+ `${VENDOR_DIR}/moment/moment.js`, // Must be included before moment-timezone
+ VENDOR_PATTERN], {base: "BASE_DIR"})
+ .pipe(sourcemaps.init({largeFile: true})) // Initialise sourcemaps plugin
+ .pipe(concat("all.js.tmp")) // Concatenate all JS files together
+ .pipe(gulp.dest(BUILD_DIR)) // Write files to build dir
+ .pipe(rename("script.js")) // Set new output filename
+ .pipe(uglify({"mangle": false}).on("error", e => console.error(e))) // Minify the JS
+ .pipe(sourcemaps.write()) // Write the sourcemaps
+ .pipe(gulp.dest(OUTPUT_DIR)); // Write files to output dir
+});
+
+gulp.task("clean:js", () => {
+ return del([ // Delete temporary files
+ "js/build",
+ ])
+});
+
+gulp.task("default", (cb) => {run_sequence("build:js", "clean:js", cb)});