Comparing version 0.0.15 to 1.0.0
166
index.js
@@ -7,5 +7,77 @@ const path = require('path') | ||
const defaultCache = [{ | ||
urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i, | ||
handler: 'CacheFirst', | ||
options: { | ||
cacheName: 'google-fonts', | ||
expiration: { | ||
maxEntries: 4, | ||
maxAgeSeconds: 365 * 24 * 60 * 60 // 365 days | ||
} | ||
} | ||
}, { | ||
urlPattern: /^https:\/\/use\.fontawesome\.com\/releases\/.*/i, | ||
handler: 'CacheFirst', | ||
options: { | ||
cacheName: 'font-awesome', | ||
expiration: { | ||
maxEntries: 1, | ||
maxAgeSeconds: 365 * 24 * 60 * 60 // 365 days | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-font-assets', | ||
expiration: { | ||
maxEntries: 4, | ||
maxAgeSeconds: 7 * 24 * 60 * 60 // 7 days | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-image-assets', | ||
expiration: { | ||
maxEntries: 64, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:js)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-js-assets', | ||
expiration: { | ||
maxEntries: 16, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:css|less)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-style-assets', | ||
expiration: { | ||
maxEntries: 16, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}, { | ||
urlPattern: /.*/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'others', | ||
expiration: { | ||
maxEntries: 16, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}] | ||
const registerSW = (config) => { | ||
registerScript = path.join(__dirname, 'register.js') | ||
console.log(`> [PWA] use the script for register: ${path.resolve(registerSW)}`) | ||
console.log(`> [PWA] auto register service worker using: ${path.resolve(registerScript)}`) | ||
@@ -21,5 +93,2 @@ const entry = config.entry | ||
// For workbox configurations: | ||
// https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin | ||
module.exports = (nextConfig = {}) => ({ | ||
@@ -36,4 +105,6 @@ ...nextConfig, | ||
// For workbox configurations: | ||
// https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin | ||
const { | ||
disable = !options.dev, | ||
disable = options.dev, | ||
register = true, | ||
@@ -43,5 +114,7 @@ dest = distDir, | ||
scope = '/', | ||
runtimeCaching = defaultCache, | ||
...workbox | ||
} = pwa | ||
console.log(`> [PWA] compile for ${options.isServer ? 'server' : 'static (client)'}`) | ||
if (!disable) { | ||
@@ -57,7 +130,6 @@ const _sw = sw.startsWith('/') ? sw : `/${sw}` | ||
if(register) { | ||
console.log(`> [PWA] auto register service worker in main.js on ${options.isServer ? '[server]' : '[static (client)]'}`) | ||
registerSW(config) | ||
} else { | ||
console.log(`> [PWA] auto register service worker is DISABLED on ${options.isServer ? '[server]' : '[static (client)]'}`) | ||
console.log(`> [PWA] make sure to implement code to register service worker`) | ||
console.log(`> [PWA] auto register service worker is disabled`) | ||
console.log(`> [PWA] make sure to handle register service worker yourself`) | ||
} | ||
@@ -102,2 +174,6 @@ | ||
} else { | ||
if (typeof runtimeCaching === 'function') { | ||
runtimeCaching = runtimeCaching(defaultCache) | ||
} | ||
console.log('> [PWA] generating new service worker', path.join(_dest, sw)) | ||
@@ -110,73 +186,3 @@ config.plugins.push( | ||
cleanupOutdatedCaches: true, | ||
runtimeCaching: [{ | ||
urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i, | ||
handler: 'CacheFirst', | ||
options: { | ||
cacheName: 'google-fonts', | ||
expiration: { | ||
maxEntries: 4, | ||
maxAgeSeconds: 365 * 24 * 60 * 60 // 365 days | ||
} | ||
} | ||
}, { | ||
urlPattern: /^https:\/\/use\.fontawesome\.com\/releases\/.*/i, | ||
handler: 'CacheFirst', | ||
options: { | ||
cacheName: 'font-awesome', | ||
expiration: { | ||
maxEntries: 1, | ||
maxAgeSeconds: 365 * 24 * 60 * 60 // 365 days | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-font-assets', | ||
expiration: { | ||
maxEntries: 4, | ||
maxAgeSeconds: 7 * 24 * 60 * 60 // 7 days | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-image-assets', | ||
expiration: { | ||
maxEntries: 64, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:js)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-js-assets', | ||
expiration: { | ||
maxEntries: 16, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}, { | ||
urlPattern: /\.(?:css|less)$/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'static-style-assets', | ||
expiration: { | ||
maxEntries: 16, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}, { | ||
urlPattern: /.*/i, | ||
handler: 'StaleWhileRevalidate', | ||
options: { | ||
cacheName: 'others', | ||
expiration: { | ||
maxEntries: 16, | ||
maxAgeSeconds: 24 * 60 * 60 // 24 hours | ||
} | ||
} | ||
}], | ||
runtimeCaching, | ||
...workbox | ||
@@ -206,2 +212,4 @@ }) | ||
} | ||
} else { | ||
console.log('[PWA] PWA support currently disabled') | ||
} | ||
@@ -208,0 +216,0 @@ |
{ | ||
"name": "next-pwa", | ||
"version": "0.0.15", | ||
"version": "1.0.0", | ||
"description": "Next.js with PWA, powered by workbox.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
252
1
16963