-
Notifications
You must be signed in to change notification settings - Fork 43
/
gulpfile.js
74 lines (58 loc) · 1.65 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
'use strict';
const fs = require('fs');
const gulp = require('gulp');
const replace = require('gulp-replace');
const ghtmlSrc = require('gulp-html-src');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require("gulp-rename");
const cssmin = require('gulp-minify-css');
const htmlreplace = require('gulp-html-replace');
const del = require('del');
gulp.task('clean', () => del(['dist/**/*']));
gulp.task('build-js', ['clean'], () => {
let rv = gulp
.src('src/index.html')
.pipe(ghtmlSrc())
.pipe(concat('app.js'))
.pipe(gulp.dest('dist/'))
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist/'));
return rv;
});
gulp.task('build-css', ['clean'], () => {
let rv = gulp
.src('src/index.html')
.pipe(ghtmlSrc({presets: 'css'}))
.pipe(concat('app.css'))
.pipe(gulp.dest('dist/'))
.pipe(cssmin())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist/'));
return rv;
});
gulp.task('inject', ['build-js', 'build-css'], () => {
let cssFile = 'dist/app.min.css';
let jsFile = 'dist/app.min.js';
return gulp.src('src/index.html')
.pipe(htmlreplace({
'css': `<style>${fs.readFileSync(cssFile, 'utf8')}</style>`,
'js': `<script>${fs.readFileSync(jsFile, 'utf8')}</script>`
}))
.pipe(gulp.dest('./'));
});
/**
* Default `gulp` methold.
*/
gulp.task('default', [
'clean',
'build-js',
'build-css',
'inject'
]);
gulp.task('watch', () => gulp.watch('src/**/*', ['default']));