next-workbox-webpack-plugin
Webpack plugin with workbox, it helps you build a Progressive Web App powered by Next.js. Generating service worker scripts and precache manifest of Next.js's pages and chunks.
Install
$ npm install -d next-workbox-webpack-plugin
Usage
const nextWorkboxWebpackPlugin = ; ;
Usage in next.config.js
const NextWorkboxWebpackPlugin = require('next-workbox-webpack-plugin');
module.exports = {
webpack: (config, {isServer, dev, buildId, config: {distDir}}) => {
if (!isServer && !dev) {
config.plugins.push(new NextWorkboxWebpackPlugin({
distDir,
buildId
}))
}
return config
}
}
How it works
Custom Server
- Only works in
NOT dev mode
. You can't test withnext
andnext start
- To serve
sw.js
, you need custom server with custom route. See test server is in this package. - You have to add script of registering service worker into part of your application
- All of files will be generated under
/static/workbox
because of exporting. You might need to add the path to gitignore.
static/workbox
├── next-precache-manifest-d42167a04499e1887dad3156b93e064d.js
├── sw.js
└── workbox-v3.0.0-beta.0
├── workbox-background-sync.dev.js
├── ...
├── workbox-sw.js
- For more information, please refer to test and Get Started With Workbox For Webpack
Now 2.0
[TBD]
Examples
- Hello PWA: You can learn how to use the webpack plugin basically
- HNPWA: Simple HNPWA apps with Next.js
License
MIT © Jimmy Moon