API configuration
When using the Maizzle API, you can pass configuration options to therender() method.
The options parameter is an object with Maizzle configuration, like you would use in config.js.
Example
app.js
CSS options
Configure how CSS is processed and optimized.css.inline
Inline CSS from<style> tags into style attributes.
css.purge
Remove unused CSS from<style> tags.
css.shorthand
Rewrite CSS properties to use shorthand syntax.css.tailwind
Pass a Tailwind CSS configuration object.The
content key is required for Tailwind to know where to look for classes to generate. Otherwise your <style> tag will be empty and no CSS would be inlined.Tailwind CSS
When using the API, you might not have atailwind.config.js file in the current directory.
If a tailwind.config.js cannot be found in the current directory (where you execute the script), the default Tailwind CSS config will be used. In order to avoid this, you may pass your own Tailwind CSS config inside the options object.
For example, let’s use tailwindcss-preset-email when rendering templates programmatically:
app.js
input string, you need to pass the content key with an array of objects that contain the raw content and the file extension.
Hooks
You can use event hooks in the API configuration to run custom logic at different stages of the rendering process.Gotchas
Since the options object that you can pass to therender method is optional, there are a few gotchas that you need to be aware of.
Tailwind config
Maizzle will use the Tailwind CSS config object as-is, which means that if you just include thecontent key it will generate CSS with the default values like rem or CSS variables.
In order to generate CSS optimized for HTML email, you need to fully configure Tailwind in the css.tailwind object. The simplest way to do this is to use a preset like tailwindcss-preset-email, as shown in the example above.
Default Tailwind
If you don’t specify a Tailwind config object, Maizzle will try to compile Tailwind usingtailwind.config.js at your current path.
The default config is not optimized for HTML email: it uses units like rem and CSS properties that are used for web design and which have little to no support in the majority of email clients.
Also, the default Tailwind config will not include any content paths that should be scanned for generating utility classes, meaning that the <style> tag in your email will be empty.
Transformers
Most transformers, such as CSS inlining or minification, are opt-in: they transform content only when you enable them. Since you don’t need to pass in a Maizzle config object, this means that most of them will not run. The following transformers always run:- Markdown (can be disabled)
- Prevent widows
- Remove attributes - removes empty
styleattributes by default - Filters - provides various text filters
CSS output
You must add the@tailwind directives in a <style> tag in the <head> of your email HTML, otherwise Tailwind CSS will not be compiled.