Skip to content

Commit

Permalink
try new sw
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomorebonato committed Jun 28, 2023
1 parent 42cc7e4 commit 337edff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
26 changes: 20 additions & 6 deletions server/plugins/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 7 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
],
})

0 comments on commit 337edff

Please sign in to comment.