This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
100 lines (86 loc) · 2.25 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
//===
// IMPORTS
//===
const {src, dest, parallel, series, watch} = require('gulp');
const browserSync = require('browser-sync').create();
const clean = require('gulp-clean');
const sass = require('gulp-dart-sass');
const sourcemaps = require('gulp-sourcemaps');
const gaze = require('gaze');
//===
// VARIABLES
//===
const runTimestamp = Math.round(Date.now() / 1000);
const SRC_PATH = 'assets';
const DEST_PATH = 'static';
//===
// TASKS
//===
function cleanDist() {
return src(
['static/img', 'static/css', 'static/fonts', 'static/js'],
{ allowEmpty: true }
).pipe(clean());
};
// Static server with reload
function initBrowserSync(cb) {
browserSync.init({
notify: false,
open: false,
proxy: 'django:8000'
});
return cb;
};
// Compile SASS + sourcemaps
function sassCompile() {
return src([SRC_PATH + "/sass/desktop.sass", SRC_PATH + "/sass/mobile.sass"])
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(dest(DEST_PATH + '/css/'))
.pipe(browserSync.stream());
};
// Copy images
function images() {
return src(SRC_PATH + '/img/**/*')
.pipe(dest(DEST_PATH + '/img/'))
.pipe(browserSync.stream());
};
// Copy fonts
function fonts() {
return src(SRC_PATH + "/fonts/**/*")
.pipe(dest(DEST_PATH + "/fonts/"))
.pipe(browserSync.stream());
}
// Compile JavaScript
function javascript() {
return src([SRC_PATH + '/js/*.js', SRC_PATH + '/js/**/*.js'])
.pipe(dest(DEST_PATH + '/js/'))
.pipe(browserSync.stream());
}
//===
// Tasks
//===
// Default: 'gulp'
const build = series(
cleanDist,
parallel(sassCompile, images, fonts, javascript)
);
exports.default = build;
// Dev: 'gulp dev'
exports.dev = function () {
build();
gaze([SRC_PATH + '/sass/*.sass', SRC_PATH + '/sass/**/*.sass'], function(err, watcher) {
this.on('all', sassCompile);
});
gaze([SRC_PATH + '/img/*', SRC_PATH + '/img/**/*'], function(err, watcher) {
this.on('all', images);
});
gaze([SRC_PATH + '/fonts/*', SRC_PATH + '/fonts/**/*'], function(err, watcher) {
this.on('all', fonts);
});
gaze([SRC_PATH + '/js/*.js', SRC_PATH + '/js/**/*.js'], function(err, watcher) {
this.on('all', javascript);
});
initBrowserSync();
}