gulp-mjml

by mjmlio

mjmlio /gulp-mjml

Add Gulp to your MJML workflow!

135 Stars 30 Forks Last release: about 1 year ago (v3.0.1) MIT License 58 Commits 6 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Gulp MJML

Add MJML to your gulp workflow!

Usage:

With an MJML file named

test.mjml
, render your emails to an html folder:
const gulp = require('gulp')
const mjml = require('gulp-mjml')

gulp.task('default', function () { return gulp.src('./test.mjml') .pipe(mjml()) .pipe(gulp.dest('./html')) })

If you have custom components linked to your own

mjmlEngine
, you can pass it to the gulp task so it uses your engine to render the html:
const gulp = require('gulp')
const mjml = require('gulp-mjml')

// Require your own components if needed, and your mjmlEngine (possibly with options) // require('./components') const mjmlEngine = require('mjml')

gulp.task('default', function () { return gulp.src('./test.mjml') .pipe(mjml(mjmlEngine, {minify: true})) .pipe(gulp.dest('./html')) })

If you'd like to get validation errors and , use

strict
and a custom error handler function. Note that using
strict
will not render the file in case of error
:
const gulp = require('gulp')

const mjml = require('gulp-mjml') const mjmlEngine = require('mjml')

function handleError (err) { console.log(err.toString()); this.emit('end'); }

gulp.task('default', function () { return gulp.src('./test.mjml') .pipe(mjml(mjmlEngine, {validationLevel: 'strict'})) .on('error', handleError) .pipe(gulp.dest('./html')) })

If you want to override the default file extension that is output use

fileExt
const gulp = require('gulp')
const mjml = require('gulp-mjml')

const mjmlEngine = require('mjml')

gulp.task('default', function () { return gulp.src('./test.mjml') .pipe(mjml(mjmlEngine, {minify: true, fileExt: ".txt"})) .pipe(gulp.dest('./html')) })

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.