forked from realitymod/PRGallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (84 loc) · 2.43 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
const gulp = require('gulp');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const tsify = require("tsify");
const htmlmin = require("gulp-htmlmin");
const debug = require("gulp-debug");
const server = require("gulp-live-server");
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");
const concat = require("gulp-concat");
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify-es').default;
const rename = require("gulp-rename");
const FILES_TO_COPY = [
'app/manifest.webmanifest',
'app/icon/*.*'
];
gulp.task('browserify', function() {
return browserify('app/index.ts')
.plugin(tsify)
.bundle()
.pipe(source('main.min.js'))
.pipe(buffer())
.pipe(uglify(/* options */))
.pipe(gulp.dest('dist'));
});
gulp.task('serviceworker', function() {
return browserify('app/service_worker.ts')
.plugin(tsify)
.bundle()
.pipe(source('service_worker.js'))
.pipe(buffer())
.pipe(uglify(/* options */))
.pipe(gulp.dest('dist'))
});
/*
* Minify and uglify CSS
*/
gulp.task('styles', function() {
return gulp.src([
'app/**/*.scss',
])
.pipe(debug())
.pipe(sass())
.pipe(autoprefixer())
.pipe(concat("bundle.css"))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('dist'));
});
/*
* Minify HTML
*/
gulp.task('minify', function() {
return gulp.src('app/**/*.html')
.pipe(debug())
.pipe(htmlmin({collapseWhitespace: true, removeComments:true}))
.pipe(gulp.dest('dist'));
});
/*
*
*/
gulp.task('staticfiles', function() {
return gulp.src(FILES_TO_COPY, {base: './app/'}).pipe(gulp.dest('dist'));
});
/*
*
*/
gulp.task('watch', function() {
gulp.watch('app/**/*.html', gulp.series('minify'));
gulp.watch(['app/**/*.ts', '!app/service_worker.ts'], gulp.series('browserify'));
gulp.watch('app/**/*.scss', gulp.series('styles'));
gulp.watch('app/service_worker.ts', gulp.series('serviceworker'));
gulp.watch(FILES_TO_COPY, gulp.series('staticfiles'));
});
/*
* Run Server
*/
gulp.task('webserver', gulp.series('browserify', 'minify', 'styles', 'staticfiles', 'serviceworker', function() {
server
.static('dist', 3000)
.start();
}));
gulp.task('default', gulp.parallel('webserver', 'watch'));