-
Notifications
You must be signed in to change notification settings - Fork 28
/
gulpfile.js
74 lines (64 loc) · 2 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
// Build step, just type:
// gulp
//
// Prereqs:
// 1) Install Node and NPM from https://nodejs.org
// Known to work with Node 4.2.6 and NPM 2.14.12
// 2) Install dependencies from package.json
// npm install
//
// The purpose of this build step is just to crush the output filesize. Everything should work
// when loaded directly out of the root directory without running this build step.
var gulp = require('gulp');
var del = require('del');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var inlineSource = require('gulp-inline-source');
var htmlmin = require('gulp-htmlmin');
var uglify = require('gulp-uglify');
var outDir = 'out/';
var paths = {
html: ['index.html'],
images: ['images/*.png'],
extras: ['manifest.json', 'favicon.ico'],
scripts: ['simple-offline-service-worker.js']
};
gulp.task('clean', function() {
return del(outDir);
});
// Optimize and copy images
gulp.task('images', ['clean'], function() {
var imageminOptions = {
use: [pngquant({quality: '65-80', speed: 1})]
};
return gulp.src(paths.images)
.pipe(imagemin(imageminOptions))
.pipe(gulp.dest(outDir + 'images/'));
});
gulp.task('minifyHtmlCssJs', ['clean'], function() {
var inlineSourceOptions = {
compress: false
};
var htmlminOptions = {
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
preserveLineBreaks: true,
removeComments: true
};
return gulp.src(paths.html)
.pipe(inlineSource(inlineSourceOptions))
.pipe(htmlmin(htmlminOptions))
.pipe(gulp.dest(outDir));
});
gulp.task('minifyExternalScripts', ['clean'], function() {
return gulp.src(paths.scripts)
.pipe(uglify())
.pipe(gulp.dest(outDir));
});
gulp.task('copy', ['clean'], function() {
// Copy extras
gulp.src(paths.extras)
.pipe(gulp.dest(outDir));
});
gulp.task('default', ['clean', 'copy', 'images', 'minifyHtmlCssJs', 'minifyExternalScripts']);