mirror of
https://github.com/PrismarineJS/prismarine-web-client.git
synced 2025-05-18 00:30:25 -04:00
add service worker for PWA
This commit is contained in:
parent
9b8481e4a7
commit
c40b00ab5c
4 changed files with 21 additions and 2 deletions
|
@ -14,7 +14,7 @@
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:url" content="https://webclient.prismarine.js.org" />
|
<meta property="og:url" content="https://webclient.prismarine.js.org" />
|
||||||
<meta property="og:image" content="https://webclient.prismarine.js.org/favicon.png" />
|
<meta property="og:image" content="https://webclient.prismarine.js.org/favicon.png" />
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json" crossorigin="use-credentials">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<debug-menu id="debugmenu" style="display: none;"></debug-menu>
|
<debug-menu id="debugmenu" style="display: none;"></debug-menu>
|
||||||
|
|
10
index.js
10
index.js
|
@ -18,6 +18,16 @@ const pathfinder = require('mineflayer-pathfinder')
|
||||||
const { Vec3 } = require('vec3')
|
const { Vec3 } = require('vec3')
|
||||||
global.THREE = require('three')
|
global.THREE = require('three')
|
||||||
|
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.register('/service-worker.js').then(registration => {
|
||||||
|
console.log('SW registered: ', registration)
|
||||||
|
}).catch(registrationError => {
|
||||||
|
console.log('SW registration failed: ', registrationError)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const maxPitch = 0.5 * Math.PI
|
const maxPitch = 0.5 * Math.PI
|
||||||
const minPitch = -0.5 * Math.PI
|
const minPitch = -0.5 * Math.PI
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
"webpack-cli": "^4.2.0",
|
"webpack-cli": "^4.2.0",
|
||||||
"webpack-dev-middleware": "^4.1.0",
|
"webpack-dev-middleware": "^4.1.0",
|
||||||
"webpack-dev-server": "^3.11.0",
|
"webpack-dev-server": "^3.11.0",
|
||||||
"webpack-merge": "^5.7.3"
|
"webpack-merge": "^5.7.3",
|
||||||
|
"workbox-webpack-plugin": "^6.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ const webpack = require('webpack')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const CopyPlugin = require('copy-webpack-plugin')
|
const CopyPlugin = require('copy-webpack-plugin')
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||||
|
const WorkboxPlugin = require('workbox-webpack-plugin')
|
||||||
// https://webpack.js.org/guides/production/
|
// https://webpack.js.org/guides/production/
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -57,6 +58,13 @@ const config = {
|
||||||
/prismarine-viewer[/|\\]viewer[/|\\]lib[/|\\]utils/,
|
/prismarine-viewer[/|\\]viewer[/|\\]lib[/|\\]utils/,
|
||||||
'./utils.web.js'
|
'./utils.web.js'
|
||||||
),
|
),
|
||||||
|
new WorkboxPlugin.GenerateSW({
|
||||||
|
// these options encourage the ServiceWorkers to get in there fast
|
||||||
|
// and not allow any straggling "old" SWs to hang around
|
||||||
|
clientsClaim: true,
|
||||||
|
skipWaiting: true,
|
||||||
|
include: ['index.html', 'manifest.json'] // not caching a lot as anyway this works only online
|
||||||
|
}),
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
{ from: path.join(__dirname, '/styles.css'), to: './styles.css' },
|
{ from: path.join(__dirname, '/styles.css'), to: './styles.css' },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue