Add Dynamic Support
This commit is contained in:
parent
c28d823d7c
commit
e74459ecb9
6 changed files with 60 additions and 4 deletions
|
|
@ -8,12 +8,17 @@
|
||||||
<title>Nebula</title>
|
<title>Nebula</title>
|
||||||
<script src="/uv/uv.bundle.js"></script>
|
<script src="/uv/uv.bundle.js"></script>
|
||||||
<script src="/uv/uv.config.js"></script>
|
<script src="/uv/uv.config.js"></script>
|
||||||
|
<script src="/dynamic/dynamic.worker.js"></script>
|
||||||
|
<script src="/dynamic/dynamic.config.js"></script>
|
||||||
<script>
|
<script>
|
||||||
if ("serviceWorker" in navigator) {
|
if ("serviceWorker" in navigator) {
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
navigator.serviceWorker.register("/sw.js", {
|
navigator.serviceWorker.register("/sw.js", {
|
||||||
scope: __uv$config.prefix
|
scope: __uv$config.prefix
|
||||||
});
|
});
|
||||||
|
navigator.serviceWorker.register("/dynsw.js", {
|
||||||
|
scope: '/dyn/'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@
|
||||||
"react-helmet": "^6.1.0",
|
"react-helmet": "^6.1.0",
|
||||||
"react-i18next": "^13.5.0",
|
"react-i18next": "^13.5.0",
|
||||||
"react-icons": "^4.12.0",
|
"react-icons": "^4.12.0",
|
||||||
"tsx": "^4.7.0"
|
"tsx": "^4.7.0",
|
||||||
|
"dynamic-npm": "github:notplayingallday383/dynamic-npm"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@preact/preset-vite": "^2.5.0",
|
"@preact/preset-vite": "^2.5.0",
|
||||||
|
|
|
||||||
28
public/dynamic/dynamic.config.js
Normal file
28
public/dynamic/dynamic.config.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
self.__dynamic$config = {
|
||||||
|
prefix: '/dyn/',
|
||||||
|
encoding: 'xor',
|
||||||
|
mode: 'production',
|
||||||
|
logLevel: 0,
|
||||||
|
bare: {
|
||||||
|
version: 3,
|
||||||
|
path: '/bare/',
|
||||||
|
},
|
||||||
|
tab: {
|
||||||
|
title: 'Service',
|
||||||
|
icon: null,
|
||||||
|
ua: null,
|
||||||
|
},
|
||||||
|
assets: {
|
||||||
|
prefix: '/dynamic/',
|
||||||
|
files: {
|
||||||
|
handler: 'dynamic.handler.js',
|
||||||
|
client: 'dynamic.client.js',
|
||||||
|
worker: 'dynamic.worker.js',
|
||||||
|
config: 'dynamic.config.js',
|
||||||
|
inject: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
block: [
|
||||||
|
|
||||||
|
]
|
||||||
|
};
|
||||||
19
public/dynsw.js
Normal file
19
public/dynsw.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
importScripts('/dynamic/dynamic.config.js');
|
||||||
|
importScripts('/dynamic/dynamic.worker.js');
|
||||||
|
|
||||||
|
const sw = new UVServiceWorker();
|
||||||
|
const dynamic = new Dynamic();
|
||||||
|
self.dynamic = dynamic;
|
||||||
|
self.addEventListener('fetch',
|
||||||
|
event => {
|
||||||
|
event.respondWith(
|
||||||
|
(async function() {
|
||||||
|
if (await dynamic.route(event)) {
|
||||||
|
return await dynamic.fetch(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await fetch(event.request);
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -2,6 +2,4 @@ importScripts("/uv/uv.bundle.js");
|
||||||
importScripts("/uv/uv.config.js");
|
importScripts("/uv/uv.config.js");
|
||||||
importScripts(__uv$config.sw || "/uv/uv.sw.js");
|
importScripts(__uv$config.sw || "/uv/uv.sw.js");
|
||||||
|
|
||||||
const sw = new UVServiceWorker();
|
|
||||||
|
|
||||||
self.addEventListener("fetch", (event) => event.respondWith(sw.fetch(event)));
|
self.addEventListener("fetch", (event) => event.respondWith(sw.fetch(event)));
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,21 @@ import { defineConfig } from "vite";
|
||||||
import preact from "@preact/preset-vite";
|
import preact from "@preact/preset-vite";
|
||||||
import { viteStaticCopy } from "vite-plugin-static-copy";
|
import { viteStaticCopy } from "vite-plugin-static-copy";
|
||||||
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
|
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
|
||||||
|
import { dynPath } from "dynamic-npm";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
viteStaticCopy({
|
viteStaticCopy({
|
||||||
targets: [
|
targets: [
|
||||||
{
|
{
|
||||||
// .replace fixes weird paths on Windows
|
|
||||||
src: `${uvPath}/uv.*.js`.replace(/\\/g, "/"),
|
src: `${uvPath}/uv.*.js`.replace(/\\/g, "/"),
|
||||||
dest: "uv",
|
dest: "uv",
|
||||||
overwrite: false
|
overwrite: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: `${dynPath}/dynamic.*.js`.replace(/\\/g, "/"),
|
||||||
|
dest: "dynamic",
|
||||||
|
overwrite: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue