Skip to content

Instantly share code, notes, and snippets.

@hyunbinseo
Created May 16, 2023 17:27
Show Gist options
  • Save hyunbinseo/e2a7cb1b0aed1f47103f06b3587bc319 to your computer and use it in GitHub Desktop.
Save hyunbinseo/e2a7cb1b0aed1f47103f06b3587bc319 to your computer and use it in GitHub Desktop.
Vite Build End Notification (SendGrid Email)
import { generateSgSendRequest } from 'sendgrid-send';
import { defineConfig } from 'vite';
// Vite Conditional Config
// Reference https://vitejs.dev/config/#conditional-config
export default defineConfig(({ command }) => ({
plugins: [
{
name: 'Build End Notification',
buildEnd: async (error) => {
// Only send notification on `build`.
if (command !== 'build') return;
const response = await fetch(
generateSgSendRequest(
{
from: { email: '[email protected]' },
personalizations: [{ to: [{ email: '[email protected]' }] }],
subject: `Build ${!error ? 'Success' : 'Fail'}`,
content: [{ type: 'text/html', value: '<<YOUR_CONTENT_HERE>>' }]
},
'<<YOUR_API_KEY_HERE>>'
)
);
// Reference https://docs.sendgrid.com/api-reference/mail-send/mail-send
if (!response.ok) console.error(await response.json());
}
}
]
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment