forked from undercode99/jakarta-lte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (114 loc) · 3.1 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
const fs = require("fs");
const gulp = require("gulp");
const browserSync = require("browser-sync").create();
const sass = require("gulp-sass");
const cleanCSS = require("gulp-clean-css");
const rename = require("gulp-rename");
const ejs = require("gulp-ejs");
const uglify = require("gulp-uglify");
const npmDist = require("gulp-npm-dist");
const postcss = require("gulp-postcss");
const { copyLibs } = require("gulp-copy-libs");
const YAML = require("yaml");
const prettier = require("gulp-prettier");
// Compile src sass
gulp.task("compile:sass", function () {
return gulp
.src("src/scss/*.scss")
.pipe(postcss([require("tailwindcss"), require("autoprefixer")]))
.pipe(sass({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(gulp.dest("./dist/css"))
.pipe(cleanCSS())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("./dist/css"))
.pipe(browserSync.stream());
});
// Compile src js
gulp.task("compile:js", function () {
return gulp
.src("src/js/**/*.js")
.pipe(gulp.dest("dist/js/"))
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("dist/js/"))
.pipe(browserSync.stream());
});
// Copy libs from node modules
gulp.task("copy:libs", function () {
const libsConfig = [
{
outputDirectory: "dist/libs/boxicons/css",
inputFiles: "node_modules/boxicons/css/*.css",
},
{
outputDirectory: "dist/libs/boxicons/fonts",
inputFiles: "node_modules/boxicons/fonts/*.{eot,svg,ttf,woff,woff2}",
},
];
return (
gulp
.src(npmDist(), { base: "./node_modules" })
.pipe(
rename(function (path) {
// Remove dist dir
path.dirname = path.dirname
.replace(/\/dist/, "")
.replace(/\\dist/, "");
})
)
.pipe(gulp.dest("./dist/libs"))
// Copy custom libs
.pipe(copyLibs(libsConfig))
);
});
// build html
gulp.task("ejs_compile:html", function () {
const file = fs.readFileSync("./config-template.yml", "utf8");
const data_content = YAML.parse(file);
function menu_builder(x) {
return x;
}
let func_helper = {
menu_builder,
};
return gulp
.src("./src/templates/*.ejs")
.pipe(ejs({ ...data_content, ...func_helper }))
.pipe(rename({ extname: ".html" }))
.pipe(gulp.dest("./pages"));
});
// Beauty html
gulp.task("prettier:html", function () {
return gulp
.src("./pages/**/*.html")
.pipe(prettier({}))
.pipe(gulp.dest("./pages"));
});
// task build
gulp.task(
"build",
gulp.series(
"copy:libs",
"compile:sass",
"compile:js",
"ejs_compile:html",
"prettier:html"
)
);
// task serve browser sync
gulp.task(
"serve",
gulp.series("build", function () {
browserSync.init({ server: "." });
gulp.watch("./src/js/**/*.js", gulp.series("compile:js"));
gulp.watch("./src/scss/**/*.scss", gulp.series("compile:sass"));
gulp
.watch(
["./src/templates/**/*.ejs"],
gulp.series(["ejs_compile:html", "prettier:html"])
)
.on("change", browserSync.reload);
})
);
// default gulp command
gulp.task("default", gulp.series("serve"));