Adds a NekR/offline-plugin serviceworker to your Razzle implementation.
yarn add razzle-plugin-offline
Edit or create razzle.config.js
in your project root.
// razzle.config.js
module.exports = {
plugins: ['offline'],
};
At the bottom of your src/client.js
add
if (process.env.NODE_ENV === 'production') {
require('razzle-plugin-offline/lib/serviceWorker')();
}
Options are optional and should be based on NekR/offline-plugin
if (process.env.NODE_ENV === 'production') {
const options = {
// my options
};
require('razzle-plugin-offline/lib/serviceWorker')(options);
}
// razzle.config.js
module.exports = {
plugins: [{
name:'offline',
options: {
autoUpdate: true
}
}],
};