-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
131 lines (118 loc) · 3.67 KB
/
Copy pathgulpfile.js
File metadata and controls
131 lines (118 loc) · 3.67 KB
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
var gulp = require("gulp")
, gutil = require("gulp-util")
, gulpif = require("gulp-if")
, uglify = require("gulp-uglify")
, minifyHTML= require("gulp-minify-html")
, jsonminify= require("gulp-jsonminify")
, imagemin = require("gulp-imagemin")
, pngquant = require("imagemin-pngquant")
, coffee = require("gulp-coffee")
, browserify= require("gulp-browserify")
, compass = require("gulp-compass")
, cleanDest = require("gulp-clean-dest")
, connect = require("gulp-connect")
, concat = require("gulp-concat");
var env
, coffeeSources
, jsSources
, sassSources
, htmlSources
, jsonSources
, imageSources
, outputDir
, sassStyle
;
env = process.env.NODE_ENV || "DEV";
if (env === "DEV") {
outputDir = "builds/development/";
sassStyle = "expanded";
} else {
outputDir = "builds/production/";
sassStyle = "compressed"
}
coffeeSources = ["components/coffee/tagline.coffee"];
jsSources =
[ "components/scripts/rclick.js"
, "components/scripts/pixgrid.js"
, "components/scripts/tagline.js"
, "components/scripts/template.js"
];
sassSources = ["components/sass/style.scss"];
htmlSources = ["builds/development/*.html"];
jsonSources = ["builds/development/js/*.json"];
imageSources= ["builds/development/images/**/*.*"];
gulp.task("html", function() {
gutil.log("- I handle HTML files");
gulp.src(htmlSources)
.pipe(gulpif(env === "PRD", minifyHTML()))
.pipe(gulpif(env === "PRD", gulp.dest(outputDir)))
.pipe(connect.reload());
});
gulp.task("json", function() {
gutil.log("- I handle JSON files");
gulp.src(jsonSources)
.pipe(gulpif(env === "PRD", jsonminify()))
.pipe(gulpif(env === "PRD", gulp.dest(outputDir + "js/")))
.pipe(connect.reload());
});
gulp.task("images", function() {
gutil.log("- I handle all the images");
gulp.src(imageSources)
.pipe(gulpif(env === "PRD", imagemin(
{ "progressive": true
, "svgoPlugins": [{ "removeViewBox": false }]
, use: [pngquant()]
})))
.pipe(gulpif(env === "PRD", gulp.dest(outputDir + "images")))
.pipe(connect.reload());
});
gulp.task("coffee", function() {
gutil.log("- I transpile coffee scripts into JavaScript files.");
gulp.src(coffeeSources)
.pipe(coffee({"bare": true})
.on("error", gutil.log))
.pipe(gulp.dest("components/scripts"))
});
gulp.task("js", function() {
gutil.log("- I concatenate all JavaScript files.");
gulp.src(jsSources) // The order of jsSources list controls the processing order.
.pipe(concat("script.js"))
.pipe(browserify())
.pipe(gulpif(env === "PRD", uglify()))
.pipe(gulp.dest(outputDir + "js"))
.pipe(connect.reload())
});
gulp.task("compass", function() {
gutil.log("- I transpile SCSS files using gulp-compass");
gulp.src(sassSources)
.pipe(compass(
{ "sass": "components/sass"
, "image": outputDir + "images"
, "style": sassStyle
, "comments": true
})
.on("error", gutil.log)
)
.pipe(gulp.dest(outputDir +"css"))
.pipe(connect.reload())
.pipe(cleanDest("css")) // Deleting "css/style.css" allows style to be changed from one run to the next
});
gulp.task("watch", function() {
gutil.log("- I sit here and watch for changes...");
gulp.watch(coffeeSources, ["coffee"]);
gulp.watch(jsSources, ["js"]);
gulp.watch("components/sass/*.scss", ["compass"]);
gulp.watch(htmlSources, ["html"])
gulp.watch(jsonSources, ["json"])
gulp.watch(imageSources, ["images"])
});
gulp.task("connect", function() {
gutil.log("- I create a server and reload when something changes");
connect.server(
{ "root": outputDir
, "livereload": true
})
});
gulp.task("default", ["html", "json", "images", "coffee", "js", "compass", "connect", "watch"], function() {
gutil.log("- I am the default task and I run the preceding tasks in sequence");
});