forked from SilverHoodCorp/polar-bookshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkbox-config.js
167 lines (116 loc) · 3.88 KB
/
workbox-config.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const fs = require('fs');
const libpath = require('path');
const globDirectory = 'dist/public';
const STATIC_FILE_EXTENSIONS = ["css", "html", "png", "svg", "ico", "woff2"];
const JAVASCRIPT_AND_STATIC_FILE_EXTENSIONS = ["js", ...STATIC_FILE_EXTENSIONS];
function recurse(dir) {
const files = fs.readdirSync(dir);
const result = [];
for (const file of files) {
const path = libpath.join(dir, file);
const stat = fs.statSync(path);
if (stat.isDirectory()) {
result.push(...recurse(path));
}
if (stat.isFile()) {
result.push(path);
}
}
return result;
}
function toExtension(path) {
if (! path) {
return undefined;
}
const matches = path.match(/\.([a-z0-9]{1,15})$/);
if (matches && matches.length === 2) {
return matches[1];
}
return undefined;
}
/**
* Return true if the path has one of the given extensions.
*/
function hasExtension(path, exts) {
const ext = toExtension(path);
if (! ext) {
return false;
}
return exts.includes(ext);
}
function stripDirPrefix(path, prefix) {
if (! prefix.endsWith(libpath.sep)) {
prefix = prefix + libpath.sep
}
if (path.startsWith(prefix)) {
return path.substring(prefix.length);
}
return path;
}
function createGlobsRecursively(path, exts) {
if (! exts) {
exts = STATIC_FILE_EXTENSIONS;
}
return recurse(libpath.join(globDirectory, path))
.filter(current => hasExtension(current, exts))
.map(current => stripDirPrefix(current, globDirectory));
}
function createPDFJSGlobs() {
return [
'pdfviewer/build/pdf.js',
'pdfviewer/build/pdf.worker.js',
'pdfviewer/web/viewer.js',
'pdfviewer/web/viewer.css',
'pdfviewer/web/index.html',
'pdfviewer/web/locale/en-US/viewer.properties',
'pdfviewer/web/locale/en-GB/viewer.properties',
...createGlobsRecursively('pdfviewer/web/images', ["png", "svg"]),
];
}
const globPatterns = [
...createGlobsRecursively('apps', STATIC_FILE_EXTENSIONS),
...createGlobsRecursively('htmlviewer', JAVASCRIPT_AND_STATIC_FILE_EXTENSIONS),
...createPDFJSGlobs(),
...createGlobsRecursively('pdfviewer-custom', JAVASCRIPT_AND_STATIC_FILE_EXTENSIONS),
...createGlobsRecursively('web/dist', JAVASCRIPT_AND_STATIC_FILE_EXTENSIONS),
...createGlobsRecursively('web/assets', JAVASCRIPT_AND_STATIC_FILE_EXTENSIONS),
'icon.ico',
'icon.png',
'icon.svg',
'index.html',
'manifest.json',
'apps/init.js',
'apps/service-worker-registration.js',
// now the custom specified resources that we need for the webapp to
// function (scripts and CSS)
'node_modules/firebase/firebase.js',
'node_modules/firebaseui/dist/firebaseui.js',
'node_modules/firebaseui/dist/firebaseui.css',
'node_modules/react-table/react-table.css',
'node_modules/bootstrap/dist/css/bootstrap.min.css',
'node_modules/bootstrap/dist/css/bootstrap-grid.min.css',
'node_modules/bootstrap/dist/css/bootstrap-reboot.min.css',
'node_modules/toastr/build/toastr.min.css',
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
'node_modules/@burtonator/react-dropdown/dist/react-dropdown.css',
'node_modules/summernote/dist/summernote-bs4.css',
];
console.log("Using static file globs: \n ", globPatterns.join("\n "));
console.log("====");
module.exports = {
globDirectory: 'dist/public',
globPatterns,
globIgnores: [],
globStrict: false,
// stripPrefix: 'dist/public',
maximumFileSizeToCacheInBytes: 15000000,
// runtimeCaching: [{
// urlPattern: /this\\.is\\.a\\.regex/,
// handler: 'networkFirst'
// }]
swDest: 'dist/public/service-worker.js',
modifyURLPrefix: {
// Remove a '/dist' prefix from the URLs:
'/dist/public': ''
}
};