-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
237 lines (224 loc) · 4.86 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
*
* Gulp Plugins
*
*/
const gulp = require("gulp");
const plugins = require("gulp-load-plugins")({
pattern: ["gulp-*", "gulp.*", "del", "fs"]
});
const env = require("dotenv").config();
const sass = require('gulp-sass')(require('sass'));
const browserSync = require("browser-sync");
const server = browserSync.create();
const path = {
dist: "./dist",
css: {
src: "./resources/scss",
dest: "./dist/css"
},
fonts: {
src: "./resources/fonts",
dest: "./dist/fonts"
},
js: {
src: "./resources/js",
dest: "./dist/js"
},
img: {
src: "./resources/img",
dest: "./dist/img"
},
php: {
src: "./resources/views"
}
};
/**
*
* Task: Browser Sync
*
* - Watch for file changes in dist folder
* - Watch for a php file change
* - Update browsers
*
*/
function reload(done) {
server.reload();
done();
}
exports.reload = reload;
function sync(done) {
done();
server.init({
proxy: process.env.HOST,
notify: false,
files: [
`${path.css.dest}/app.css`,
`${path.js.dest}/app.js`,
`${path.img.dest}/**.*`
]
});
}
exports.sync = sync;
/**
*
* Task: Styles
*
* - Sourcemap
* - Combine
* - Concat
* - Minify
* - Sync browsers
*
*/
function css() {
return gulp
.src([`${path.css.src}/app.scss`, `${path.css.src}/editor-styles.scss`, `${path.css.src}/login.scss`])
.pipe(plugins.sassGlob())
.pipe(sass())
.pipe(plugins.postcss([
require('postcss-custom-media'),
require('postcss-easing-gradients'),
require('autoprefixer'),
require('cssnano')
]))
.pipe(gulp.dest(path.css.dest))
.pipe(browserSync.stream());
}
exports.css = css;
function cssDev() {
return gulp
.src([`${path.css.src}/app.scss`, `${path.css.src}/editor-styles.scss`, `${path.css.src}/login.scss`])
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sassGlob())
.pipe(sass())
.pipe(plugins.postcss([
require('postcss-custom-media'),
require('postcss-easing-gradients'),
require('autoprefixer'),
require('cssnano')
]))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(path.css.dest))
.pipe(browserSync.stream());
}
exports.css = cssDev;
/**
*
* Task: Scripts
*
* - Sourcemap
* - Modernizr
* - Combine
* - Concat
* - Minify
* - Sync browsers
*
*/
function js() {
return gulp
.src(`${path.js.src}/*.js`)
.pipe(
plugins.babel({
presets: ["@babel/preset-env"]
})
)
.pipe(plugins.terser())
.pipe(gulp.dest(path.js.dest));
}
exports.js = js;
/**
*
* Task: Images
*
* - Get gif, jpg and png files and optimize them
*
*/
function img() {
return gulp
.src([
`${path.img.src}/**/*.png`,
`${path.img.src}/**/*.gif`,
`${path.img.src}/**/*.jpg`,
`${path.img.src}/**/*.jpeg`,
`${path.img.src}/**/*.svg`
])
.pipe(plugins.image())
.pipe(gulp.dest(path.img.dest))
.pipe(browserSync.stream());
}
exports.img = img;
/**
*
* Task: Fonts
*
*/
function localFonts() {
return gulp
.src([
`${path.fonts.src}/**/*.eot`,
`${path.fonts.src}/**/*.otf`,
`${path.fonts.src}/**/*.ttf`,
`${path.fonts.src}/**/*.woff`,
`${path.fonts.src}/**/*.woff2`
])
.pipe(gulp.dest(path.fonts.dest))
.pipe(browserSync.stream());
}
exports.localFonts = localFonts;
/**
*
* Task: Google Fonts
*
*/
function googleFonts() {
return gulp
.src("./fonts.list")
.pipe(plugins.googleWebfonts({}))
.pipe(gulp.dest(path.fonts.dest));
}
exports.googleFonts = googleFonts;
/**
*
* Task: Clean
*
* - Delete dist folder
*
*/
function clean() {
return plugins.del([`${path.dist}/**`]);
}
exports.clean = clean;
/**
*
* Task: Watch
*
* - Watch file changes and start corresponding tasks
*
*/
// Watch files
function watchFiles() {
gulp.watch(`${path.css.src}/**/*.scss`, cssDev);
gulp.watch(`${path.js.src}/**/*.js`, js);
gulp.watch(`${path.img.src}/**/*.*`, img);
gulp.watch(`${path.fonts.src}/**/*.*`, localFonts);
gulp.watch("fonts.list", googleFonts);
}
exports.watchFiles = watchFiles;
// Complex tasks
const fonts = gulp.parallel(localFonts, googleFonts);
const build = gulp.series(
clean,
gulp.parallel(css, img, js, googleFonts, localFonts)
);
const buildDev = gulp.series(
clean,
gulp.parallel(cssDev, img, js, googleFonts, localFonts)
);
const watch = gulp.parallel(watchFiles, sync);
const dev = gulp.series(buildDev, watch);
// Export tasks
exports.build = build;
exports.default = dev;
exports.fonts = fonts;
exports.watch = watch;