-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
91 lines (76 loc) · 2.42 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
"use strict";
const { src, dest, parallel, series } = require('gulp');
const gulp = require('gulp');
const del = require('delete');
const uglify = require('gulp-uglify');
const gbabel = require('gulp-babel');
const tsc = require('gulp-typescript');
const minHtml = require('gulp-htmlmin');
const minCss = require('gulp-clean-css');
const through = require('through2');
//const sass = require('gulp-sass');
const targetFile = "public/";
const tscCompilerSettings = {
"target": 'es2020',
"module": "es2020",
"importsNotUsedAsValues": "error",
"moduleResolution": "node"
};
const htmlMinifierSettings = {
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
};
const cssMinifierSettings = {};
const minifyJSON = through.obj(function (file, enc, cb) {
try {
let jsonVal = JSON.parse(file.contents.toString(enc));
file.contents = Buffer.from(JSON.stringify(jsonVal, null, 0), enc);
cb(null, file);
} catch (error) {
cb(error, file);
}
});
function clean(cb){
del(['./public/**'], cb);
}
function ts(cb){
return src(["src/**/*.ts"],"src/").pipe(tsc(tscCompilerSettings)).pipe(uglify()).pipe(dest(targetFile));
}
function html(cb){
return src("src/**/*.html","src/").pipe(minHtml(htmlMinifierSettings)).pipe(dest(targetFile));
}
function css(cb){
return src("src/**/*.css","src/").pipe(minCss(cssMinifierSettings)).pipe(dest(targetFile));
}
function json(cb){
return src("src/**/*.json","src/").pipe( minifyJSON).pipe(dest(targetFile));
}
function js(cb){
return src(["src/**/*.js"],"src/").pipe(gbabel()).pipe(uglify()).pipe(dest(targetFile));
}
function ts_dev(cb){
return src(["src/**/*.ts"],"src/").pipe(tsc(tscCompilerSettings)).pipe(dest(targetFile));
}
function html_dev(cb){
return src("src/**/*.html","src/").pipe(dest(targetFile));
}
function css_dev(cb){
return src("src/**/*.css","src/").pipe(dest(targetFile));
}
function json_dev(cb){
return src("src/**/*.json","src/").pipe(dest(targetFile));
}
function js_dev(cb){
return src(["src/**/*.js"],"src/").pipe(gbabel()).pipe(dest(targetFile));
}
function static_files(cb){
return src(["src/**/*.png","src/**/*.jpeg","src/**/*.jpg","src/**/*.svg"],"src/").pipe(dest(targetFile));
}
const build = series( clean, parallel(html,js,ts,css,json,static_files));
const buildDev = series( clean, parallel(html_dev,js_dev,ts_dev,css_dev,json_dev,static_files));
exports.clean = clean;
exports.build = build;
exports.buildDev= buildDev;
exports.default = build;