fastify / fastify-vite

Fastify plugin for Vite integration
MIT License
894 stars 75 forks source link

feat: make Vite configuration available from distribution bundle #156

Closed onlywei closed 2 months ago

onlywei commented 4 months ago

Addresses #155

Adds a new config option that needs a vite plugin to work.

By default, @fastify/vite looks up the Vite configuration options by importing Vite from node_modules and then using its Node API to look up the vite.config file. This is often not desirable in production mode since many production builds declare Vite as a devDependency and exclude it from their final container/docker images to save space.

To support this kind of production build, this PR makes @fastify/vite ship with a Vite plugin that can save the handful of properties that it needs from the resolved Vite configuration object to a file in a cache directory. These properties can than be loaded instead of loading the config through vite itself.

See the changes to the docs file for exactly what is happening in this change.

Checklist

netlify[bot] commented 4 months ago

Deploy Preview for agitated-mahavira-26f8f9 canceled.

Name Link
Latest commit 853306a2a3cd518a17e6466805d15242de717acf
Latest deploy log https://app.netlify.com/sites/agitated-mahavira-26f8f9/deploys/66f0ab5b8422670008741e0f
galvez commented 4 months ago

This is absolutely amazing, thank you @onlywei! I'll be reviewing shortly.

onlywei commented 2 months ago

@galvez In this PR I have made effort to maintain backwards compatibility. Shall I delete those backwards compatibility code since there is an upcoming major release anyway?

gurgunday commented 2 months ago

Shall I delete those backwards compatibility code since there is an upcoming major release anyway?

Not sure if it's "too late" or not, so it could be better to keep it until @galvez chimes in

galvez commented 2 months ago

@mcollina Do you see foresee any issues using node_modules/.cache?

galvez commented 2 months ago

Can you explain why for instance in TypeScript's case we need distDir to be explicit?

viteFastify({ distDir: resolve(import.meta.dirname, 'dist') }),

Perhaps we should include the explanation as part of the already extended bits in the docs you added?

Though it seems like something we could autoresolve?

onlywei commented 2 months ago

Can you explain why for instance in TypeScript's case we need distDir to be explicit?

viteFastify({ distDir: resolve(import.meta.dirname, 'dist') }),

Perhaps we should include the explanation as part of the already extended bits in the docs you added?

Though it seems like something we could autoresolve?

I forgot to delete that too. Good catch. It's deleted now.