1
Fork 0

Add service worker back after Esbuild switch

This commit is contained in:
viktorstrate 2021-02-25 16:38:48 +01:00
parent 38e1871415
commit f31afb8339
No known key found for this signature in database
GPG Key ID: 3F855605109C1E8A
5 changed files with 952 additions and 456 deletions

View File

@ -72,9 +72,9 @@ COPY api/data /app/data
RUN apt-get update \ RUN apt-get update \
# Required dependencies # Required dependencies
&& apt-get install -y libdlib19 \ && apt-get install -y libdlib19 ffmpeg \
# Optional dependencies # Optional dependencies
&& apt-get install -y ffmpeg darktable; exit 0 \ && apt-get install -y darktable; exit 0 \
# Cleanup # Cleanup
&& apt-get clean && rm -rf /var/lib/apt/lists/* && apt-get clean && rm -rf /var/lib/apt/lists/*

View File

@ -64,4 +64,10 @@ if (watchMode) {
}) })
} else { } else {
esbuild.buildSync(esbuildOptions) esbuild.buildSync(esbuildOptions)
require('workbox-build').generateSW({
globDirectory: 'dist/',
globPatterns: ['**/*.{png,svg,woff2,ttf,eot,woff,js,ico,html,json,css}'],
swDest: 'dist/service-worker.js',
})
} }

1371
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -55,10 +55,10 @@
"jest": "^26.6.3", "jest": "^26.6.3",
"lint-staged": "^10.5.3", "lint-staged": "^10.5.3",
"mapbox-gl": "^1.13.0", "mapbox-gl": "^1.13.0",
"parcel-plugin-sw-cache": "^0.3.1",
"prettier": "^2.2.1", "prettier": "^2.2.1",
"react-router-prop-types": "^1.0.5", "react-router-prop-types": "^1.0.5",
"react-test-renderer": "^17.0.1" "react-test-renderer": "^17.0.1",
"workbox-build": "^6.1.1"
}, },
"cache": { "cache": {
"swDest": "service-worker.js" "swDest": "service-worker.js"

View File

@ -8,33 +8,16 @@
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy. // To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior. // This link also includes instructions on opting out of this behavior.
const isLocalhost = Boolean( const isProduction = process.env.NODE_ENV === 'production'
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
)
export default function register() { export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { if (isProduction && 'serviceWorker' in navigator) {
window.addEventListener('load', () => { window.addEventListener('load', () => {
const swUrl = `/service-worker.js` const swUrl = `/service-worker.js`
if (isLocalhost) { if (!isProduction) {
// This is running on localhost. Lets check if a service worker still exists or not. // This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl) checkValidServiceWorker(swUrl)
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://goo.gl/SC7cgQ'
)
})
} else { } else {
// Is not local host. Just register service worker // Is not local host. Just register service worker
registerValidSW(swUrl) registerValidSW(swUrl)