-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (85 loc) · 2.38 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
// gulp v4.0.2
const gulp = require("gulp"),
fs = require("fs"),
ejs = require("gulp-ejs"),
data = require("gulp-data"),
rename = require("gulp-rename"),
sass = require("gulp-sass"),
uglify = require("gulp-uglify"),
cleanCSS = require("gulp-clean-css"),
plumber = require("gulp-plumber"),
browser = require("browser-sync")
mmq = require("gulp-merge-media-queries");
const cleanCSS_1stSettings =
{ // ref: https://outcloud.blogspot.com/2018/09/Minify-CSS-by-CleanCSS-MergeMediaQuery.html
level: {
1: {
roundingPrecision : 3
},
2: {
removeDuplicateFontRules: true,
removeDuplicateMediaBlocks: true,
removeDuplicateRules: true,
mergeSemantically: true,
removeUnusedAtRules: true,
restructureRules: true
}
}
};
const cleanCSS_2ndSettings =
{
level: {
1: {
all: false,
removeWhitespace: true
}
}
};
gulp.task("server", function(done) {
browser.init({
server: {
baseDir: "./docs",
startPath: '/',
routes : {
'/': 'docs'
}
}
});
done();
});
gulp.task("ejs", function() {
var json = JSON.parse(fs.readFileSync("./source/html/variables.json"));
return gulp.src(["./source/html/**/*.ejs", "!./source/html/template/*.ejs"], { base: "./source/html" })
.pipe(plumber())
.pipe(data(file => {
return {
'filename': file.path
}
}))
.pipe(ejs(json))
.pipe(rename({extname:'.html'}))
.pipe(gulp.dest("./docs"));
});
gulp.task("sass", function() {
return gulp.src("./source/sass/**/*scss")
.pipe(plumber())
.pipe(sass())
.pipe(cleanCSS(cleanCSS_1stSettings))
.pipe(mmq())
.pipe(cleanCSS(cleanCSS_2ndSettings))
.pipe(gulp.dest("./docs/css/"));
});
gulp.task("js", function() {
return gulp.src("./source/js/**/*.js")
.pipe(uglify())
.pipe(gulp.dest("./docs/js/"));
});
// watch
gulp.task("watch", (done) => {
gulp.watch("./source/html/**/*.ejs", gulp.series("ejs"));
gulp.watch("./source/js/**/*.js", gulp.series("js"));
gulp.watch("./source/sass/**/*.scss", gulp.series("sass"));
done();
});
// scripts tasks
gulp.task('default', gulp.series('watch', 'server'));