5 Star 10 Fork 7

Gitee 极速下载/polar-bookshelf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/burtonator/polar-bookshelf
克隆/下载
workbox-config.js 3.68 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin Burton 提交于 2020-11-18 13:19 . workaround for workbox caching.
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));
}
const globPatterns = [
...createGlobsRecursively('apps', STATIC_FILE_EXTENSIONS),
...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',
];
console.log("Using static file globs: \n ", globPatterns.join("\n "));
console.log("====");
// https://stackoverflow.com/questions/49482680/workbox-the-danger-of-self-skipwaiting
// https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.generateSW
module.exports = {
globDirectory: 'dist/public',
skipWaiting: true,
globPatterns,
globIgnores: [],
globStrict: false,
// stripPrefix: 'dist/public',
maximumFileSizeToCacheInBytes: 150000000,
swDest: 'dist/public/service-worker.js',
runtimeCaching: [
{
// https://js.stripe.com/v3
urlPattern: /https:\/\/js\.stripe\.com\/v3/,
handler: 'staleWhileRevalidate'
}
],
// {
// urlPattern: /.*/,
// handler: 'staleWhileRevalidate'
// },
// {
// // these URLs are immutable based on content hash as computed by
// // webpack so just use cacheFirst which only fetches them the
// // first time
// urlPattern: /https:\/\/storage.google.com\/stash/,
// handler: 'CacheFirst'
// }
// ],
// runtimeCaching: [
// {
// // these URLs are immutable based on content hash as computed by
// // webpack so just use cacheFirst which only fetches them the
// // first time
// urlPattern: /web\/dist\/images\/.*/,
// handler: 'CacheFirst'
// }
// ],
modifyURLPrefix: {
// Remove a '/dist' prefix from the URLs:
'/dist/public': ''
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/polar-bookshelf.git
git@gitee.com:mirrors/polar-bookshelf.git
mirrors
polar-bookshelf
polar-bookshelf
master

搜索帮助