Commit bf8f584b authored by Genar Trias Ortiz's avatar Genar Trias Ortiz 🎉

generating custom service worker

parent 6f7f1265
Pipeline #56956686 failed with stages
in 5 minutes and 54 seconds
......@@ -9,7 +9,7 @@ const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const getClientEnvironment = require('./env');
const paths = require('./paths');
const { GenerateSW } = require('workbox-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
......@@ -236,18 +236,9 @@ module.exports = {
new InterpolateHtmlPlugin(env.raw),
// Generate a service worker script that will precache, and keep up to date,
// the HTML & assets that are part of the Webpack build.
new GenerateSW({
// Config options, if needed.
// For unknown URLs, fallback to the index page
navigateFallback: publicUrl + '/index.html',
// Ignores URLs starting from /__ (useful for Firebase):
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
navigateFallbackWhitelist: [/^(?!\/__).*/],
swDest: path.join('build', 'service-worker.js'),
runtimeCaching: [{
urlPattern: "(.*)",
handler: "StaleWhileRevalidate"
}]
new InjectManifest({
swSrc: path.join('src', 'service-worker.js'),
swDest: path.join('service-worker.js')
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
......
......@@ -5,7 +5,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const { GenerateSW } = require('workbox-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const paths = require('./paths');
......@@ -283,18 +283,9 @@ module.exports = {
}),
// Generate a service worker script that will precache, and keep up to date,
// the HTML & assets that are part of the Webpack build.
new GenerateSW({
// Config options, if needed.
// For unknown URLs, fallback to the index page
navigateFallback: publicUrl + '/index.html',
// Ignores URLs starting from /__ (useful for Firebase):
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
navigateFallbackWhitelist: [/^(?!\/__).*/],
swDest: path.join('service-worker.js'),
runtimeCaching: [{
urlPattern: "(.*)",
handler: "StaleWhileRevalidate"
}]
new InjectManifest({
swSrc: path.join('src', 'service-worker.ts'),
swDest: path.join('service-worker.js')
}),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
......
// Loading precache
workbox.precaching.precacheAndRoute(self.__precacheManifest);
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg)$/,
new workbox.strategies.CacheFirst({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
],
})
);
/* workbox.routing.registerRoute(
// Custom `matchCallback` function
({event}) => event.request.destination === 'audio',
new workbox.strategies.CacheFirst({
cacheName: 'audio',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
],
})
) */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment