diff --git a/package.json b/package.json index 137ad18..20af256 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@babel/runtime": "^7.14.6", "babel-runtime": "~6.25.0", "color": "^3.1.3", + "html-minifier-terser": "*", "react-reconciler": "^0.26.1" }, "babel": { diff --git a/src/index.js b/src/index.js index 2716068..3b875ea 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +import { minify } from 'html-minifier-terser' import ReactDOMServer from 'react-dom/server'; import mjml2html from 'mjml'; @@ -47,10 +48,22 @@ function render(email, options = {}) { const defaults = { keepComments: false, beautify: false, - minify: true, validationLevel: 'strict', }; - return mjml2html(renderToMjml(email), { ...defaults, ...options }); + + const html = mjml2html(renderToMjml(email), { ...defaults, ...options, minify: false }); + + if (options.minify) { + return minify(html, { + caseSensitive: true, + collapseWhitespace: true, + minifyCSS: true, + removeComments: true, + removeEmptyAttributes: true + }); + } + + return html; } function renderToMjml(email) {