├── test-img.jpg ├── test-include.mjml ├── .github ├── FUNDING.yml └── workflows │ └── nodejs.yml ├── .gitignore ├── LICENSE ├── package.json ├── README.md ├── index.js └── __tests__ ├── index-test.js └── __snapshots__ └── index-test.js.snap /test-img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nodkz/mjml-with-images-loader/HEAD/test-img.jpg -------------------------------------------------------------------------------- /test-include.mjml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | INCLUDED MESSAGE 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [nodkz] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # graphql-compose 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: [push, pull_request] 7 | 8 | jobs: 9 | publish: 10 | if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta' 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Use Node.js 14 15 | uses: actions/setup-node@v2 16 | with: 17 | node-version: 14 18 | - name: Install node_modules 19 | run: yarn install 20 | - name: Build 21 | run: yarn build 22 | - name: Semantic Release (publish to npm) 23 | run: yarn semantic-release 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ramiro Silveyra d'Avila 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mjml-with-images-loader", 3 | "version": "0.0.0-semantically-released", 4 | "description": "MJML loader for webpack with images", 5 | "main": "index.js", 6 | "files": [ 7 | "index.js" 8 | ], 9 | "scripts": { 10 | "build": "echo \"nothing to build, pack as is\"", 11 | "semantic-release": "semantic-release" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/nodkz/mjml-with-images-loader.git" 16 | }, 17 | "keywords": [ 18 | "mjml", 19 | "webpack", 20 | "images", 21 | "loader" 22 | ], 23 | "author": "Pavel Chertorogov", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/nodkz/mjml-with-images-loader/issues" 27 | }, 28 | "homepage": "https://github.com/nodkz/mjml-with-images-loader#readme", 29 | "dependencies": { 30 | "base64-image-loader": "^1.0.0", 31 | "colors": "1.4.0", 32 | "loader-utils": "^1.1.0" 33 | }, 34 | "peerDependencies": { 35 | "mjml": ">=4.1.0" 36 | }, 37 | "devDependencies": { 38 | "mjml": "4.9.3", 39 | "semantic-release": "^17.4.3" 40 | }, 41 | "jest": { 42 | "roots": [ 43 | "" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MJML loader for Webpack 2 | 3 | Converts MJML files with images to HTML and exports them as string or as Nodemailer config. Images will be inserted as base64 data. 4 | 5 | Images should have relative paths (starting from `./` or `../`). Such files resolved and inserted as base64 strings (see examples below). 6 | 7 | This package adds dependencies to Webpack for included mjml templates ``. So if you change included file, also will be regenerated depended files. 8 | 9 | ## Install 10 | ```js 11 | npm install --save-dev mjml-with-images-loader mjml 12 | ``` 13 | 14 | ## Usage 15 | 16 | [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) 17 | 18 | ## Example 1 (for passing to Nodemailer) 19 | 20 | With this configuration: 21 | ```javascript 22 | { 23 | module: { 24 | loaders: [ 25 | { test: /\.mjml$/, loader: 'mjml-with-images-loader' } 26 | ] 27 | } 28 | } 29 | ``` 30 | `template.mjml` 31 | ```xml 32 | 33 | 34 | 35 | 36 | 37 | Hello World! 38 | 39 | 40 | 41 | 42 | 43 | 44 | ``` 45 | `index.js` 46 | ```javascript 47 | const template = require('./template.mjml'); 48 | console.log(template); 49 | ``` 50 | `console.log` output (compatible with [Nodemailer](https://github.com/nodemailer/nodemailer#e-mail-message-fields) configuration): 51 | ``` 52 | { 53 | html: ' ... ... ', 54 | attachments: [{ 55 | filename: '1234.jpg', 56 | path: 'data:image/jpg;base64,/9j/4RpdRXhpZgAA ...', 57 | cid: '1234', 58 | }], 59 | } 60 | ``` 61 | 62 | ## Example 2 (with `onlyHtml` option, for browser rendering) 63 | 64 | With this configuration: 65 | ```javascript 66 | { 67 | module: { 68 | loaders: [ 69 | { test: /\.mjml$/, loader: 'mjml-with-images-loader?onlyHtml' } 70 | ] 71 | } 72 | } 73 | ``` 74 | `template.mjml` 75 | ```xml 76 | 77 | 78 | 79 | 80 | 81 | Hello World! 82 | 83 | 84 | 85 | 86 | 87 | 88 | ``` 89 | `index.js` 90 | ```javascript 91 | const template = require('./template.mjml'); 92 | console.log(template); 93 | ``` 94 | `console.log` output (ready to display on web-page via `