-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
43 lines (38 loc) · 1.17 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
'use strict';
const del = require('del');
const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const replace = require('gulp-replace-task')
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const fs = require('fs');
// Clean output directory
gulp.task('clean', () => del(['dist']));
// Gulp task to minify HTML files
gulp.task('html', function () {
return gulp.src(['./src/bccp.html'])
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
}))
.pipe(gulp.dest('./dist'));
});
// Gulp task to minify JavaScript files
gulp.task('script', function () {
const content = fs.readFileSync('./dist/bccp.html', 'utf8').toString();
return gulp.src('./src/bccp.js')
.pipe(sourcemaps.init())
.pipe(replace({
patterns: [{
match: '###html###',
replacement: content,
}],
usePrefix: false
}))
.pipe(sourcemaps.write())
// Minify the file
.pipe(uglify())
// Output
.pipe(gulp.dest('./dist'))
});