-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
68 lines (63 loc) · 1.8 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
const gulp = require('gulp');
const pug = require('gulp-pug');
const sass = require('gulp-sass')(require('sass'));
const data = require('gulp-data');
const connect = require('gulp-connect');
const sitemap = require('gulp-sitemap');
function buildScss() {
gulp.src('src/scss/**/*.scss')
.pipe(data((file) => {
console.log("[build] " + file['history']);
}))
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./static/styles'))
.pipe(connect.reload());
}
function buildPug() {
let build_time = new Date().getTime();
gulp.src('src/pug/**/index.pug')
.pipe(data((file) => {
console.log("[build] " + file['history']);
const result = {
timestamp: build_time,
index: require('./data/index.json'),
index_old: require('./data/index2020.json'),
power2020: require('./data/power2020.json'),
power2021: require('./data/power2021.json'),
power2022: require('./data/power2022.json'),
power_ai: require('./data/power_ai.json'),
ssr2021: require('./data/ssr2021.json')
};
return result;
}))
.pipe(pug())
.pipe(gulp.dest('./static/'))
.pipe(sitemap({
siteUrl: 'https://sch001.g0v.tw',
images: true
}))
.pipe(gulp.dest('./static/'))
.pipe(connect.reload());
}
gulp.task('build', async() => {
await buildScss();
await buildPug();
});
gulp.task('server', function () {
connect.server({
port: 3000,
livereload: true,
host: '::',
root: 'static'
});
buildScss();
buildPug();
gulp.watch(['src/**/*.scss'], function (cb) {
buildScss();
cb();
});
gulp.watch(['src/**/*.pug', 'src/**/*.scss', 'static/assets/js/*.js', 'data/*.json'], function (cb) {
buildPug();
cb();
});
});