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

Is it possible to inline external dependencies? #305

Closed
2 tasks done
Blankeos opened this issue Mar 6, 2024 · 2 comments
Closed
2 tasks done

Is it possible to inline external dependencies? #305

Blankeos opened this issue Mar 6, 2024 · 2 comments

Comments

@Blankeos
Copy link

Blankeos commented Mar 6, 2024

Description

Context

My goal currently is to generate the App type for my ElysiaJS server (basically the same as tRPC). So I can use it for my client on the frontend.

So far it works great. Here's my Config:

import { resolve } from "path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, "src/appType.ts"),
      name: "MyLib",
      formats: ["es"],
    },
    rollupOptions: {
      output: {
        dir: "codegen-vite",
      },
    },
  },
  plugins: [dts({ rollupTypes: true, outDir: "codegen-vite" })],
});

It then generates a file like this:
image

I can basically serve this on an endpoint and I can consume it on my frontend for my client by saving it somewhere in src after a curl script. It's super cool since I wouldn't need to share these types via an intermediary npm package.

The Feature Request

Is there any way we can also "inline" the types from external dependencies? 'elysia', 'geojson', 'lucia' for example. So that I wouldn't need to bun add -D @types/elysia @types/geojson @types/lucia on the client.

Suggested solution

Not too sure...

A great API addition would probably be dts({ rollupTypes: true, inlineExternalDeps: true }) though.

Alternative

No response

Additional context

No response

Validations

  • Read the FAQ.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@qmhc
Copy link
Owner

qmhc commented Mar 12, 2024

Why you want this? (first of all, it's hard to implement ...) I think this is a fake requirement, refer to #302.

@Blankeos
Copy link
Author

No worries! Just wondering.

Why I want this? I wrote it above. But for more context: I have separate client and backend repos for ElysiaJS. It's a typesafe backend like tRPC and similarly, it only works in monorepos, or if the type definitions are shared via an npm package. I have a polyrepo client and backend separate repos.

In any case, vite-plugin-dts already takes care of the transpilation for me. The type definitions from external libraries are also pretty much at the top anyway. So my work-around would be just to reinstall the types via the client repo (bun install -D @types/*)

Will be closing this now! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants