fastify / fastify-vite

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

How to use Vue plugins like instance.use(...) #133

Closed alemagio closed 6 months ago

alemagio commented 7 months ago

Prerequisites

Issue

Hi,

I am trying to use Vue plugins but I need access to the Vue instance. The only thing I could do was to copy the source code from the create.js file in the repo and change it as I needed. Is there a better way?

galvez commented 7 months ago

Right now that's the only way to do it, just copy virtual/create.js from the @fastify/vue package and place it in your Vite root directory — @fastify/vue will automatically use your version of it as long as you always import from /:create.js.

I'm open to suggestions on how to make these types of customisations easier!

alemagio commented 7 months ago

Hey @galvez sorry for the late response. Anyway, I did that and works perfectly, my idea could be to make the system "merge" the existing create.js and the one added in my project root.

So my create.js might appear like this


export default async function create ({ instance, ctx, router }) {

  instance.use(myPlugin)

  return { instance, ctx, router }
}

Like a middleware. Just wondering, not sure if it's doable.

galvez commented 7 months ago

Let's keep this issue open while I thinker with it a bit.

Thanks for giving @fastify/vue a shot!

galvez commented 6 months ago

https://github.com/fastify/fastify-vite/releases/tag/vue-v0.4.0

Now please go tweet merrily about this project kthxbai 😸