MJML CLI

5.0.1 · active · verified Sun Apr 19

The `mjml` package (which provides the `mjml-cli` functionality) is a robust, open-source framework designed to simplify the creation of responsive emails. It allows developers to build emails using a custom XML-like component language (MJML) that is then compiled into production-ready, semantic HTML, ensuring consistent rendering across various email clients. The current stable version, 5.0.1, introduces significant improvements in HTML output, minification, and security. Releases follow a steady cadence, with active development on minor versions and frequent alpha/beta cycles for major upgrades. Key differentiators include its declarative component-based approach, strong focus on email client compatibility, excellent documentation, and vibrant community support, collectively addressing the historical pain points of crafting reliable HTML emails. While the dedicated `mjml-cli` npm package is deprecated, the core `mjml` package provides the command-line interface functionality, enabling compilation, validation, and watch modes directly from the terminal.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install the `mjml` package and use its command-line interface to compile an MJML file to HTML, including watching for file changes and applying custom minification options.

npm install mjml

# Create an MJML file, e.g., 'template.mjml'
# <mjml>
#   <mj-body>
#     <mj-section>
#       <mj-column>
#         <mj-text>Hello from MJML!</mj-text>
#         <mj-button href="https://mjml.io">Learn More</mj-button>
#       </mj-column>
#     </mj-section>
#   </mj-body>
# </mjml>

# Compile MJML to HTML and output to a file
./node_modules/.bin/mjml template.mjml -o output.html

# Alternatively, if 'mjml' is globally installed or in your PATH:
mjml template.mjml -o output.html

# Watch for changes in 'template.mjml' and recompile automatically
mjml --watch template.mjml --output watch-output.html

# Compile with custom options: minify HTML and specify CSS minification preset
mjml template.mjml --config.minify true --config.minifyOptions='{"minifyCss": "default"}' -o minified.html

view raw JSON →