-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
174 lines (160 loc) · 4.37 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"use strict";
let gulp = require("gulp"),
autoprefixer = require("gulp-autoprefixer"),
livereload = require("gulp-livereload"),
sass = require("gulp-sass"),
notify = require("gulp-notify"),
uglify = require("gulp-uglify"),
concat = require("gulp-concat"),
cleanCSS = require("gulp-clean-css"),
rename = require("gulp-rename"),
imagemin = require("gulp-imagemin"),
del = require("del"),
sassLint = require("gulp-sass-lint"),
newer = require("gulp-newer"),
sourcemaps = require("gulp-sourcemaps"),
babel = require("gulp-babel"),
plumber = require("gulp-plumber"),
cp = require("child_process");
/**
* Unify all scripts to work with source and destination paths.
* For more custom paths, please add them in this object
*/
const paths = {
source: {
scripts: "assets/src/scripts/",
sass: "assets/src/sass/",
images: "assets/src/images/",
fonts: "assets/src/fonts/",
},
destination: {
scripts: "assets/dist/scripts/",
css: "assets/dist/css/",
images: "assets/dist/images/",
fonts: "assets/dist/fonts/",
},
};
gulp.task("sass", function () {
return (
gulp
.src(paths.source.sass + "**/*.scss")
.pipe(
sass({
includePaths: [
"node_modules/foundation-sites/scss/",
"node_modules/@fortawesome/fontawesome-free/scss/",
],
})
)
.pipe(sourcemaps.init())
.pipe(
sassLint({
files: {
ignore: [
paths.source.sass + "/base/_normalize.scss",
paths.source.sass + "/modularscale/**/*.scss",
paths.source.sass + "/foundation/**/*.scss",
paths.source.sass + "/font-awesome/**/*.scss",
paths.source.sass + "/font-awesome/**/*.scss",
paths.source.sass + "/**/*.css",
paths.destination.css + "/**/*.css",
],
},
})
)
.pipe(sassLint.format())
// .pipe(sassLint.failOnError())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(paths.destination.css))
.pipe(
notify({
onLast: true,
title: "Sass compiled successfully.",
})
)
);
});
gulp.task("cssmin", function () {
return gulp
.src(paths.destination.css + "master.css")
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(cleanCSS({ compatibility: "ie8" }))
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(paths.destination.css))
.pipe(
notify({
message: "Successfully minified master.min.css",
onLast: true,
})
);
});
// The files to be watched for minifying. If more dev js files are added this
// will have to be updated.
gulp.task("watch", function () {
livereload.listen();
gulp.watch(paths.source.sass + "**/*.scss", gulp.series("sass"));
gulp.watch(paths.source.scripts + "**/*.js", gulp.series("minifyScripts"));
gulp.watch(paths.source.images + "*", gulp.series("optimizeImages"));
// Once the CSS file is build, minify it.
gulp.watch(paths.destination.css + "master.css", gulp.series("cssmin"));
});
gulp.task("minifyScripts", function () {
// Add separate folders if required.
return gulp
.src([
paths.source.scripts + "vendor/*.js",
paths.source.scripts + "inc/*.js",
paths.source.scripts + "scripts.js",
])
.pipe(
plumber({
handleError: function (error) {
console.log(error);
this.emit("end");
},
})
)
.pipe(
babel({
presets: ["@babel/preset-env"],
})
)
.pipe(concat("bundle.min.js"))
.pipe(uglify())
.pipe(gulp.dest(paths.destination.scripts));
});
gulp.task("optimizeImages", function () {
// Add separate folders if required.
return gulp
.src(paths.source.images + "*")
.pipe(newer(paths.destination.images))
.pipe(imagemin())
.pipe(gulp.dest(paths.destination.images));
});
gulp.task("optimizeFonts", function () {
gulp.src(paths.source.fonts + "*").pipe(gulp.dest(paths.destination.fonts));
});
// This will take care of rights permission errors if any
gulp.task("cleanup", function () {
del(paths.destination.scripts + "bundle.min.js");
del(paths.destination.css + "*.css");
});
// Will delete .git files so that you can use it on your own repository
gulp.task("reset", function () {
del(".git");
del(".DS_Store");
// @TODO: create a command that will rename all functions and comments
// to use the one the developer needs.
});
// What will be run with simply writing "$ gulp"
gulp.task(
"default",
gulp.series(
"sass",
gulp.parallel("minifyScripts", "cssmin", "optimizeImages"),
"watch"
)
);