-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
83 lines (50 loc) · 1.58 KB
/
Copy pathgulpfile.js
File metadata and controls
83 lines (50 loc) · 1.58 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
const { src, dest, task } = require('gulp');
const replace = require('gulp-replace');
/* PRE-BUILD */
/*
* Inserts the service worker into the src directory so it is included in the build.
* @param env dev|prod
* */
function insertServiceWorker(env) {
return src('./service-worker/' + env +'/firebase-messaging-sw.js')
.pipe(dest('./src'));
}
/* PRE-BUILD TASK */
task('preBuildDev', function(cb) {
insertServiceWorker('dev');
cb();
});
task('preBuildProd', function(cb) {
insertServiceWorker('prod');
cb();
});
/* POST-BUILD */
/*
* Replaces the begining of the onFetch function in the service worker in order to avoid a bug found in
* Safari/IOS.
*
* The error thrown when attempting to upload is:
* Firebase Storage: An unknown error ocurred, please check the error payload for server response.
* (storage/unknown) Multipart body does not contain 2 or 3 parts.
*
* We only saw this error in Safari/IOS, other OS/Browsers seem to be functioning normally.
* */
function removeFirebaseStorageFromSWOnFetch(env) {
return src(['./dist/gui-' + env + '/ngsw-worker.js'])
.pipe(replace(
'onFetch(event) {',
`onFetch(event) {
if (event.request.url.indexOf('firebasestorage.googleapis.com') !== -1) { return; }`
)
)
.pipe(dest('./dist/gui-' + env));
}
/* POST-BUILD TASK */
task('postBuildDev', function(cb) {
removeFirebaseStorageFromSWOnFetch('development');
cb();
});
task('postBuildProd', function(cb) {
removeFirebaseStorageFromSWOnFetch('production');
cb();
});