actually decent service worker wip
This commit is contained in:
parent
d7894e07e9
commit
2e3e629406
1
cookbook/static/vue/manifest.json
Normal file
1
cookbook/static/vue/manifest.json
Normal file
@ -0,0 +1 @@
|
||||
{"name":"Recipes","short_name":"Recipes","theme_color":"#4DBA87","icons":[{"src":"./img/icons/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"./img/icons/android-chrome-512x512.png","sizes":"512x512","type":"image/png"},{"src":"./img/icons/android-chrome-maskable-192x192.png","sizes":"192x192","type":"image/png","purpose":"maskable"},{"src":"./img/icons/android-chrome-maskable-512x512.png","sizes":"512x512","type":"image/png","purpose":"maskable"}],"start_url":".","display":"standalone","background_color":"#000000"}
|
1
cookbook/static/vue/recipe_view.html
Normal file
1
cookbook/static/vue/recipe_view.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue App</title><link href="css/chunk-vendors.css" rel="preload" as="style"><link href="js/chunk-vendors.js" rel="preload" as="script"><link href="js/recipe_view.js" rel="preload" as="script"><link href="css/chunk-vendors.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="img/icons/favicon-16x16.png"><link rel="manifest" href="manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><meta name="apple-mobile-web-app-title" content="Recipes"><link rel="apple-touch-icon" href="img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><div id="app"></div><script src="js/chunk-vendors.js"></script></body></html>
|
1
cookbook/templates/sw.js
Normal file
1
cookbook/templates/sw.js
Normal file
File diff suppressed because one or more lines are too long
@ -100,7 +100,7 @@ urlpatterns = [
|
||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
|
||||
path('offline/', views.offline, name='view_offline'),
|
||||
path('service-worker.js', (TemplateView.as_view(template_name="service-worker.js", content_type='application/javascript', )), name='service_worker'),
|
||||
path('service-worker.js', (TemplateView.as_view(template_name="sw.js", content_type='application/javascript', )), name='service_worker'),
|
||||
|
||||
]
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
"bootstrap-vue": "^2.21.2",
|
||||
"core-js": "^3.6.5",
|
||||
"moment": "^2.29.1",
|
||||
"register-service-worker": "^1.7.1",
|
||||
"vue": "^2.6.11",
|
||||
"vue-multiselect": "^2.1.6",
|
||||
"vue-template-compiler": "^2.6.12",
|
||||
@ -20,15 +21,16 @@
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "~4.5.0",
|
||||
"@vue/cli-plugin-eslint": "~4.5.0",
|
||||
"@vue/cli-plugin-pwa": "~4.5.0",
|
||||
"@vue/cli-service": "~4.5.0",
|
||||
"@vue/compiler-sfc": "^3.0.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"eslint": "^6.7.2",
|
||||
"eslint-plugin-vue": "^7.0.0-0",
|
||||
"webpack-bundle-tracker": "0.4.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"@vue/cli-plugin-pwa/workbox-webpack-plugin": "^5.1.3"
|
||||
"webpack-bundle-tracker": "0.4.3",
|
||||
"workbox-strategies": "^6.0.2",
|
||||
"workbox-precaching": "^6.0.2",
|
||||
"workbox-routing": "^6.0.2"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
@ -50,5 +52,8 @@
|
||||
"> 1%",
|
||||
"last 2 versions",
|
||||
"not dead"
|
||||
]
|
||||
],
|
||||
"resolutions": {
|
||||
"@vue/cli-plugin-pwa/workbox-webpack-plugin": "^5.1.3"
|
||||
}
|
||||
}
|
||||
|
32
vue/src/registerServiceWorker.js
Normal file
32
vue/src/registerServiceWorker.js
Normal file
@ -0,0 +1,32 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import { register } from 'register-service-worker'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready () {
|
||||
console.log(
|
||||
'App is being served from cache by a service worker.\n' +
|
||||
'For more details, visit https://goo.gl/AFskqB'
|
||||
)
|
||||
},
|
||||
registered () {
|
||||
console.log('Service worker has been registered.')
|
||||
},
|
||||
cached () {
|
||||
console.log('Content has been cached for offline use.')
|
||||
},
|
||||
updatefound () {
|
||||
console.log('New content is downloading.')
|
||||
},
|
||||
updated () {
|
||||
console.log('New content is available; please refresh.')
|
||||
},
|
||||
offline () {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
},
|
||||
error (error) {
|
||||
console.error('Error during service worker registration:', error)
|
||||
}
|
||||
})
|
||||
}
|
39
vue/src/sw.js
Normal file
39
vue/src/sw.js
Normal file
@ -0,0 +1,39 @@
|
||||
// These JavaScript module imports need to be bundled:
|
||||
import {precacheAndRoute} from 'workbox-precaching';
|
||||
import {registerRoute} from 'workbox-routing';
|
||||
import {CacheFirst, NetworkFirst, StaleWhileRevalidate} from 'workbox-strategies';
|
||||
|
||||
precacheAndRoute(self.__WB_MANIFEST);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === 'image',
|
||||
new CacheFirst({cacheName: 'images'}),
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === 'script' || request.destination === 'style',
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: 'assets'
|
||||
})
|
||||
)
|
||||
|
||||
registerRoute(
|
||||
new RegExp('jsi18n/'),
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: 'assets'
|
||||
})
|
||||
)
|
||||
|
||||
registerRoute(
|
||||
new RegExp('api/*'),
|
||||
new NetworkFirst({
|
||||
cacheName: 'api'
|
||||
})
|
||||
)
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === 'document',
|
||||
new NetworkFirst({
|
||||
cacheName: 'html'
|
||||
})
|
||||
)
|
@ -16,6 +16,20 @@ module.exports = {
|
||||
: 'http://localhost:8080/',
|
||||
outputDir: '../cookbook/static/vue/',
|
||||
runtimeCompiler: true,
|
||||
pwa: {
|
||||
name: 'Recipes',
|
||||
themeColor: '#4DBA87',
|
||||
msTileColor: '#000000',
|
||||
appleMobileWebAppCapable: 'yes',
|
||||
appleMobileWebAppStatusBarStyle: 'black',
|
||||
|
||||
|
||||
workboxPluginMode: 'InjectManifest',
|
||||
workboxOptions: {
|
||||
swSrc: './src/sw.js',
|
||||
swDest: '../../templates/sw.js',
|
||||
}
|
||||
},
|
||||
chainWebpack: config => {
|
||||
|
||||
config.optimization.splitChunks({
|
||||
@ -29,11 +43,13 @@ module.exports = {
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
Object.keys(pages).forEach(page => {
|
||||
config.plugins.delete(`html-${page}`);
|
||||
config.plugins.delete(`preload-${page}`);
|
||||
config.plugins.delete(`prefetch-${page}`);
|
||||
})
|
||||
*/
|
||||
|
||||
config
|
||||
.plugin('BundleTracker')
|
||||
|
@ -1302,6 +1302,15 @@
|
||||
webpack "^4.0.0"
|
||||
yorkie "^2.0.0"
|
||||
|
||||
"@vue/cli-plugin-pwa@~4.5.0":
|
||||
version "4.5.10"
|
||||
resolved "https://registry.npm.taobao.org/@vue/cli-plugin-pwa/download/@vue/cli-plugin-pwa-4.5.10.tgz#e415a1ae339bf697b0656e3774dfad031c9564ed"
|
||||
integrity sha1-5BWhrjOb9pewZW43dN+tAxyVZO0=
|
||||
dependencies:
|
||||
"@vue/cli-shared-utils" "^4.5.10"
|
||||
webpack "^4.0.0"
|
||||
workbox-webpack-plugin "^4.3.1"
|
||||
|
||||
"@vue/cli-plugin-router@^4.5.10":
|
||||
version "4.5.10"
|
||||
resolved "https://registry.npm.taobao.org/@vue/cli-plugin-router/download/@vue/cli-plugin-router-4.5.10.tgz?cache=0&sync_timestamp=1609924480510&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fcli-plugin-router%2Fdownload%2F%40vue%2Fcli-plugin-router-4.5.10.tgz#546eaf6295bb125ce2365fb6db83548979776b0d"
|
||||
@ -8839,13 +8848,6 @@ workbox-cacheable-response@^5.1.4:
|
||||
dependencies:
|
||||
workbox-core "^5.1.4"
|
||||
|
||||
workbox-cacheable-response@^6.0.2:
|
||||
version "6.0.2"
|
||||
resolved "https://registry.yarnpkg.com/workbox-cacheable-response/-/workbox-cacheable-response-6.0.2.tgz#00b1133c4c846a2874f32ae14206c0636bacfd87"
|
||||
integrity sha512-OrgFiYWkmFXDIbNRYSu+fchcfoZqyJ4yZbdc8WKUjr9v/MghKHfR9u7UI077xBkjno5J3YNpbwx73/no3HkrzA==
|
||||
dependencies:
|
||||
workbox-core "^6.0.2"
|
||||
|
||||
workbox-core@^5.1.4:
|
||||
version "5.1.4"
|
||||
resolved "https://registry.yarnpkg.com/workbox-core/-/workbox-core-5.1.4.tgz#8bbfb2362ecdff30e25d123c82c79ac65d9264f4"
|
||||
@ -8863,13 +8865,6 @@ workbox-expiration@^5.1.4:
|
||||
dependencies:
|
||||
workbox-core "^5.1.4"
|
||||
|
||||
workbox-expiration@^6.0.2:
|
||||
version "6.0.2"
|
||||
resolved "https://registry.yarnpkg.com/workbox-expiration/-/workbox-expiration-6.0.2.tgz#ac01e8d17f48daa31dc0872c09ee6f4d2cf28ccb"
|
||||
integrity sha512-6+nbR18cklAdI3BPT675ytftXPwnVbXGR8mPWNWTJtl5y2urRYv56ZOJLD7FBFVkZ8EjWiRhNP/A0fkxgdKtWQ==
|
||||
dependencies:
|
||||
workbox-core "^6.0.2"
|
||||
|
||||
workbox-google-analytics@^5.1.4:
|
||||
version "5.1.4"
|
||||
resolved "https://registry.yarnpkg.com/workbox-google-analytics/-/workbox-google-analytics-5.1.4.tgz#b3376806b1ac7d7df8418304d379707195fa8517"
|
||||
@ -8894,6 +8889,15 @@ workbox-precaching@^5.1.4:
|
||||
dependencies:
|
||||
workbox-core "^5.1.4"
|
||||
|
||||
workbox-precaching@^6.0.2:
|
||||
version "6.0.2"
|
||||
resolved "https://registry.yarnpkg.com/workbox-precaching/-/workbox-precaching-6.0.2.tgz#cb45f290b0604bef1d9fc96bf42df82385d54e54"
|
||||
integrity sha512-sqKWL2emzmGnfJpna+9RjUkUiqQO++AKfwljCbgkHg8wBbVLy/rnui3eelKgAI7D8R31LJFfiZkY/kXmwkjtlQ==
|
||||
dependencies:
|
||||
workbox-core "^6.0.2"
|
||||
workbox-routing "^6.0.2"
|
||||
workbox-strategies "^6.0.2"
|
||||
|
||||
workbox-range-requests@^5.1.4:
|
||||
version "5.1.4"
|
||||
resolved "https://registry.yarnpkg.com/workbox-range-requests/-/workbox-range-requests-5.1.4.tgz#7066a12c121df65bf76fdf2b0868016aa2bab859"
|
||||
@ -8943,7 +8947,7 @@ workbox-sw@^5.1.4:
|
||||
resolved "https://registry.yarnpkg.com/workbox-sw/-/workbox-sw-5.1.4.tgz#2bb34c9f7381f90d84cef644816d45150011d3db"
|
||||
integrity sha512-9xKnKw95aXwSNc8kk8gki4HU0g0W6KXu+xks7wFuC7h0sembFnTrKtckqZxbSod41TDaGh+gWUA5IRXrL0ECRA==
|
||||
|
||||
workbox-webpack-plugin@^5.1.3:
|
||||
workbox-webpack-plugin@^4.3.1, workbox-webpack-plugin@^5.1.3:
|
||||
version "5.1.4"
|
||||
resolved "https://registry.yarnpkg.com/workbox-webpack-plugin/-/workbox-webpack-plugin-5.1.4.tgz#7bfe8c16e40fe9ed8937080ac7ae9c8bde01e79c"
|
||||
integrity sha512-PZafF4HpugZndqISi3rZ4ZK4A4DxO8rAqt2FwRptgsDx7NF8TVKP86/huHquUsRjMGQllsNdn4FNl8CD/UvKmQ==
|
||||
|
Loading…
Reference in New Issue
Block a user