fastify / fastify-vite

Fastify plugin for Vite integration.
MIT License
849 stars 71 forks source link

Serve static assets from ssr builds in production mode #116

Closed ajaishankar closed 9 months ago

ajaishankar commented 10 months ago

Prerequisites

Issue

Vite has the option to generate assets for ssr builds.

https://main.vitejs.dev/config/build-options#build-ssremitassets

Currently @fastify/vite only serves client assets, could it be updated to also serve ssr build assets?

Something like:

  await this.scope.register(async function staticContext (scope) {
    await scope.register(FastifyStatic, {
      root: [resolve(clientDist, assetsDir), resolve(serverDist, assetsDir)],
      prefix: `/${assetsDir}`
    })
  })
galvez commented 9 months ago

Yep, that sounds like a reasonable thing to do. Can you open a PR with that change? I'll review and test then.

ajaishankar commented 9 months ago

@galvez Have opened PR https://github.com/fastify/fastify-vite/pull/121

Was not sure about how to run the tests though...