Skip to content

A modern MJML boilerplate for building responsive HTML email templates using Bun, TypeScript, and Biome. Includes built-in support for: βœ… MJML compilation, 🧼 Minification, 🧩 {{Mustache-style}} templating , πŸ–₯️ Local preview resulting HTML.

License

Notifications You must be signed in to change notification settings

mikezotovdev/mjml-boilerplate

Repository files navigation

MJML Boilerplate

A modern MJML boilerplate for building responsive HTML email templates using Bun, TypeScript, and Biome. Includes built-in support for:

  • βœ… MJML compilation
  • 🧼 Minification via html-minifier
  • 🧩 Mustache-style templating (e.g. {{ colorBgDefault }})
  • πŸ–₯️ Local preview with variable interpolation
  • ⚑ Superfast builds with Bun

Preview of compiled email

Example of a compiled MJML email using this boilerplate.


πŸš€ Getting Started

1. Clone the repo

git clone https://github.com/mikezotovdev/mjml-boilerplate.git
cd mjml-boilerplate

2. Install dependencies

bun install

3. Build

bun run build

⚠️ Note: The build command does not interpolate variables such as {{ colorBgDefault }} or {{ firstName }}. These placeholders are preserved in the final output (in public/) because the email content is expected to be injected server-side at runtime.

4. Preview with variables

bun run preview

This command performs a local build with variables fully interpolated for visual testing and previewing emails.


πŸ“ Project Structure

.
β”œβ”€β”€ .githooks/                    # Git hooks (e.g. pre-push)
β”œβ”€β”€ biome.json                    # Biome formatter and linter config
β”œβ”€β”€ build.const.ts                # Build-time constants
β”œβ”€β”€ build.helpers.ts              # Build utilities
β”œβ”€β”€ build.preview.ts              # Preview build (with interpolated variables)
β”œβ”€β”€ build.templates.ts            # MJML -> HTML build logic
β”œβ”€β”€ postbuild.cleanup.ts          # Post-build cleanup script
β”œβ”€β”€ postbuild.minify.ts           # Minify HTML output
β”œβ”€β”€ dist/                         # Preview output (interpolated HTML)
β”œβ”€β”€ public/                       # Final output (minified, placeholders retained)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   └── images/
β”‚   β”‚       β”œβ”€β”€ common/           # Shared image assets
β”‚   β”‚       └── subject/          # Subject-specific icons
β”‚   β”œβ”€β”€ common/
β”‚   β”‚   β”œβ”€β”€ footer/               # Reusable footer components
β”‚   β”‚   β”œβ”€β”€ head/                 # MJML attributes, global attributes, banners, etc.
β”‚   β”‚   └── header/               # Reusable header component
β”‚   └── templates/                # Your email templates go here (use folders). A few examples are already included.
β”‚       β”œβ”€β”€ EmailConfirmation/
β”‚       β”œβ”€β”€ PasswordChanged/
β”‚       β”œβ”€β”€ PasswordReset/
β”‚       └── SignUpWelcome/

🧩 Template Variables

Use Mustache-style syntax in your MJML:

<mj-text>Hello, {{ firstName }}!</mj-text>

πŸ“š Template Variable Reference

Common variables

Variable Meaning Example
appLink Link to the app https://app.example.com
supportTelegram Support telegram nickname (not a link, no "@" prefix) support
supportEmail Support email [email protected]
firstName First name of the user Billy
userEmail User email address [email protected]
companyName Company name Gachi LTD
link Target action link (e.g. confirmation/reset link) https://app.example.com/api/verify/email?code=69

Color variables (global)

Variable Meaning Example
colorTextDefault Default text color #1A1A1A
colorTextDescription Description text color #6B7780
colorTextBrand Brand text color #219b61
colorTextBrandDark Brand dark text color (used for titles) #176B44
colorTextLink Link text color #1B7F4C
colorTextButton Button text color #FFFFFF
colorBgDefault Default background color #FFFFFF
colorBgBrand Brand background color #219b61
colorBgButtonBrand Brand button background color #219b61
colorBorderDefault Default border color #D0E4DA

Icons, logos, illustrations

Icons are stored in @2x resolution to ensure crisp display on retina screens.

Variable Icon size (width x height) Example
logoUrl 142x48 https://...image.png
emailIconUrl 48x48 https://...image.png
telegramLogoUrl 48x48 https://...image.png
subjectPasswordIconUrl 80x80 https://...image.png
subjectSecurityIconUrl 80x80 https://...image.png
subjectEmailIconUrl 80x80 https://...image.png
subjectWelcomeIconUrl 80x80 https://...image.png

πŸ“Œ Template Usage Guidelines

Follow these best practices to ensure your email templates render correctly and build reliably:

  • ⚠️ Keep consistent file depth for all *.mjml files. MJML cannot reliably resolve includes from files at different nesting levels.
  • 🚫 Never edit files manually in public/ β€” always build from source templates instead.
  • 🧩 Use {{ variableName }} syntax for all dynamic content.
  • ♻️ Put shared MJML blocks in src/common/ to avoid duplication.
  • πŸ’‘ Wrap conditional logic in HTML comments to prevent MJML from stripping unknown tags:
    <!-- {{#if userName}} -->
    <mj-text>Hello, {{ userName }}!</mj-text>
    <!-- {{/if}} -->

πŸ§ͺ Scripts

Script Description
bun run build Clean, compile, and minify templates (no variables interpolated)
bun run preview Full build with live preview of injected variables
bun run fix Format and lint using Biome
bun run clean-deps Remove all dependencies and lockfile
bun run setup-hooks Git pre-push hook setup

πŸ›  Tooling

  • Bun – ultra-fast JS runtime
  • MJML – email markup language
  • TypeScript – type-safe scripting
  • Biome – code formatter + linter
  • html-minifier – for lightweight, production-ready output

πŸ™‹β€β™‚οΈ Author

Created by Mike Zotov

LinkedIn Β· GitHub


❀️ Support

If you find this project helpful, feel free to support it:

  • ERC-20/BNB/Base: 0x117D11A2AD3D084b1aBC2a2F8be9531884936054
  • Solana: 7bYonr2pYa3Fs5vh21ngcAVHBUufGnUFp5mBposFMrxz
  • Bitcoin: bc1qm2dydvexnrh7caqc4wz4lasaqwfz8zaez298kd

πŸ“¦ License

MIT Β© Mike Zotov


🌐 Links

About

A modern MJML boilerplate for building responsive HTML email templates using Bun, TypeScript, and Biome. Includes built-in support for: βœ… MJML compilation, 🧼 Minification, 🧩 {{Mustache-style}} templating , πŸ–₯️ Local preview resulting HTML.

Topics

Resources

License

Stars

Watchers

Forks