-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
141 lines (125 loc) · 3.5 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
/**
* @name gulp-packager
* @version 1.5.0
* @release 15-07-2021
*/
const { paths } = require("./_config/paths");
const {
src,
dest,
watch,
series
} = require('gulp');
// const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const livereload = require('gulp-livereload');
const autoprefixer = require('gulp-autoprefixer');
// const sass = require('gulp-sass')(require('node-sass'));
const sass = require('gulp-sass')(require('sass'));
const cleanCss = require('gulp-clean-css');
const ts = require('gulp-typescript');
const rename = require('gulp-rename');
// const concat = require('gulp-concat');
const purgecss = require('gulp-purgecss');
const browserSync = require('browser-sync').create();
// const del = require('delete');
// const { EventEmitter } = require('events');
// const { exec } = require('child_process');
// const fs = require('fs');
// function clean(cb) {
// // body omitted
// cb();
// }
async function SCSS() {
return src(paths.cssSrc)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
overrideBrowserslist: ["defaults"]
}))
.pipe(sourcemaps.write())
.pipe(dest(paths.cssDest))
.pipe(cleanCss())
// .pipe(purgecss({
// content: [
// '*.html',
// '**/*.js'
// ]
// }))
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.cssDest))
.pipe(livereload())
.pipe(browserSync.reload({ stream: true }));
// .pipe(browserSync.stream({ match: '**/*.css' }));
}
async function typescript() {
return src(paths.tsSrc)
.pipe(ts({
target: 'ES5',
noImplicitAny: true,
}))
.pipe(dest(paths.tsDest))
.pipe(livereload());
// cb();
}
async function syncServe() {
browserSync.init({
watch: true,
server: {
baseDir: paths.root,
serveStaticOptions: {
extensions: ["html"]
}
},
// https: {
// key: "./livereload.key",
// cert: "./livereload.crt"
// },
callbacks: {
/**
* This 'ready' callback can be used
* to access the Browsersync instance
*/
// ready: function (err, bs) {
// // example of accessing URLS
// // console.log(bs.options.get('urls'));
// // example of adding a middleware at the end
// // of the stack after Browsersync is running
// bs.addMiddleware("*", function (req, res) {
// // console.log(req.url);
// res.writeHead(302, {
// location: req.url + ".html"
// });
// res.end("Redirecting!");
// });
// }
}
});
livereload.listen();
}
watch(paths.cssSrc, series(SCSS));
watch(paths.tsSrc, series(typescript));
// function streamTask() {
// return src('*.js')
// .pipe(dest('output'));
// }
// function promiseTask() {
// return Promise.resolve('the value is ignored');
// }
// function eventEmitterTask() {
// const emitter = new EventEmitter();
// // Emit has to happen async otherwise gulp isn't listening yet
// setTimeout(() => emitter.emit('finish'), 250);
// return emitter;
// }
// function childProcessTask() {
// return exec('date');
// }
// async function asyncAwaitTask() {
// const { version } = fs.readFileSync('package.json');
// console.log(version);
// await Promise.resolve('some result');
// }
// watch(['*.php', '*.html', '**/*.js', '**/*.css']).on('change', browserSync.reload);
// exports.build = series(clean, parallel(css, javascript));
exports.default = series(SCSS, typescript, syncServe);