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

chore: separate build chunks for services #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

johannschopplich
Copy link
Contributor

@johannschopplich johannschopplich commented Oct 24, 2024

Alternative to #2.

All services now have a separate chunk. :)

@fayazara
Copy link
Contributor

Hey @johannschopplich thanks for the PR, pulled this and made a tar locally with npm pack and then installed this local package in a test project as a dev Dependency

Made a test api endpoint using one of the services

import { useEmail } from "use-email";
export default defineEventHandler(async (event) => {
  const emailService = await useEmail("resend");
  const response = await emailService.send({
    from: "sender@example.com",
    to: "recipient@example.com",
    subject: "Hello from use-email!",
    text: "This is a test email sent using use-email package.",
  });
  return response;
});

Its making the chunks but all of the services are still getting bundled in the application, did I miss anything here?

Screenshot 24-10 at 19

@johannschopplich
Copy link
Contributor Author

Ah OK, now I get your point... Sorry, was missing it the whole time. 😄 Since the dynamic imports will be evaluated at runtime, the chunks for each provider will still be bundled, yes. Rollup can't statically determine, which provider will be imported at runtime. But still, since they are separate chunks, does it matter?

The only alternative I see is to let the user import the provider manually. For example:

const { default: resend } = await import('use-email/resend')
const emailService = await useEmail(resend);

This is the only way that comes to mind to actually bundle only the services used. You can use package.json sub-path exports (see last commit).

You could change to default exports, so the await import is a bit simpler and all services export the same name.

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

Successfully merging this pull request may close these issues.

2 participants