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.
npm install mjml-cliVerified import paths — ran on the pinned version, not inferred.
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.
Uninstall `mjml-cli` if present (`npm uninstall mjml-cli`) and install the core `mjml` package (`npm install mjml`). All CLI commands are available via the `mjml` executable provided by the `mjml` package.
Carefully review your compiled HTML output after upgrading. Adjust `--config.minifyOptions` according to `htmlnano` and `cssnano` documentation if specific minification behavior is required. For CSS, `minifyCss` options now align with `cssnano` presets.
Ensure all `mj-include` paths are correct, relative, and accessible. If `ignoreIncludes` is used, verify its configuration and the `includePath` option. Test thoroughly, as previously tolerated incorrect paths might now cause compilation failures.
Inspect the generated HTML for changes around the `<body>` tag. Adjust any custom CSS, JavaScript, or integration points that interact directly with the `<body>` element or its immediate children.
Enable style sanitization by using `--config.sanitizeStyles true` in your CLI command or programmatic options. This option temporarily replaces template tokens during CSS processing and restores them afterward, preventing parsing issues.
Install `mjml` globally (`npm install -g mjml`), or run it from your local `node_modules/.bin` directory (`./node_modules/.bin/mjml`), or add `./node_modules/.bin` to your PATH temporarily (`export PATH="$PATH:./node_modules/.bin"`).
Review the MJML file for errors indicated in the output. If the validation is too strict for your use case, change the validation level to `normal` (default) or `skip` using `--validationLevel normal` or `--validationLevel skip`.
Verify that the path specified in `mj-include` is correct relative to the including file or the configured `includePath` option. Ensure the included file exists and has the necessary read permissions. For v5, remember `mj-include` handling is stricter.