-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
149 lines (135 loc) · 5.34 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
const gulp = require('gulp');
const gutil = require('gulp-util');
const autoprefixer = require('gulp-autoprefixer');
const child = require('child_process');
const sass = require('gulp-sass')(require('sass'));
const hash = require("gulp-hash");
const del = require("del");
const hugo = child.spawn('hugo', ['serve', '--bind=0.0.0.0']);
var purify = require('gulp-purifycss');
let cleanCSS = require('gulp-clean-css');
gulp.task('hugo', () => {
const hugo = child.spawn('hugo', ['serve']);
const hugoLogger = (buffer) => {
buffer.toString()
.split(/\n/)
.forEach((message) => gutil.log('Hugo: ' + message))
};
hugo.stdout.on('data', hugoLogger);
hugo.stderr.on('data', hugoLogger);
});
// Compile SCSS files to CSS
gulp.task("scss-main", function () {
//del(["static/_assets/css/www/**/*"])
gulp.src("src/scss/main.scss")
//del(["static/_assets/css/*"])
.pipe(sass({outputStyle : "compressed"}))
.pipe(autoprefixer({browsers : ["last 20 versions"]}))
.pipe(purify(['static/_assets/js/**/*.js', 'layouts/**/*.html']))
.pipe(cleanCSS({debug: true}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(hash())
.pipe(gulp.dest("static/_assets/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/css"))
});
gulp.task("scss-main-addon", function () {
//del(["static/_assets/css/www/**/*"])
gulp.src("src/scss/main-addon.scss")
//del(["static/_assets/css/*"])
.pipe(sass({outputStyle : "compressed"}))
.pipe(autoprefixer({browsers : ["last 20 versions"]}))
.pipe(purify(['static/_assets/js/**/*.js', 'layouts/**/*.html']))
.pipe(cleanCSS({debug: true}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(hash())
.pipe(gulp.dest("static/_assets/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/css"))
});
gulp.task("scss-font", function () {
//del(["static/_assets/css/www/**/*"])
gulp.src("src/scss/components/font.scss")
//del(["static/_assets/css/*"])
.pipe(sass({outputStyle : "compressed"}))
.pipe(autoprefixer({browsers : ["last 20 versions"]}))
.pipe(purify(['static/_assets/js/**/*.js', 'layouts/**/*.html']))
.pipe(cleanCSS({debug: true}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(hash())
.pipe(gulp.dest("static/_assets/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/css"))
});
gulp.task("scss-bg", function () {
//del(["static/_assets/css/www/**/*"])
gulp.src("src/scss/components/bg.scss")
//del(["static/_assets/css/*"])
.pipe(sass({outputStyle : "compressed"}))
.pipe(autoprefixer({browsers : ["last 20 versions"]}))
.pipe(purify(['static/_assets/js/**/*.js', 'layouts/**/*.html']))
.pipe(cleanCSS({debug: true}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(hash())
.pipe(gulp.dest("static/_assets/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/css"))
});
gulp.task("scss-icon", function () {
//del(["static/_assets/css/www/**/*"])
gulp.src("src/scss/components/icon.scss")
//del(["static/_assets/css/*"])
.pipe(sass({outputStyle : "compressed"}))
.pipe(autoprefixer({browsers : ["last 20 versions"]}))
.pipe(purify(['static/_assets/js/**/*.js', 'layouts/**/*.html']))
.pipe(cleanCSS({debug: true}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(hash())
.pipe(gulp.dest("static/_assets/css"))
//Create a hash map
.pipe(hash.manifest("hash.json"))
//Put the map in the data directory
.pipe(gulp.dest("data/css"))
});
// Hash javascript
gulp.task("js", function () {
//del(["static/_assets/js/www/**/*"])
gulp.src(["src/js/**/*", "node_modules/bootstrap/dist/js/bootstrap.min.js"])
.pipe(hash())
.pipe(gulp.dest("static/_assets/js"))
.pipe(hash.manifest("hash.json"))
.pipe(gulp.dest("data/js"))
});
// Watch asset folder for changes
gulp.task("watch", gulp.series("js","scss-main","scss-main-addon","scss-font","scss-bg","scss-icon"), function () {
gulp.watch("src/scss/**/*", ["scss-main"])
gulp.watch("src/js/**/*", ["js"])
});
gulp.task("prefix", () => {
gulp.src('./public/**/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(gulp.dest(function (file) {
return file.base;
}))
});
gulp.task('start', gulp.series('hugo', 'watch'));