chore: separate build chunks for services#3
chore: separate build chunks for services#3johannschopplich wants to merge 4 commits intoSupersaasHQ:mainfrom johannschopplich:chore/build-chunks
Conversation
|
Hey @johannschopplich thanks for the PR, pulled this and made a tar locally with 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? |
|
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 |

Alternative to #2.
All services now have a separate chunk. :)