Enable offline capability of your webapp using ServiceWorker or AppCache.
This config use offline-plugin to achieve generation of ServiceWorker and AppCache files.
npm install --save-dev @easy-webpack/config-offline
easy-webpack is also required.
// webpack.config.js
const generateConfig = require('@easy-webpack/core').generateConfig;
const baseConfig = { ... }; // project-specific config like the entry file
const offlineConfig = {
caches: {
main: [':rest:'],
additional: [':externals:'],
optional: ['*.chunk.js']
},
ServiceWorker: {
events: true
},
AppCache: {
caches: ['main', 'additional', 'optional']
}
}
module.exports = generateConfig(
baseConfig,
require('@easy-webpack/config-offline')
({ options: offlineConfig })
);
// Any client JS file, typically main entry
require('offline-plugin/runtime').install();
// This config will generate a service worker and app cache config in output path
It is recommended to put config-offline
at the end of webpack config chain.
Type: Object
Default: {}
This is identical to options in offline-plugin. Please check their documentation on how to configure it.