-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
187 lines (172 loc) · 4.73 KB
/
gulpfile.babel.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
import gulp from "gulp";
import del from "del";
import rev from "gulp-rev";
import revReplace from "gulp-rev-replace";
import revNapkin from "gulp-rev-napkin";
import plumber from "gulp-plumber";
import sourcemaps from "gulp-sourcemaps";
import gulpSass from "gulp-sass";
import dartSass from "sass";
import rename from "gulp-rename";
import notify from "gulp-notify";
const $ = require("auto-plug")("gulp");
const sass = gulpSass(dartSass);
var onError = function (err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Basso",
})(err);
this.emit("end");
};
// compresses images (client => dist)
gulp.task("images", () => {
return gulp
.src("client/**/*.{jpg,png,gif,svg}")
.pipe(
$.imagemin({
progressive: true,
interlaced: true,
})
)
.pipe(gulp.dest("public"));
});
gulp.task("styles", function () {
return gulp
.src(["./client/styles/main.scss", "./client/styles/oldie.scss"])
.pipe(plumber({ errorHandler: onError }))
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: "node_modules",
importer: function importer(url, prev, done) {
if (url === "@financial-times/math") {
url = "@financial-times/math/index.scss";
}
if (url === "@financial-times/sass-mq") {
url = "@financial-times/sass-mq/index.scss";
}
return { file: url };
},
})
)
.pipe(rename("main.css"))
.pipe(gulp.dest("public/styles"));
});
// builds scripts with browserify
gulp.task("scripts", () => {
var main = gulp
.src(["./client/scripts/main.js"])
.pipe(plumber({ errorHandler: onError }))
.pipe(rename("main.bundle.js"))
.pipe(gulp.dest("public/scripts"));
var scroll = gulp
.src(["./client/scripts/scroll-depth-tracking.js"])
.pipe(plumber({ errorHandler: onError }))
.pipe(rename("scroll-depth-tracking.bundle.js"))
.pipe(gulp.dest("public/scripts"));
return main && scroll;
});
// copies over miscellaneous files (client => dist)
gulp.task("copy", () => {
return gulp
.src(
[
"client/**/*",
"!client/styles/**",
"!client/**/*.{scss,js,jpg,png,gif,svg}", // all handled by other tasks
],
{ dot: true }
)
.pipe(gulp.dest("public"));
});
// clears out the dist and .tmp folders
gulp.task("clean", del.bind(null, ["public/*", "!public/.git"], { dot: true }));
gulp.task("rev", () => {
return (
gulp
.src(
[
"public/styles/**/*.css",
"public/scripts/**/*.js",
"public/images/**/*.{png,svg,gif,jpg}",
],
{ base: "assets" }
)
.pipe(gulp.dest("public")) // copy original assets to build dir
// .pipe(rev())
.pipe(revReplace({ replaceInExtensions: [".css"] }))
.pipe(revNapkin({ verbose: false }))
.pipe(gulp.dest("public")) // write rev'd assets to build dir
.pipe(rev.manifest())
.pipe(gulp.dest("public"))
); // write manifest to build dir
});
// makes a production build (client => dist)
gulp.task(
"default",
gulp.series("clean", "copy", "styles", "scripts", "images", "rev"),
(done) => {
done();
}
);
// sets up watch-and-rebuild for JS and CSS
gulp.task("watch", () => {
gulp.watch(
"./client/**/*.scss",
gulp.series(["clean", "styles", "scripts", "images"])
);
gulp.watch(
"./client/**/*.{js,hbs}",
gulp.series(["clean", "styles", "scripts", "images"])
);
gulp.watch(
"./client/**/*.{jpg,png,gif,svg}",
gulp.series(["clean", "styles", "scripts", "images"])
);
});
// runs a development server (serving up .tmp and client)
gulp.task("serve", gulp.series(["watch", "images"]), (done) => {
const bs = require("browser-sync").create();
bs.init(
{
files: ["public/**/*", "client/**/*"],
server: {
baseDir: ["public", "client"],
},
open: false,
notify: false,
},
done
);
});
// builds and serves up the 'public' directory
gulp.task("serve:dist", gulp.series(["default"]), (done) => {
require("browser-sync").create().init(
{
open: false,
notify: false,
server: "public",
},
done
);
});
// lints JS files (DISABLED for poor ES6 support; we're going to switch to ESLint)
// gulp.task('jshint', () => {
// return obt.verify.jsHint(gulp, {
// jshint: './client/scripts/*.js',
// }).on('error', function (error) {
// console.error('\n', error, '\n');
// this.emit('end');
// });
// });
// lints SCSS files
// gulp.task('scsslint', () => {
// return obt.verify.scssLint(gulp, {
// sass: './client/styles/*.scss',
// }).on('error', function (error) {
// console.error('\n', error, '\n');
// this.emit('end');
// });
// });