-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: Dynamic imports #2
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
"src/index.ts", | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, using Like this: export default defineBuildConfig({
entries: [
"src/index",
"src/services/resend",
"src/services/plunk"
// etc.
],
// You should now be able to omit the `externals`!
} Rollup should automatically resolve these as separate chunks. |
||
builder: "mkdist", | ||
input: "src/services", | ||
outDir: "dist", | ||
}, | ||
], | ||
clean: false, | ||
declaration: true, | ||
rollup: { | ||
emitCJS: true, | ||
}, | ||
externals: [fileURLToPath(new URL("src/services", import.meta.url))], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
import { PlunkService } from "./services/plunk"; | ||
import { PostmarkService } from "./services/postmark"; | ||
import { ResendService } from "./services/resend"; | ||
import { SendGridService } from "./services/sendgrid"; | ||
import { MailgunService } from "./services/mailgun"; | ||
import type { EmailProvider } from "./types/email-options"; | ||
import type { EmailService } from "./types/email-service"; | ||
|
||
/** | ||
* Factory function to get the email service based on the provider | ||
* @param provider - The email provider | ||
* @returns The email service instance | ||
* @returns A Promise that resolves to the email service instance | ||
* @throws Error if the provider is not supported | ||
*/ | ||
export function useEmail(provider: EmailProvider): EmailService { | ||
export async function useEmail(provider: EmailProvider): Promise<EmailService> { | ||
switch (provider) { | ||
case "resend": { | ||
const { ResendService } = await import("./services/resend"); | ||
return new ResendService(); | ||
} | ||
case "plunk": { | ||
const { PlunkService } = await import("./services/plunk"); | ||
return new PlunkService(); | ||
} | ||
case "sendgrid": { | ||
const { SendGridService } = await import("./services/sendgrid"); | ||
return new SendGridService(); | ||
} | ||
case "postmark": { | ||
const { PostmarkService } = await import("./services/postmark"); | ||
return new PostmarkService(); | ||
} | ||
case "mailgun": { | ||
return MailgunService(); | ||
} | ||
default: { | ||
throw new Error(`Unsupported email provider: ${provider}`); | ||
Check failure on line 29 in src/index.ts GitHub Actions / ciUnhandled error
|
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the extension: