Workbox webpack Plugins
以下の2つのpluginが提供されている
generateSW plugin
使い所
precacheしたい
simpleなconfigで良い
使い所でない
Web pushなどのfeatureを使いたい
service worker内に複雑なロジックを書いたり別のscriptを読み込んだりしたい
code:js
// Inside of webpack.config.js:
const {GenerateSW} = require('workbox-webpack-plugin');
module.exports = {
// Other webpack config...
plugins: [
// Other plugins...
new GenerateSW({
option: 'value',
})
]
};
injectManifest plugin
使い所
自前で書いたservice workerのコードとWorkbox webpack Pluginが自動生成するmanifestをマージするときに使う
precacheしたい
Web pushなどのfeatureを使いたい
使い所でない
今すぐ簡単にservice workerを導入したい
code:js
// Inside of webpack.config.js:
const {InjectManifest} = require('workbox-webpack-plugin');
module.exports = {
// Other webpack config...
plugins: [
// Other plugins...
new InjectManifest({
swSrc: './src/sw.js',
})
]
};