server side rendering
Deno
Server-Side Rendering with Deno
deno
support is available on version `0.8.0-beta' and aboveIntroduction
Vue Email
can now be used to render and send emails from the server side using deno too.
Installation and usage
Deno
is slightly different compared to Node
and Bun
, but with the support for npm, it is now possible to use Vue Email on the server side with Deno.
For this, you need to create the configuration file, and write the following:
{
"imports": {
"vue": "npm:vue",
"@vue-email/compiler": "npm:@vue-email/compiler@version",
},
"tasks": {
"dev": "deno run --allow-net --allow-read index.ts"
}
}
This will enable you to use the Vue Email
on the server side without encountering any errors. The library relies on the vue package as a dependency, and if it is not found, an error will be thrown.
Now in your index.ts
you can use the package:
import { config } from "@vue-email/compiler";
import "vue";
const vueEmail = config("/templates/path")
async function main() {
const template = await vueEmail.render("Template.vue");
console.log(template);
}
main();
vue
package in your index.ts
file. This allows deno
to import it correctly, and ensures that the library works as expected.Finally you can run with:
deno task dev
Config
You can see the config here.
Render
The render
method takes two arguments, the first is the name of the template file, and the second is an optional props object.
const template = await vueEmail.render("Template.vue", {
props: {
name: "John Doe",
},
});
Example
in this example we will use Express.js
to render and view an email.
import express from "npm:express";
import { config } from "@vue-email/compiler";
const app = express();
const vueEmail = config("./templates", {
verbose: false,
options: {
baseUrl: "https://vue-email-demo.vercel.app/",
},
});
app.get("/", async function (req, res) {
const template = await vueEmail.render("WelcomeEmail.vue", {
props: {
name: "John Doe",
},
});
res.send(template);
});
app.listen(3000);
Sending Emails
Once you have rendered your email template, you can send it using any email provider you like.
Vue Email
does not provide any email sending functionality, you will need to use a third party email provider to send your emails, check the integration section for more information. IntegrationsBugs and Issues
If you encounter any bugs or issues, feel free to open an issue at GitHub