This repository has been archived by the owner on Jan 17, 2019. It is now read-only.
forked from udacity/mws-restaurant-stage-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
96 lines (83 loc) · 2.55 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 responsive = require('gulp-responsive');
const inlineCss = require('gulp-inline-style');
const cleanCss = require('gulp-clean-css');
const minifyJs = require('gulp-minify');
const concatJs = require('gulp-concat');
//const sourcemaps = require('gulp-sourcemaps');
const serve = require('gulp-serve');
gulp.task('images', function () {
return gulp.src('img/*.{jpg,png}')
.pipe(responsive({
// Resize all JPG images to three different sizes: 200, 500, and 630 pixels
'*': [{
width: 320,
rename: { suffix: '-320px' },
}, {
width: 640,
rename: { suffix: '-640px' },
}, {
// Compress, strip metadata, and rename original image
rename: { suffix: '-original' },
},
{
width: 320,
rename: { suffix: '-320px', extname:'.webp' },
}, {
width: 640,
rename: { suffix: '-640px', extname:'.webp' },
}, {
// Compress, strip metadata, and rename original image
rename: { suffix: '-original', extname:'.webp' },
}]
}, {
// Global configuration for all images
// The output quality for JPEG, WebP and TIFF output formats
quality: 70,
// Use progressive (interlace) scan for JPEG and PNG output
progressive: true,
// Strip all metadata
withMetadata: false,
}))
.pipe(gulp.dest('dist/img'));
});
gulp.task('css',['minify-css'], function() {
gulp.src('./*.html')
.pipe(inlineCss('./.tmp/'))
.pipe(gulp.dest('dist'));
})
gulp.task('minify-css', function() {
return gulp.src('./css/*.css')
.pipe(cleanCss())
.pipe(gulp.dest('./.tmp/css'));
});
gulp.task('concat-js', function() {
gulp.src(['./js/common.js','./js/dbhelper.js','./js/idb.js'])
//.pipe(sourcemaps.init())
.pipe(concatJs('common.js'))
.pipe(minifyJs())
//.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/js'))
gulp.src('./js/main.js')
.pipe(concatJs('main.js'))
.pipe(minifyJs())
.pipe(gulp.dest('dist/js'))
gulp.src('./js/restaurant_info.js')
.pipe(concatJs('restaurant_info.js'))
.pipe(minifyJs())
.pipe(gulp.dest('dist/js'))
})
gulp.task('watch', function() {
gulp.watch('js/**/*.js', ['concat-js']);
gulp.watch('css/**/*.css', ['css']);
gulp.watch('*.html', ['css']);
});
gulp.task('copy-serviceworker', function() {
gulp.src('sw.js')
.pipe(gulp.dest('dist/'));
gulp.src('manifest.json').pipe(gulp.dest('dist'));
})
gulp.task('default',['images','css','concat-js','copy-serviceworker','watch', 'serve'])
gulp.task('serve', serve({
root: ['dist']
}));