-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-chunks-to-service-worker.sh
42 lines (34 loc) · 1.06 KB
/
copy-chunks-to-service-worker.sh
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
exit 1 # this script is no longer necessary when using Sapper, which auto-generates a service worker for you
entries=()
for entry in "build/static/css"/*
do
# ignore maps and other files
if [[ $entry =~ .*\.chunk\.css$ ]]
then
# remove "build" from start of path string
entries+=(" '${entry/build/}',")
fi
done
# echo $entries
for entry in "build/static/js"/*
do
# ignore maps and other files
if [[ $entry =~ .*\.chunk\.js$ ]]
then
# remove "build" from start of path string
entries+=(" '${entry/build/}',")
fi
done
# echo $entries
# empty temp file:
touch temp.service-worker.js
> temp.service-worker.js
# fill file:
printf "%s\n" "${entries[@]}" > temp.entries.txt
awk '/ \/\/ START OF AUTOMATICALLY-ENTERED LINES:/ { t=1; print; printf("\n"); system("cat temp.entries.txt"); printf("\n"); }
/ \/\/ END OF AUTOMATICALLY-ENTERED LINES/ { t=0 }
t==0 { print } ' public/my-service-worker.js > temp.service-worker.js
# replace with temp contents:
mv temp.service-worker.js public/my-service-worker.js
# cleanup:
rm temp.entries.txt