From 337edff013b195338cba00f86f350da2d979d3b5 Mon Sep 17 00:00:00 2001 From: Giacomo Rebonato Date: Wed, 28 Jun 2023 14:12:34 +0100 Subject: [PATCH] try new sw --- server/plugins/vite-plugin.ts | 26 ++++++++++++++++++++------ vite.config.ts | 8 +++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/server/plugins/vite-plugin.ts b/server/plugins/vite-plugin.ts index efa191a..662827b 100644 --- a/server/plugins/vite-plugin.ts +++ b/server/plugins/vite-plugin.ts @@ -21,17 +21,31 @@ export const vitePlugin = async ( if (env.NODE_ENV === 'production') { const root = Path.join(appRoot.path, 'dist', 'assets') - await app.register(import('@fastify/static'), { - root, - prefix: '/assets/', + app.get('/index.html', (request, reply) => { + reply.type('text/html').send(htmlFile) }) - app.get('/manifest.webmanifest', (request, reply) => { - reply.sendFile('manifest.webmanifest', Path.join(appRoot.path, 'dist')) + app.get('/manifest*', (request, reply) => { + const urlParts = request.url.split('/') + const lastPart = urlParts[1] + + reply.sendFile(lastPart, Path.join(appRoot.path, 'dist')) }) app.get('/sw.js', (request, reply) => { - reply.sendFile('sw.js', Path.join(appRoot.path, 'dist')) + reply.sendFile('sw.js', root) + }) + + app.get('/workbox*', (request, reply) => { + const urlParts = request.url.split('/') + const lastPart = urlParts[1] + + reply.sendFile(lastPart, root) + }) + + await app.register(import('@fastify/static'), { + root, + prefix: '/assets/', }) app.get('*', async (request, reply) => { diff --git a/vite.config.ts b/vite.config.ts index 81c676e..82d4019 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,5 +4,11 @@ import { VitePWA } from 'vite-plugin-pwa' import { defineConfig } from 'vite' export default defineConfig({ - plugins: [react(), VitePWA({ includeAssets: ['**/*'] })], + plugins: [ + react(), + VitePWA({ + includeAssets: ['**/*'], + outDir: './dist/assets', + }), + ], })