@treygrr/vjml
v0.1.6
Published
Vue MJML-style email components with a plain Vue plugin and browser renderer.
Maintainers
Readme
vjml
VJML is a Vue-only MJML-style email component library for standard Vue apps. It provides a plugin for global component registration, typed component exports, and browser-side render helpers for turning Vue email components into email-safe HTML.
It includes:
- the copied MJML-style runtime components
- plugin-based global registration for Vue apps
- metadata and typed component prop exports
- browser-side render helpers for converting a Vue email component into email-safe HTML
Repository layout
srccontains the publishable component library and is the only code compiled intodist.testcontains the component parity suites, shared test utilities, and end-to-end sample email fixtures.websitecontains the Nuxt documentation site and is managed as a workspace from the repository root.playgroundcontains the local development app used for previewing and testing the library.- The playground imports the library through the local
vjmlsource alias, while the published npm package name is@treygrr/vjml.
Run npm install from the repository root. The root package manages both the publishable library and the website workspace.
Scripts
npm run devstarts the local playground.npm run dev:playgroundalso starts the local playground explicitly.npm run dev:websitestarts the Nuxt docs site from the root workspace.npm run docs:devis an alias fornpm run dev:website.npm run docs:buildbuilds the docs site from the root workspace.npm run docs:generategenerates the static docs output from the root workspace.npm run docs:previewpreviews the built docs site locally.npm run buildbuilds both the library and the website from the repository root.npm run build:libruns the library build directly.npm run build:websiteruns only the Nuxt docs build.npm run testruns the renderer parity test suite.npm run test:accordionruns the first component parity suite against the accordion fixtures.npm run typecheckvalidates the playground and library source.npm run typecheck:websiteruns the Nuxt workspace typecheck from the repository root.
Component parity tests
The parity harness lives under test/components.
- Each component gets its own folder.
- Each variant is represented by a
.vuefixture and a matching.mjmlfixture. - The component test renders both sides, normalizes the generated HTML, and compares the results.
Contributing
Contributions go through GitHub pull requests. Before opening a pull request, make sure the change is covered by tests, run the relevant verification commands, and update docs or generated metadata when the public surface changes.
- Changes to existing behavior need updated coverage.
- New features and new components need new coverage.
- Runtime and component changes should update parity fixtures under
test/componentsortest/samples. - Library changes should be verified with
npm run typecheck,npm run test, andnpm run build. - Docs changes live under
website/and should be verified withcd website && npm run build.
See CONTRIBUTING.md for the full contributor workflow and GitHub merge policy.
License
MIT. See LICENSE.
Install the plugin
import { createApp } from 'vue'
import App from './App.vue'
import VjmlPlugin from '@treygrr/vjml'
createApp(App)
.use(VjmlPlugin, {
includeUnprefixedAliases: true,
prefix: 'VJ',
render: {
validation: 'warn',
},
})
.mount('#app')Set includeUnprefixedAliases: true when you want both VJText-style prefixed names and bare aliases such as Text or Mjml available from the plugin.
You can also import components directly:
import { Body, Button, Column, Mjml, Section, Text } from '@treygrr/vjml'Preview in the browser
The main @treygrr/vjml entry now includes a browser-side renderer and an iframe preview component.
<script setup lang="ts">
import WelcomeEmail from './WelcomeEmail.vue'
import { VjmlRenderFrame } from '@treygrr/vjml'
</script>
<template>
<VjmlRenderFrame :component="WelcomeEmail" />
</template>If you want the generated HTML directly in a browser runtime, use createVjmlRenderer() from @treygrr/vjml.
import WelcomeEmail from './WelcomeEmail.vue'
import { createVjmlRenderer } from '@treygrr/vjml'
const { renderToHtml } = createVjmlRenderer()
const { html, issues } = await renderToHtml(WelcomeEmail)Render an email component
import WelcomeEmail from './WelcomeEmail.vue'
import { createVjmlRenderer } from '@treygrr/vjml'
const { renderToHtml } = createVjmlRenderer({
render: {
validation: 'strict',
},
})
const { html, issues } = await renderToHtml(WelcomeEmail, {
props: {
firstName: 'Ada',
},
})Inside a setup context, useVjmlRenderer() is also available from @treygrr/vjml and merges the injected plugin config automatically.
Important entries
src/index.tsexports the plugin, components, metadata, and shared utilities.src/runtime/componentscontains the copied VJML component implementations.src/runtime/internalcontains the browser render pipeline and document/context helpers.src/metadata.tsandsrc/metadata.generated.tsprovide component metadata used by validation and serialization.playground/App.vueis the development catalog that imports and exercises the library.
