This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
136 lines (124 loc) · 3.27 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
var gulp = require("gulp"),
gutil = require("gulp-util"),
concat = require("gulp-concat"),
usemin = require("gulp-usemin"),
minifyCSS = require("gulp-minify-css"),
del = require("del"),
processhtml = require("gulp-processhtml"),
minifyHTML = require("gulp-minify-html"),
uglify = require("gulp-uglify"),
es = require("event-stream"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
sourcemaps = require("gulp-sourcemaps"),
watchify = require("watchify"),
dotenv = require("dotenv");
var dir = {
dev: "./src/",
prod: "./dist/"
};
dotenv.load(); // Load environment variables from .env
/**
* Main execution
*/
gulp.task("default", ["clean"], function() {
gulp.start("scripts", "styles", "images", "robots");
});
/**
* Scripts
* Compiles all Require.js modules into one script, then uglifies and minifies the compiled file
*/
var initBundle = function(watch) {
var bundle = browserify({
entries: [
dir.dev + "scripts/shims/marionette.js",
dir.dev + "scripts/main.js"
],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
if(watch) {
bundle = watchify(bundle);
bundle.on("update", function() {
execBundle(bundle);
});
}
return execBundle(bundle);
};
var execBundle = function(bundle) {
return bundle.bundle()
.pipe(source("main.min.js"))
//.pipe(buffer())
//.pipe(sourcemaps.init({loadMaps: true}))
//.pipe(uglify())
//.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(dir.prod + "scripts/"));
};
gulp.task("watch", function() {
return initBundle(true);
});
gulp.task("scripts", function() {
return initBundle(false);
/*return browserify({
entries: [
dir.dev + "scripts/shims/marionette.js",
dir.dev + "scripts/main.js"
],
debug: true
})
.bundle()
.pipe(source("main.min.js"))
//.pipe(buffer())
//.pipe(sourcemaps.init({loadMaps: true}))
//.pipe(uglify())
//.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(dir.prod + "scripts/"));*/
});
/**
* Styles
* Combines all stylesheets then minifies it
*/
gulp.task("styles", function() {
return gulp.src(dir.dev + "*.html")
.pipe(usemin({
css: [minifyCSS({keepSpecialComments: 0}), "concat"]
}))
.pipe(minifyHTML())
.pipe(gulp.dest(dir.prod));
});
/**
* Robots.txt
* Copies file into dist directory
*/
gulp.task("robots", function() {
return gulp.src(dir.dev + "robots.txt")
.pipe(gulp.dest(dir.prod));
});
/**
* Images
* Copies images directory to production folder
* We could probably do some compression here
*/
gulp.task("images", function() {
return gulp.src(dir.dev + "images/**/*")
.pipe(gulp.dest(dir.prod + "images"));
});
/**
* HTML
* Minifies HTML
*/
gulp.task("html", function() {
return gulp.src(dir.dev + "*.html")
.pipe(minifyHTML())
.pipe(gulp.dest(dir.prod));
});
/**
* Clean
* Clean out the build directory for a new compile
*/
gulp.task("clean", function(cb) {
return del(dir.prod, cb);
});