Last active
July 15, 2018 18:17
-
-
Save drenther/e0be2a16fd83489ea966eaa1e65953ba to your computer and use it in GitHub Desktop.
next.config.js with webpack-pwa-manifest added
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withCSS = require('@zeit/next-css'); | |
const NextWorkboxPlugin = require('next-workbox-webpack-plugin'); | |
const WebpackPwaManifest = require('webpack-pwa-manifest'); | |
const path = require('path'); | |
module.exports = withCSS({ | |
webpack(config, { isServer, buildId, dev }) { | |
const workboxOptions = { | |
clientsClaim: true, | |
skipWaiting: true, | |
globPatterns: ['.next/static/*', '.next/static/commons/*'], | |
modifyUrlPrefix: { | |
'.next': '/_next', | |
}, | |
runtimeCaching: [ | |
{ | |
urlPattern: '/', | |
handler: 'networkFirst', | |
options: { | |
cacheName: 'html-cache', | |
}, | |
}, | |
{ | |
urlPattern: /[^3]\/movie\//, | |
handler: 'networkFirst', | |
options: { | |
cacheName: 'html-cache', | |
}, | |
}, | |
{ | |
urlPattern: new RegExp('^https://api.themoviedb.org/3/movie'), | |
handler: 'staleWhileRevalidate', | |
options: { | |
cacheName: 'api-cache', | |
cacheableResponse: { | |
statuses: [200], | |
}, | |
}, | |
}, | |
{ | |
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif)/, | |
handler: 'cacheFirst', | |
options: { | |
cacheName: 'image-cache', | |
cacheableResponse: { | |
statuses: [0, 200], | |
}, | |
}, | |
}, | |
], | |
}; | |
if (!isServer && !dev) { | |
config.plugins.push( | |
new NextWorkboxPlugin({ | |
buildId, | |
...workboxOptions, | |
}), | |
new WebpackPwaManifest({ | |
filename: 'static/manifest.json', | |
name: 'Next PWA', | |
short_name: 'Next-PWA', | |
description: 'A Movie browsing PWA using Next.js and Google Workbox', | |
background_color: '#ffffff', | |
theme_color: '#5755d9', | |
display: 'standalone', | |
orientation: 'portrait', | |
fingerprints: false, | |
inject: false, | |
start_url: '/', | |
ios: { | |
'apple-mobile-web-app-title': 'Next-PWA', | |
'apple-mobile-web-app-status-bar-style': '#5755d9', | |
}, | |
icons: [ | |
{ | |
src: path.resolve('static/favicon.ico'), | |
sizes: [96, 128, 192, 256, 384, 512], | |
destination: '/static', | |
}, | |
], | |
includeDirectory: true, | |
publicPath: '..', | |
}) | |
); | |
} | |
return config; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment