-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·158 lines (143 loc) · 4.12 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
// Load all the modules from package.json
var gulp = require("gulp"),
plumber = require("gulp-plumber"),
autoprefixer = require("gulp-autoprefixer"),
watch = require("gulp-watch"),
jshint = require("gulp-jshint"),
stylish = require("jshint-stylish"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
notify = require("gulp-notify"),
include = require("gulp-include"),
sass = require("gulp-sass"),
browserSync = require("browser-sync").create(),
critical = require("critical"),
zip = require("gulp-zip");
var config = {
nodeDir: "./node_modules"
};
// Default error handler
var onError = function(err) {
console.log("An error occured:", err.message);
this.emit("end");
};
// JS to watch
var jsFiles = ["./js/**/*.js", "!./js/dist/*.js"];
// Sass files to watch
var cssFiles = ["./sass/**/*.scss"];
// automatically reloads the page when files changed
var browserSyncWatchFiles = ["./*.min.css", "./js/**/*.min.js", "./**/*.php"];
// see: https://www.browsersync.io/docs/options/
var browserSyncOptions = {
watchTask: true,
proxy: "http://sp:8888/"
};
// Zip files up
gulp.task("zip", function() {
return gulp
.src(
[
"*",
"./css/*",
"./fonts/*",
"./images/**/*",
"./inc/**/*",
"./js/**/*",
"./languages/*",
"./sass/**/*",
"./template-parts/*",
"./templates/*",
"!bower_components",
"!node_modules"
],
{ base: "." }
)
.pipe(zip("fitzmuseum.zip"))
.pipe(gulp.dest("."));
});
// Jshint outputs any kind of javascript problems you might have
// Only checks javascript files inside /src directory
gulp.task("jshint", function() {
return gulp
.src("./js/src/*.js")
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter("fail"));
});
// Concatenates all files that it finds in the manifest
// and creates two versions: normal and minified.
// It's dependent on the jshint task to succeed.
gulp.task("scripts", function() {
return (
gulp
.src("./js/manifest.js")
.pipe(include())
.pipe(rename({ basename: "scripts" }))
.pipe(gulp.dest("./js/dist"))
// Normal done, time to create the minified javascript (scripts.min.js)
// remove the following 3 lines if you don't want it
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("./js/dist"))
.pipe(browserSync.reload({ stream: true }))
.pipe(notify({ message: "scripts task complete" }))
);
});
// Sass - Creates a regular and minified .css file in root
gulp.task("sass", function() {
return gulp
.src("./sass/style.scss")
.pipe(plumber())
.pipe(
sass({
errLogToConsole: true,
precision: 8,
noCache: true,
//imagePath: 'assets/img',
includePaths: [config.nodeDir + "/bootstrap/scss"]
}).on("error", sass.logError)
)
.pipe(autoprefixer())
.pipe(gulp.dest("."))
.pipe(sass({ outputStyle: "compressed" }).on("error", sass.logError))
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("."))
.pipe(browserSync.reload({ stream: true }))
.pipe(notify({ title: "Sass", message: "sass task complete" }));
});
// Generate & Inline Critical-path CSS
gulp.task("critical", function(cb) {
critical.generate({
base: "./",
src: "http://sp:8888/",
dest: "css/home.min.css",
ignore: ["@font-face"],
dimensions: [
{
width: 320,
height: 480
},
{
width: 768,
height: 1024
},
{
width: 1280,
height: 960
}
],
minify: true
});
});
// Starts browser-sync task for starting the server.
gulp.task("browser-sync", function() {
browserSync.init(browserSyncWatchFiles, browserSyncOptions);
});
// Start the livereload server and watch files for change
gulp.task("watch", function() {
// don't listen to whole js folder, it'll create an infinite loop
// run jshint be compiling js code
gulp.watch(jsFiles, gulp.series("jshint", gulp.parallel("scripts")));
gulp.watch(cssFiles, gulp.parallel("sass"));
});
gulp.task("default", gulp.parallel("watch", "browser-sync"));