-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.mjs
126 lines (111 loc) · 3.39 KB
/
gulpfile.mjs
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
import gulp from "gulp";
import concat from "gulp-concat";
import dartSass from 'sass';
import gulpSass from "gulp-sass";
import autoprefixer from "gulp-autoprefixer";
import hash from "gulp-hash";
import { deleteAsync } from "del";
import svgmin from "gulp-svgmin";
import imagemin from "gulp-imagemin";
import imageResize from "gulp-image-resize";
import uglify from "gulp-uglify";
import cssmin from "gulp-cssmin";
import changed from "gulp-changed";
// import gzip from "gulp-gzip";
const sass = gulpSass(dartSass);
// Compile SCSS files to CSS
async function scss() {
//Delete our old css files
deleteAsync(["static/css/**/*"])
//compile hashed css files
gulp.src(["static/vendor/css/**/*", "static/src/scss/main.scss"])
.pipe(sass({
outputStyle: "compressed"
}))
.pipe(autoprefixer())
.pipe(concat('main.css'))
.pipe(cssmin())
// .pipe(gzip())
.pipe(hash())
.pipe(gulp.dest("static/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/css"))
//Delete our old css files
deleteAsync(["static/demo/css/*"])
//compile hashed css files
gulp.src(["static/demo/src/css/*"])
.pipe(sass({
outputStyle: "compressed"
}))
.pipe(autoprefixer())
.pipe(cssmin())
// .pipe(gzip())
.pipe(hash())
.pipe(gulp.dest("static/demo/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/demo/css"))
}
async function img() {
gulp.src("static/src/img/previews/**/*")
.pipe(imageResize({
width: 128,
height: 128,
cover: true,
crop: true
}))
.pipe(gulp.dest("static/img/previews"))
gulp.src("static/src/img/**/*")
.pipe(changed("static/img"))
.pipe(imagemin())
// .pipe(gzip())
.pipe(gulp.dest("static/img"))
gulp.src("static/demo/src/img/**/*")
.pipe(imagemin())
// .pipe(gzip())
.pipe(gulp.dest("static/demo/img"))
}
// Hash SVG
async function svg() {
deleteAsync(["static/svg/**/*"])
gulp.src("static/src/svg/**/*")
.pipe(svgmin())
// .pipe(hash())
.pipe(gulp.dest("layouts/partials/svg"))
// .pipe(hash.manifest("hash.json"))
//.pipe(gulp.dest("data/img"))
}
// Hash javascript
async function js() {
deleteAsync(["static/js/**/*"])
gulp.src(["static/vendor/js/**/*", "static/src/js/**/*"])
.pipe(concat('main.js'))
.pipe(uglify())
// .pipe(gzip())
.pipe(hash())
.pipe(gulp.dest("static/js"))
.pipe(hash.manifest("hash.json"))
.pipe(gulp.dest("data/js"))
deleteAsync(["static/demo/js/**/*"])
gulp.src(["static/demo/src/js/**/*"])
.pipe(concat('main.js'))
.pipe(uglify())
// .pipe(gzip())
.pipe(hash())
.pipe(gulp.dest("static/demo/js"))
.pipe(hash.manifest("hash.json"))
.pipe(gulp.dest("data/demo/js"))
}
const rebuildFiles = gulp.series(scss, img, svg, js);
// Set watch as default task
const watchFiles = async function () {
gulp.watch(["static/vendor/css/**/*", "static/src/scss/**/*", "static/demo/src/css/*"], scss);
gulp.watch("static/src/img/**/*", img);
gulp.watch("static/src/svg/**/*", svg);
gulp.watch(["static/vendor/js/**/*", "static/src/js/**/*"], js);
}
export { rebuildFiles as rebuild };
export { watchFiles as default };