Skip to main content
When you run maizzle build, your Templates go through a series of events that compile them to plain HTML and apply various, email-specific transformations. To get a better understanding of how Maizzle builds your emails, here’s a step-by-step guide of what’s going on under the hood.

Environment config

First, a global configuration object is computed by merging your Environment config on top of the base config.js. For example, running maizzle build production will tell Maizzle to look for the config.production.js file at your current location, and merge it on top of config.js. When running maizzle build or maizzle serve, only the base config.js will be used.

beforeCreate()

The beforeCreate event (CLI-only) is triggered, giving you access to the config before Maizzle loops over your Templates to compile them.

Clean destination

The destination directories that you have defined under build.output.path in your environment config are deleted.
Be careful when customizing this path, so you don’t end up deleting important directories and files on your machine.

Compile templates

Each Template file is parsed and compiled:
1

Read template file

Maizzle reads the Template file
2

Extract Front Matter

It extracts its Front Matter
3

Compute config

A unique Template config is computed by merging the Template’s Front Matter keys with the Environment config
4

beforeRender() event

beforeRender() event is triggered
5

Render HTML

The HTML is rendered with PostHTMLYour Environment name and all config options (including any you defined in Front Matter) are exposed under the page object, which you can access through expressions.PostHTML plugins that are used as part of the rendering process:
  • envTags - core plugin that enables <env:?> tags
  • envAttributes - core plugin that enables attributes like src-{env}
  • expandLinkTags - core plugin that expands local <link> tags into <style> tags
  • postcssPlugin - this is where the Tailwind CSS magic happens
  • fetchPlugin - enables the <fetch> tag
  • posthtml-component - the PostHTML plugin that powers Maizzle’s components
6

afterRender() event

afterRender() event is triggered

Transformers

The compiled HTML is now passed on to a series of Transformers. Most of them are enabled by default, but some need to be explicitly enabled in your config.js. The order in which they’re executed is exactly as follows:
1

coreTransformers

Remove <plaintext> tags when developing locally, enable no-inline attribute for <style> tags
2

safeClassNames

safeClassNames - escaped characters in <head> and <body> CSS classes are replaced with email-safe alternatives
3

filters

filters - Liquid-like filters are applied to the HTML
4

markdown

markdown is compiled
5

widowWords

widowWords - widow words are prevented in tags with the prevent-widows attribute
6

attributeToStyle

attributeToStyle - translates HTML attributes to inline CSS
7

inlineCSS

inlineCSS - CSS is inlined
8

removeAttributes

removeAttributes - HTML attribute removal based on your config
9

shorthandCSS

shorthandCSS - longhand CSS in style attributes is converted to shorthand-form
10

addAttributes

addAttributes - user-configured attributes are added to tags
11

baseURL

baseURL - a base URL is prepended to configured attribute values
12

urlParameters

urlParameters - configured parameters are added to URLs
13

sixHex

sixHex - ensures six digit HEX color codes are used in bgcolor and color attributes
14

posthtmlMSO

posthtmlMSO - <outlook> tags are replaced with the correct MSO comments
15

purgeCSS

purgeCSS - unused CSS is removed from <style> tags and HTML attributes
16

templateTag

templateTag - <template> tags are replaced with their content
17

replaceStrings

replaceStrings - strings are replaced based on your config
18

prettify

prettify - HTML is prettified
19

minify

minify - HTML is minified

afterTransformers()

The afterTransformers event is triggered.

Plaintext

A plaintext version is created at the configured location, if plaintext was enabled.

Write to disk

The compiled HTML is saved at the configured location, with the configured extension.

Copy static files

All files and folders in build.static.source are copied to build.static.destination.

afterBuild()

The afterBuild event is triggered (CLI-only).

Build docs developers (and LLMs) love