-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a custom mjml loader to support version 4
- Loading branch information
1 parent
9d723f6
commit 1e5c922
Showing
8 changed files
with
72 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const mjml2html = require('mjml'); | ||
|
||
module.exports = function mjmlLoader(content) { | ||
this.cacheable(); | ||
|
||
const result = mjml2html(content); | ||
|
||
if (result.errors.length) { | ||
const errorMsg = `[mjml-loader] ERROR in ${this.resourcePath}: | ||
${result.errors.map(error => `- ${error.formattedMessage}`)}`; | ||
|
||
const error = new Error(errorMsg); | ||
error.code = 'MJML_INVALID'; | ||
|
||
throw error; | ||
} | ||
|
||
return `module.exports = ${JSON.stringify(result.html)};`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const mjml2html = require('mjml'); | ||
|
||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.mjml$/, | ||
loader: require.resolve('./mjml-loader.js') | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
<mjml> | ||
<mj-head> | ||
<mj-title><%= title %></mj-title> | ||
<mj-title> | ||
<%= title %> | ||
</mj-title> | ||
|
||
<mj-attributes> | ||
<mj-class name="body-text" font-family="Open Sans, Arial, sans-serif" color="#111111" font-size="16px" line-height="26px" align="center"> | ||
</mj-class> | ||
<mj-class name="body-text" font-family="Open Sans, Arial, sans-serif" color="#111111" font-size="16px" line-height="26px" align="center"></mj-class> | ||
</mj-attributes> | ||
|
||
<mj-font name="Open Sans" href="http://fonts.googleapis.com/css?family=Open+Sans"> | ||
</mj-font> | ||
<mj-font name="Open Sans" href="http://fonts.googleapis.com/css?family=Open+Sans"></mj-font> | ||
</mj-head> | ||
|
||
<mj-body background-color="#ffffff" padding="0px"> | ||
<mj-section background-color="#f0f0f0"> | ||
<mj-section background-color="#fbdde2"> | ||
<mj-column> | ||
<mj-text mj-class="body-text" font-size="20px">Hello, <%= name %>!</mj-text> | ||
<mj-text mj-class="body-text" font-size="20px">Hello, | ||
<%= name %>!</mj-text> | ||
<mj-text align="left" mj-class="body-text"> | ||
I hope you like my imaginary smoothie shop website. You can go back to the | ||
<a href="https://medium.com/@maciejmatu">article</a> if you'd like. Don't worry, you didn't actually order 500,000 smoothies. | ||
If you would like to contact me, feel free to reach out on | ||
<a href="https://medium.com/@maciejmatu">article</a> if you'd like. Don't worry, you didn't actually order 500,000 smoothies. If you would like to contact me, feel free to reach out on | ||
<a target="_blank" rel="noopener" href="https://www.linkedin.com/in/maciej-matuszewski-5087a975/">linked.in</a>, | ||
<a target="_blank" rel="noopener" href="http://github.com/maciejmatu">github</a> or send me a message at | ||
<a href="mailto:[email protected]">[email protected]</a> | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> | ||
|
||
<mj-section padding-top="0"> | ||
<mj-section background-color="#f0f0f0"> | ||
<mj-column> | ||
<mj-social font-size="12px" icon-size="30px" mode="horizontal"> | ||
<mj-social-element border-radius="4px" name="twitter" href="https://mjml.io/"></mj-social-element> | ||
<mj-social-element border-radius="4px" name="twitter" href="https://twitter.com/maciej_matu"></mj-social-element> | ||
|
||
<mj-social-element border-radius="4px" name="linkedin" href="https://www.linkedin.com/in/maciej-matuszewski-5087a975/"></mj-social-element> | ||
<mj-social-element border-radius="4px" name="linkedin" href="https://www.linkedin.com/in/maciej-matuszewski-5087a975/"></mj-social-element> | ||
</mj-social> | ||
</mj-column> | ||
</mj-section> | ||
|
||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
const mjml2html = require('mjml'); | ||
|
||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ test: /\.mjml$/, loader: 'mjml-loader' } | ||
{ | ||
test: /\.mjml$/, | ||
loader: function(content) { | ||
const result = mjml2html(content); | ||
|
||
return `module.exports = ${JSON.stringify(result.html)};`; | ||
} | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.