Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for minification #75

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@babel/runtime": "^7.14.6",
"babel-runtime": "~6.25.0",
"color": "^3.1.3",
"html-minifier-terser": "*",
daliusd marked this conversation as resolved.
Show resolved Hide resolved
"react-reconciler": "^0.26.1"
},
"babel": {
Expand Down
17 changes: 15 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { minify } from 'html-minifier-terser'
import ReactDOMServer from 'react-dom/server';
import mjml2html from 'mjml';

Expand Down Expand Up @@ -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) {
Expand Down