Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = (nextConfig = {}) => ({
// https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-webpack-plugin.GenerateSW
const {
disable = false,
enableOffline = !dev,
register = true,
dest = distDir,
sw = 'sw.js',
Expand Down Expand Up @@ -82,7 +83,7 @@ module.exports = (nextConfig = {}) => ({
})

if (!options.isServer) {
if (dev) {
if (!enableOffline) {
console.log(
'> [PWA] Build in develop mode, cache and precache are mostly disabled. This means offline support is disabled, but you can continue developing other functions in service worker.'
)
Expand Down Expand Up @@ -188,13 +189,13 @@ module.exports = (nextConfig = {}) => ({
const prefix = config.output.publicPath ? `${config.output.publicPath}static/` : 'static/'
const workboxCommon = {
swDest: path.join(_dest, sw),
additionalManifestEntries: dev ? [] : manifestEntries,
additionalManifestEntries: !enableOffline ? [] : manifestEntries,
exclude: [
({ asset, compilation }) => {
if (asset.name.match(/^(build-manifest\.json|react-loadable-manifest\.json)$/)) {
return true
}
if (dev && !asset.name.startsWith('static/runtime/')) {
if (!enableOffline && !asset.name.startsWith('static/runtime/')) {
return true
}
if (experimental.modern /* modern */) {
Expand Down Expand Up @@ -237,7 +238,7 @@ module.exports = (nextConfig = {}) => ({
})
)
} else {
if (dev) {
if (!enableOffline) {
ignoreURLParametersMatching.push(/ts/)
}

Expand All @@ -250,7 +251,7 @@ module.exports = (nextConfig = {}) => ({
ignoreURLParametersMatching,
importScripts,
...workbox,
runtimeCaching: dev
runtimeCaching: !enableOffline
? [
{
urlPattern: /.*/i,
Expand Down