Skip to content

Commit

Permalink
feat: add offline mode (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts committed Dec 8, 2019
1 parent e2fea88 commit 34fb324
Show file tree
Hide file tree
Showing 4 changed files with 556 additions and 13 deletions.
26 changes: 24 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

const withOffline = require('next-offline')
const merge = require('webpack-merge')

const nextConfig = {
Expand Down Expand Up @@ -36,7 +37,28 @@ const nextConfig = {
}
]
}
})
}),
workboxOpts: {
clientsClaim: true,
manifestTransforms: [
originalManifest => {
const warnings = []

const manifest = originalManifest
.map(entry => {
if (/\/pages\/(?!_).+\.js$/.test(entry.url)) return null
if (/\.jpe?g$/i.test(entry.url)) return null

return entry
})
.filter(Boolean)

return { manifest, warnings }
}
],
skipWaiting: true,
swDest: 'static/service-worker.js'
}
}

module.exports = nextConfig
module.exports = withOffline(nextConfig)
8 changes: 8 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
"cache-control": "immutable, max-age=31536000"
},
"src": "/_next/.+"
},
{
"dest": "/_next/static/service-worker.js",
"headers": {
"cache-control": "max-age=0",
"service-Worker-allowed": "/"
},
"src": "/service-worker\\.js"
}
],
"scope": "inabagumi",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@next/plugin-material-ui": "^9.1.4",
"clsx": "^1.0.4",
"next": "^9.1.4",
"next-offline": "^5.0.0-beta.11",
"nprogress": "^0.2.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
Expand Down
Loading

0 comments on commit 34fb324

Please sign in to comment.