Repository URL to install this package:
|
Version:
1.2.9 ▾
|
/* eslint-disable */
/* prettier-ignore */
import { resolveToRoot } from '../../config/resolveToRoot'
import { Configuration, Options } from '../../typings'
/**
* @todo enable again
* @see https://github.com/oliviertassinari/serviceworker-webpack-plugin
* @see http://air.ghost.io/using-workbox-webpack-to-precache-with-service-worker/
* @see https://github.com/jeffposnick/create-react-pwa/issues/11
*
* need to add in express which means it needs to be in manifest
*/
export default function serviceWorkerPlugin(
config: Configuration,
options: Options
) {
const { isClient, isProd } = options
// only want a sw in the browser
if (isClient === false) {
return
}
if (isProd === false) {
return
}
console.warn('[bs] DISABLED SERVICE_WORKER @TODO @JAMES')
return
if (!process.env.SHOULD_USE_SERVICE_WORKER) {
return
}
const WorkboxPlugin = require('workbox-webpack-plugin')
const plugin = new WorkboxPlugin({
// !.hot
globPatterns: ['**/*.{html,js,css}'],
// @todo - this only works once output is built, annoying
// globDirectory: resolveToRoot('./dist/dist/client'),
globDirectory: resolveToRoot('./dist/dist/bundled'),
swSrc: resolveToRoot('./src/client/workers/workbox.ts'),
swDest: resolveToRoot('./dist/dist/bundled/client/workbox.js'),
})
config.plugins.push(plugin)
}