-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate project to Remix's Vite plugin (#81)
* Migrate from Remix compiler to Vite * Update remix-pwa stuff * Fix CSS URL imports * Fix warning about importing from /public/favicon.ico * Reorder imports * Remove @epic-web/remember * Make favicon destination directory path more clear * Write sw.js directly to build/client * Update clean script
- Loading branch information
Showing
15 changed files
with
522 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,57 @@ | ||
/// <reference lib="WebWorker" /> | ||
|
||
import { Storage } from '@remix-pwa/cache'; | ||
import { cacheFirst, networkFirst } from '@remix-pwa/strategy'; | ||
import type { DefaultFetchHandler } from '@remix-pwa/sw'; | ||
import { RemixNavigationHandler, logger, matchRequest } from '@remix-pwa/sw'; | ||
import { | ||
EnhancedCache, | ||
logger, | ||
clearUpOldCaches, | ||
NavigationHandler, | ||
} from '@remix-pwa/sw'; | ||
|
||
declare let self: ServiceWorkerGlobalScope; | ||
|
||
const PAGES = 'page-cache'; | ||
const DATA = 'data-cache'; | ||
const ASSETS = 'assets-cache'; | ||
const CURRENT_CACHE_VERSION = 'v2'; | ||
|
||
// Open the caches and wrap them in `RemixCache` instances. | ||
const dataCache = Storage.open(DATA, { | ||
ttl: 60 * 60 * 24 * 7 * 1_000, // 7 days | ||
}); | ||
const documentCache = Storage.open(PAGES); | ||
const assetCache = Storage.open(ASSETS); | ||
// const assetCache = new EnhancedCache('remix-assets', { | ||
// version: CURRENT_CACHE_VERSION, | ||
// strategy: 'CacheFirst', | ||
// strategyOptions: { | ||
// maxEntries: 2, | ||
// maxAgeSeconds: 60, | ||
// cacheableResponse: false, | ||
// }, | ||
// }); | ||
|
||
self.addEventListener('install', (event: ExtendableEvent) => { | ||
logger.log('Service worker installed'); | ||
event.waitUntil(self.skipWaiting()); | ||
}); | ||
|
||
self.addEventListener('activate', (event: ExtendableEvent) => { | ||
logger.log('Service worker activated'); | ||
event.waitUntil(self.clients.claim()); | ||
logger.log('installing service worker'); | ||
event.waitUntil( | ||
Promise.all([ | ||
self.skipWaiting(), | ||
// assetCache.preCacheUrls(['/entry.worker.css']), | ||
]), | ||
); | ||
}); | ||
|
||
const dataHandler = networkFirst({ | ||
cache: dataCache, | ||
}); | ||
|
||
const assetsHandler = cacheFirst({ | ||
cache: assetCache, | ||
cacheQueryOptions: { | ||
ignoreSearch: true, | ||
ignoreVary: true, | ||
}, | ||
}); | ||
|
||
// The default fetch event handler will be invoke if the | ||
// route is not matched by any of the worker action/loader. | ||
export const defaultFetchHandler: DefaultFetchHandler = ({ | ||
context, | ||
request, | ||
}) => { | ||
const type = matchRequest(request); | ||
|
||
if (type === 'asset') { | ||
return assetsHandler(context.event.request); | ||
} | ||
|
||
if (type === 'loader') { | ||
return dataHandler(context.event.request); | ||
} | ||
|
||
return context.fetchFromServer(); | ||
}; | ||
|
||
const handler = new RemixNavigationHandler({ | ||
dataCache, | ||
documentCache, | ||
self.addEventListener('activate', (event) => { | ||
logger.log(self.clients, 'manifest:\n', self.__workerManifest); | ||
event.waitUntil( | ||
Promise.all([ | ||
clearUpOldCaches(['remix-assets'], CURRENT_CACHE_VERSION), | ||
]).then(() => { | ||
self.clients.claim(); | ||
}), | ||
); | ||
}); | ||
|
||
self.addEventListener('message', (event) => { | ||
event.waitUntil(handler.handle(event)); | ||
new NavigationHandler({ | ||
documentCache: new EnhancedCache('remix-document', { | ||
version: CURRENT_CACHE_VERSION, | ||
strategy: 'CacheFirst', | ||
strategyOptions: { | ||
maxEntries: 10, | ||
maxAgeSeconds: 60, | ||
cacheableResponse: { | ||
statuses: [200], | ||
}, | ||
}, | ||
}), | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
import { remember } from '@epic-web/remember'; | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
export const prisma = remember('prisma', () => { | ||
const client = new PrismaClient(); | ||
client.$connect(); | ||
return client; | ||
}); | ||
export const prisma = new PrismaClient(); | ||
|
||
prisma.$connect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/// <reference types="@remix-run/dev" /> | ||
/// <reference types="vite/client" /> | ||
/// <reference types="@remix-run/node" /> |
Oops, something went wrong.