-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
51 lines (47 loc) · 1.3 KB
/
gulpfile.js
File metadata and controls
51 lines (47 loc) · 1.3 KB
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
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const minifyCss = require('gulp-clean-css');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const { inlineSource } = require('inline-source');
const through = require('through2');
const fs = require('fs');
const path = require('path');
gulp.task('js', function () {
return gulp
.src('./src/analytics.js')
.pipe(concat('scripts.js'))
.pipe(
babel({
presets: ['@babel/env'],
})
)
.pipe(gulp.dest('./src/dist'));
});
gulp.task('inline', async function () {
return gulp
.src('./src/index.html')
.pipe(
through.obj(async function (file, enc, cb) {
try {
const html = file.contents.toString();
const dir = path.dirname(file.path);
const inlined = await inlineSource(html, {
rootpath: dir,
compress: true,
svgAsImage: false,
});
file.contents = Buffer.from(inlined);
cb(null, file);
} catch (err) {
cb(err);
}
})
)
.pipe(gulp.dest('./'));
});
gulp.task('watch', function () {
gulp.watch(['src/dist/*', 'src/*'], gulp.series('build'));
});
gulp.task('build', gulp.series('js', 'inline'));
gulp.task('default', gulp.series('build'));