@vitejs/plugin-vue, loading every email through Vite’s
server-side module loader. There’s nothing to configure: it works with the files you already have.
What’s supported
- Single file components, including
<script setup lang="ts"> - TypeScript, in
.vuefiles and in the modules they import - Path aliases from the
pathsof yourtsconfig.json, like"@/*": ["./*"] - JSON imports, like
import messages from '../messages/en.json' - Raw imports, with the
?rawsuffix, likeimport theme from './theme.css?raw', which is how you can keep the CSS for thethemeprop ofTailwindin a.cssfile. Not every bundler supports?rawthough: for emails your Nuxt server routes import too, keep that CSS in a string exported from a.tsfile instead, as in the Nuxt guide - Dependencies, from
node_modulesor from other packages of your workspace - Static files: image URLs in templates, like
<Img src="/static/logo.png" />, stay URLs instead of becoming module imports, so the preview can serve them fromemails/static
email dev right away.
emails/welcome.vue
What’s not supported
- Your Vite configuration: the CLI doesn’t load
vite.config.ts, so plugins you add there don’t apply to your emails. Pass the plugins your emails need with--vite-pluginsinstead. .envfiles: they aren’t loaded either.process.envhas the environment variables of the process running the CLI, set by your shell or your tooling.
Compiling emails in your own code
Node.js can’t import.vue files on its own, so the code that renders your emails with render
has to be compiled with a Vue plugin too. Keep the URLs of images as they are, like the CLI does, by
turning off transformAssetUrls.
- Nuxt
- Vite
- tsdown
Add the
@vuemaildev/nuxt module, and import emails from your server routes. See Nuxt.nuxt.config.ts