Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the Vite dev server #3869

Closed
brillout opened this issue Feb 12, 2022 · 7 comments
Closed

Expose the Vite dev server #3869

brillout opened this issue Feb 12, 2022 · 7 comments
Labels
feature / enhancement New feature or request

Comments

@brillout
Copy link

Describe the problem

Telefunc cannot be used with SvelteKit because Telefunc needs a reference to the Vite dev server which SvelteKit creates at:

const server = await vite.createServer(merged_config);
.

(Telefunc needs the Vite dev server to be able to run vite.ssrLoadModule() in order to import.meta.glob('**/*.telefunc.*').)

Describe the proposed solution

Expose the vite dev server.

For reference this is how Telefunc integrates with vite-plugin-ssr: https://github.com/vikejs/telefunc/blob/ff196287342b4ea3addbc0e0a559eef680f73796/examples/vite-plugin-ssr/server/index.js

Note how the Vite dev server is set to telefuncConfig.viteDevServer here: https://github.com/vikejs/telefunc/blob/ff196287342b4ea3addbc0e0a559eef680f73796/examples/vite-plugin-ssr/server/index.js#L23

@benmccann mentioned that there is PR to make the Vite dev server accessible, any chance to get it merged?

CC @phiberber who is working on a SvelteKit + Telefunc example.

Alternatives considered

No response

Importance

i cannot use SvelteKit without it

Additional Information

No response

@bluwy
Copy link
Member

bluwy commented Feb 12, 2022

Related #2921

@bluwy bluwy added the feature / enhancement New feature or request label Feb 12, 2022
@benmccann
Copy link
Member

Here's the PR for reference: #2663. But we didn't want to expose the dev server or component loading unless absolutely necessary

I'm not entirely sure you'd need it for what you're attempting. The hooks are loaded via ssrLoadModule:

? await vite.ssrLoadModule(`/${config.kit.files.hooks}`)

As a result, anything loaded in the hooks should generally be transitively loaded by Vite's ssrLoadModule. Is there some way that telefunc's API could be changed to simply do a standard import and not require access to the ViteDevServer? I believe it should just work in that case

@benmccann
Copy link
Member

@phiberber also said he was able to grab it from a Vite plugin as another solution:

{
  name: "telefunc-config",
  configureServer(viteDevServer) {
    telefuncConfig.viteDevServer = viteDevServer;
  }
}

@dougmoscrop
Copy link

I would like to run the dev server in-process; I don't need access to the internals, an opaque function that takes (req, res, next) or Web Fetch versions would be fine. I guess this actually also asks for a programmatic interface to SvelteKit.

@phiberber
Copy link

@phiberber also said he was able to grab it from a Vite plugin as another solution:

{
  name: "telefunc-config",
  configureServer(viteDevServer) {
    telefuncConfig.viteDevServer = viteDevServer;
  }
}

This is now implemented in the Telefunc vite plugin.

I would like to run the dev server in-process; I don't need access to the internals, an opaque function that takes (req, res, next) or Web Fetch versions would be fine. I guess this actually also asks for a programmatic interface to SvelteKit.

I think that you can use of Svelte Kit Endpoints to that, if not maybe an express-like middleware system written with Svelte Kit hooks fullfills your needs, not sure how recommended is it though.

@Rich-Harris
Copy link
Member

If this relies on the dev server, how does it work in prod?

@Rich-Harris
Copy link
Member

Going to close this now that we just use a regular Vite config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants