-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGulpfile.js
More file actions
87 lines (77 loc) · 2.29 KB
/
Copy pathGulpfile.js
File metadata and controls
87 lines (77 loc) · 2.29 KB
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
var gulp = require('gulp');
var sass = require('gulp-sass');
var svgSymbols = require('gulp-svg-symbols');
var htmlmin = require('gulp-htmlmin');
var svgo = require('gulp-svgo');
var gls = require('gulp-live-server');
var purge = require('gulp-css-purge');
var uncache = require('gulp-uncache');
const workboxBuild = require('workbox-build');
gulp.task('imgs', function () {
return gulp.src('src/img/*.svg')
.pipe(svgo())
.pipe(gulp.dest('dist/img/'));
});
gulp.task('sw', () => {
return workboxBuild.generateSW({
skipWaiting: true,
clientsClaim: true,
swDest: 'dist/sw.js',
globDirectory: 'dist',
globPatterns: ['**\/*.{js,css,html,png,svg,json}'],
runtimeCaching: [
{
urlPattern: /^https:\/\/code\.getmdl\.io/,
handler: 'staleWhileRevalidate'
},
{
urlPattern: /^https:\/\/fonts\.googleapis\.com/,
handler: 'staleWhileRevalidate'
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com/,
handler: 'staleWhileRevalidate'
}
]
});
});
gulp.task('js', function () {
return gulp.src('./src/js/*.js')
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('static', function () {
return gulp.src('./src/static/*')
.pipe(gulp.dest('./dist/'));
});
gulp.task('sass', function () {
return gulp.src('./src/sass/*.scss')
.pipe(sass({ style: 'compressed' }).on('error', sass.logError))
.pipe(purge({
shorten : false,
shorten_zero : false,
shorten_hexcolor_extended_names: true,
shorten_font: true,
shorten_background: true,
shorten_background_min: 2,
shorten_margin: true,
shorten_padding: true,
shorten_list_style: true,
}))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(uncache())
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['imgs','sass','html', 'js', 'static', 'sw']);
gulp.task('dev', ['default'], function(){
var server = gls.static('dist');
server.start();
gulp.watch('./src/index.html', ['html','sw']);
gulp.watch('./src/img/*.svg', ['imgs','sw']);
gulp.watch('./src/sass/*.scss', ['sass','sw']);
gulp.watch('./src/js/*.js', ['js','sw']);
gulp.watch('./src/static/*', ['static','sw']);
});