Try out next-pwa (#1056)

* try our next-pwa

* remove unregister

* skip waiting
main
Michael Fix 3 years ago committed by GitHub
parent 325189925d
commit 0e7fc9f916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,15 +1,16 @@
const bundleAnalyzer = require('@next/bundle-analyzer') const bundleAnalyzer = require('@next/bundle-analyzer')
const withOffline = require('next-offline') const withOffline = require('next-pwa')
const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true' }) const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true' })
module.exports = withBundleAnalyzer( module.exports = withBundleAnalyzer(
withOffline({ withOffline({
target: 'serverless', target: 'serverless',
dontAutoRegisterSw: true, pwa: {
// https://github.com/hanford/next-offline/blob/master/packages/now2-example/next.config.js disable: process.env.NODE_ENV !== 'production',
workboxOpts: { dest: 'public',
swDest: 'static/service-worker.js', register: false,
skipWaiting: false,
}, },
webpack: (config, options) => { webpack: (config, options) => {
config.module.rules.push({ config.module.rules.push({

@ -16,13 +16,6 @@
} }
], ],
"routes": [ "routes": [
{
"src": "^/service-worker.js$",
"dest": "/_next/static/service-worker.js",
"headers": {
"Service-Worker-Allowed": "/"
}
},
{ {
"src": "/api/image/?(?<id>[^/]*)", "src": "/api/image/?(?<id>[^/]*)",
"dest": "api/image/index.js?id=$id", "dest": "api/image/index.js?id=$id",

@ -54,7 +54,7 @@
"morphmorph": "^0.1.3", "morphmorph": "^0.1.3",
"ms": "^2.1.3", "ms": "^2.1.3",
"next": "^10.2.2", "next": "^10.2.2",
"next-offline": "^5.0.5", "next-pwa": "^3.1.0",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"react": "^17.0.2", "react": "^17.0.2",
"react-click-outside": "^3.0.0", "react-click-outside": "^3.0.0",

@ -1,7 +1,6 @@
// Theirs // Theirs
import React from 'react' import React from 'react'
import { withRouter } from 'next/router' import { withRouter } from 'next/router'
import { register, unregister } from 'next-offline/runtime'
import Either from 'eitherx' import Either from 'eitherx'
// Ours // Ours
@ -11,10 +10,14 @@ import { MetaLinks } from '../components/Meta'
class Index extends React.Component { class Index extends React.Component {
componentDidMount() { componentDidMount() {
register() window.workbox.register()
} }
componentWillUnmount() { componentWillUnmount() {
unregister() if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister()
})
}
} }
shouldComponentUpdate = () => false shouldComponentUpdate = () => false

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save