Skip to content

Commit

Permalink
Vite Config
Browse files Browse the repository at this point in the history
Brought this over from Dovetail. Haven't gotten the TypeScript Service Worker set up properly yet. It works for vite preview, but I can't get a proxy for it to work while running the app with vite dev.
  • Loading branch information
Offroaders123 committed Jul 11, 2023
1 parent ddc5370 commit b2feb33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"private": true,
"type": "module",
"scripts": {
"build": "tsc; vite build --base ./ --target esnext",
"dev": "vite --host --port 5500 --base ./",
"preview": "vite preview --host --port 5500 --base ./"
"build": "tsc; vite build",
"dev": "vite",
"preview": "vite preview"
},
"dependencies": {
"@stedit/menu-drop": "^1.0.1",
Expand Down
14 changes: 10 additions & 4 deletions public/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

var self = /** @type { ServiceWorkerGlobalScope } */ (/** @type { unknown } */ (globalThis));

const CACHE_VERSION = "Smart Text Editor v4.23.0";
const NAME = "Smart Text Editor";
const VERSION = "v4.24.0";
const CACHE_NAME = /** @type { const } */ (`${NAME} ${VERSION}`);

const IS_MACOS_DEVICE = (/(macOS|Mac)/i.test(navigator.userAgentData?.platform ?? navigator.platform) && navigator.standalone === undefined);

Expand Down Expand Up @@ -67,7 +69,7 @@ self.addEventListener("message",async event => {
const keys = await caches.keys();

await Promise.all(keys.map(async key => {
if (key.startsWith("Smart Text Editor ")){
if (key.startsWith(NAME)){
await caches.delete(key);
}
}));
Expand All @@ -80,12 +82,14 @@ self.addEventListener("message",async event => {

/**
* Clears out old versions of the app from Cache Storage.
*
* @returns { Promise<void> }
*/
async function removeOutdatedVersions(){
const keys = await caches.keys();

await Promise.all(keys.map(async key => {
const isOutdatedVersion = key.startsWith("Smart Text Editor ") && key !== CACHE_VERSION;
const isOutdatedVersion = key.startsWith(NAME) && key !== CACHE_NAME;

if (isOutdatedVersion){
await caches.delete(key);
Expand All @@ -102,6 +106,7 @@ async function removeOutdatedVersions(){
* If it hasn't been cached yet, it will fetch the network for a response, cache a clone, then return the response.
*
* @param { Request } request
* @returns { Promise<Response> }
*/
async function matchRequest(request){
let response = await caches.match(request);
Expand All @@ -118,9 +123,10 @@ async function matchRequest(request){
*
* @param { Request } request
* @param { Response } response
* @return { Promise<void> }
*/
async function cacheRequest(request,response){
const cache = await caches.open(CACHE_VERSION);
const cache = await caches.open(CACHE_NAME);
await cache.put(request,response.clone());
}

Expand Down
16 changes: 16 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "vite";

export default defineConfig({
base: "./",
build: {
target: "esnext"
},
server: {
port: 5500,
strictPort: true
},
preview: {
port: 5500,
strictPort: true
}
});

0 comments on commit b2feb33

Please sign in to comment.