npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mjml-with-images-loader

v2.0.1

Published

MJML loader for webpack with images

Downloads

109

Readme

MJML loader for Webpack

Converts MJML files with images to HTML and exports them as string or as Nodemailer config. Images will be inserted as base64 data.

Images should have relative paths (starting from ./ or ../). Such files resolved and inserted as base64 strings (see examples below).

This package adds dependencies to Webpack for included mjml templates <mj-include path="./some_other.mjml" />. So if you change included file, also will be regenerated depended files.

Install

npm install --save-dev mjml-with-images-loader mjml

Usage

Documentation: Using loaders

Example 1 (for passing to Nodemailer)

With this configuration:

{
    module: {
      loaders: [
        { test: /\.mjml$/, loader: 'mjml-with-images-loader' }
      ]
    }
}

template.mjml

 <mjml>
  <mj-body>
    <mj-container>
      <mj-section>
        <mj-column>
          <mj-text>Hello World!</mj-text>
          <mj-image src="./pic.jpg" width="480px" padding-top="20px"></mj-image>
        </mj-column>
      </mj-section>
    </mj-container>
  </mj-body>
</mjml>

index.js

const template = require('./template.mjml');
console.log(template);

console.log output (compatible with Nodemailer configuration):

{
  html: '<html> ... <img src="cid:1234"></img> ... </html>',
  attachments: [{
    filename: '1234.jpg',
    path: 'data:image/jpg;base64,/9j/4RpdRXhpZgAA ...',
    cid: '1234',
  }],
}

Example 2 (with onlyHtml option, for browser rendering)

With this configuration:

{
    module: {
      loaders: [
        { test: /\.mjml$/, loader: 'mjml-with-images-loader?onlyHtml' }
      ]
    }
}

template.mjml

 <mjml>
  <mj-body>
    <mj-container>
      <mj-section>
        <mj-column>
          <mj-text>Hello World!</mj-text>
          <mj-image src="./pic.jpg" width="480px" padding-top="20px"></mj-image>
        </mj-column>
      </mj-section>
    </mj-container>
  </mj-body>
</mjml>

index.js

const template = require('./template.mjml');
console.log(template);

console.log output (ready to display on web-page via <iframe srcDoc={template} height="100%" width="100%" />):

'<html> ... <img src="data:image/jpg;base64,/9j/4RpdRXhpZgAA ..."></img> ... </html>'

License

MIT (http://www.opensource.org/licenses/mit-license.php)