Created
May 16, 2023 17:27
-
-
Save hyunbinseo/e2a7cb1b0aed1f47103f06b3587bc319 to your computer and use it in GitHub Desktop.
Vite Build End Notification (SendGrid Email)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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