Registry / devops / webpack-mjml-loader

webpack-mjml-loader

JSON →
library2.0.1jsnpmunverified

A webpack loader that compiles MJML email templates into HTML strings at build time. Current stable version is 2.0.1 (released March 2025), targeting webpack 5 exclusively. For webpack 4, use v1.1.0. MJML is a peer dependency, allowing you to choose any MJML v4+ version. Key differentiators: forwards all MJML options (like minification) via loader options, outputs HTML as a default export string, and ships TypeScript definitions. Compared to other MJML loaders, this one is simple, well-maintained, and explicitly designed for webpack 5.

npm install webpack-mjml-loader
INSTALL
IMPORT
SIG · WEBPACK-MJML-LOADE
W
webpack-mjml-loader
devopsjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default import from .mjml file
import template from './email.mjml'
import { template } from './email.mjml'
The loader converts MJML to an HTML string as the default export. Named import will fail.
webpack rule for .mjml files
module.exports = { module: { rules: [ { test: /\.mjml$/, use: 'webpack-mjml-loader' } ] } }
module.exports = { module: { rules: [ { test: /\.mjml$/, loader: 'webpack-mjml-loader' } ] } }
Use the `use` property for loaders in webpack 5. The `loader` shorthand is deprecated.
TypeScript import
import template from './email.mjml'
import * as template from './email.mjml'
TypeScript users may need to add a module declaration for .mjml files: declare module '*.mjml' { const content: string; export default content; }

Shows how to install, configure webpack rule for .mjml files, and import compiled HTML string.

// Install: // npm install -D webpack-mjml-loader mjml // webpack.config.js module.exports = { module: { rules: [ { test: /\.mjml$/, use: [ { loader: 'webpack-mjml-loader', options: { minify: true } } ] } ] } }; // email.mjml <mjml> <mj-body> <mj-section> <mj-column> <mj-text>Hello World!</mj-text> </mj-column> </mj-section> </mj-body> </mjml> // app.js import template from './email.mjml'; console.log(template); // HTML string output
Debug
Known issues
breakingv2.0.0 drops webpack 4 support – upgrade to webpack 5 or stay on v1.1.0.
fix
Use webpack 5. If you must use webpack 4, pin to webpack-mjml-loader@1.1.0.
affects: >=2.0.0 <3.0.0
deprecatedv1.x will not receive updates – new features only for v2.
fix
Migrate to v2 and webpack 5.
affects: >=1.0.0 <2.0.0
gotchaMJML must be installed as a peer dependency – missing it causes an error at build time.
fix
Run: npm install -D mjml
affects: >=1.0.0
gotchaOptions are forwarded to MJML's mjml2html – misconfigured options (e.g., invalid validationLevel) can silently produce broken HTML.
fix
Refer to MJML documentation for valid options. Start without options and add gradually.
affects: >=1.1.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Webpack config does not have a rule for .mjml files or the loader is not applied.
fix
Add a module rule in webpack.config.js: { test: /\.mjml$/, use: 'webpack-mjml-loader' }
Cannot find module 'mjml'
MJML peer dependency is not installed.
fix
Run: npm install -D mjml
TypeScript: Cannot find module './email.mjml' or its corresponding type declarations.
TypeScript does not recognize .mjml files without a module declaration.
fix
Create a declaration file (e.g., global.d.ts) with: declare module '*.mjml' { const content: string; export default content; }
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
mjmlrequiredPeer dependency – transforms MJML syntax to HTML
Agent activity
25 hits · last 30 days
node
20
OpenAI (training)
1
Resources
webpack-mjml-loader — npm install webpack-mjml-loader · libregistry