-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
executable file
·212 lines (195 loc) · 5.73 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Gulp.js configuration
"use strict";
// options for src and build folders
const dir = {
src: "./assets/src/",
build: "./assets/build/",
vendor: "./assets/vendor/",
root: "./",
// Replace with URL of your local site
localDevURL: "dev-colab.test/"
},
// gulp plugins etc
gulp = require("gulp"),
gutil = require("gulp-util"),
sass = require("gulp-sass"),
cssnano = require("cssnano"),
autoprefixer = require("gulp-autoprefixer"),
sourcemaps = require("gulp-sourcemaps"),
//NOTE: commenting this out because it's whining about something or other and I don't even use this thing. its another thing from a previous dev
// jshint = require("gulp-jshint"),
// stylish = require("jshint-stylish"),
uglify = require("gulp-uglify"),
concat = require("gulp-concat"),
rename = require("gulp-rename"),
plumber = require("gulp-plumber"),
//NOTE: I have commented out bower because it's something left over from the previous dev and I don't really use the command that uses it and from what I can tell that command is better handled with npm but yeah that's it for now.
// bower = require("gulp-bower"),
babel = require("gulp-babel"),
postcss = require("gulp-postcss"),
browserSync = require("browser-sync").create();
// Browser-sync
var browsersync = false;
//- CSS
//config
var scss = {
src: dir.src + "scss/*.scss",
watch: dir.src + "scss/**/*.scss", //*/
build: dir.build + "scss/",
sassOpts: {
outputStyle: "expanded",
// imagePath : images.build,
precision: 3,
errLogToConsole: true
},
processors: [
require("postcss-assets")({
// loadPaths: ['images/'],
basePath: dir.build
}),
require("autoprefixer")(),
require("css-mqpacker"),
require("cssnano")
]
};
// SCSS processing
gulp.task(
"scss",
gulp.series(() => {
return gulp
.src(scss.src)
.pipe(sourcemaps.init())
.pipe(sass(scss.sassOpts))
.pipe(postcss(scss.processors))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(scss.build))
.pipe(
browsersync
? browsersync.reload({
stream: true
})
: gutil.noop()
);
})
);
//- Javascript
//config
var js = {
src: dir.src + "js/*.js",
watch: dir.src + "js/**/*.js",
foundation: dir.vendor + "foundation-sites/js/",
build: dir.build + "js/",
};
// concat and minify JavaScript
gulp.task(
"site-js",
gulp.series(() => {
return gulp
.src(js.src)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat("scripts.js"))
.pipe(gulp.dest(js.build))
.pipe(
rename({
suffix: ".min"
})
)
.pipe(uglify())
.pipe(sourcemaps.write(".")) // Creates sourcemap for minified JS
.pipe(gulp.dest(js.build))
.pipe(
browsersync
? browsersync.reload({
stream: true
})
: gutil.noop()
);
})
);
// concat, and minify Foundation JavaScript
gulp.task(
"foundation-js",
gulp.series(() => {
return gulp
.src([
// Foundation core - needed if you want to use any of the components below
dir.vendor + "foundation.cor*.js",
dir.vendor + "foundation.util.*.js",
// Pick the components you need in your project
dir.vendor + "foundation.abid*.js",
dir.vendor + "foundation.accordi*n.js",
dir.vendor + "foundation.accordionMen*.js",
dir.vendor + "foundation.dr*lldown.js",
dir.vendor + "foundation.drop*own.js",
dir.vendor + "foundation.dro*downMenu.js",
dir.vendor + "foundation.equ*lizer.js",
dir.vendor + "foundation.int*rchange.js",
dir.vendor + "foundation.mage*lan.js",
dir.vendor + "foundation.offca*vas.js",
dir.vendor + "foundation.orb*t.js",
dir.vendor + "foundation.res*onsiveMenu.js",
dir.vendor + "foundation.respon*iveToggle.js",
dir.vendor + "foundation.rev*al.js",
dir.vendor + "foundation.sli*er.js",
dir.vendor + "foundation.stick*.js",
dir.vendor + "foundation.t*bs.js",
dir.vendor + "foundation.t*ggler.js",
dir.vendor + "foundation.tool*ip.js"
])
.pipe(
babel({
presets: ["es2015"],
compact: true
})
)
.pipe(sourcemaps.init())
.pipe(concat("foundation.js"))
.pipe(gulp.dest("./assets/build/js"))
.pipe(
rename({
suffix: ".min"
})
)
.pipe(uglify())
.pipe(sourcemaps.write(".")) // Creates sourcemap for minified Foundation JS
.pipe(gulp.dest("./assets/build/js"));
})
);
// Browser-Sync watch files and inject changes
gulp.task(
"dev",
gulp.series(() => {
// Watch files
var files = [
"./assets/build/scss/*.css",
"./assets/build/js/*.js",
"**/*.php",
"assets/images/**/*.{png,jpg,gif,svg,webp}"
];
browserSync.init(files, {
proxy: dir.localDevURL
});
//watch scss
gulp.watch(scss.watch, gulp.series("scss"));
// watch js
gulp
.watch("./assets/src/js/*.js", gulp.series("site-js"))
.on("change", browserSync.reload);
})
);
// Watch files for changes (without Browser-Sync)
gulp.task(
"watch",
gulp.series(() => {
// Watch .scss files
gulp.watch(["./assets/src/scss/**/*.scss"], gulp.series("scss"));
// Watch site-js files
gulp.watch("./assets/src/js/*.js", gulp.series("site-js"));
})
);
// Run styles, site-js and foundation-js
gulp.task(
"default",
gulp.series("scss", "site-js", "foundation-js")
);