Skip to content

Commit

Permalink
Merge pull request #270 from Thomascogez/feature/replace-html-minifie…
Browse files Browse the repository at this point in the history
…r-with-htmlnano

Feature/replace html minifier with htmlnano
  • Loading branch information
Thomascogez committed Jul 20, 2024
2 parents 973bf94 + 030d7b6 commit 430aad5
Show file tree
Hide file tree
Showing 11 changed files with 9,491 additions and 3,880 deletions.
36 changes: 36 additions & 0 deletions MIGRATION_GUIDES/FROM_1.3.X_TO_1.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Migration Guide from 1.3.x to 1.4.0

## Breaking Changes
- `html-minifier` has been removed from the dependencies and it's now replaced by `htmlnano` (as a peer dependency) (reported by #268).
- The `minifyHtmlOutput` is now `false` by default, since `htmlnano` require a bit more configuration to work properly.
- The `htmlMinifierOptions` as been rename to `templateMinifierOptions` and it's now an object with the following properties:
- `options`: (optional) Wich is the options object passed to `htmlnano`.
- `preset`: (optional) Which is the preset used by `htmlnano`.

## How to migrate

### 1. Update the `nodemailer-mjml` version

```bash
npm install nodemailer-mjml@latest
or
yarn add nodemailer-mjml@latest
```
### 2. If you where using minifyHtmlOutput, you will need to enable it explicitly in the options

### 3. Install `htmlnano` dependency (as a dev dependency)

```bash
npm install --save-dev htmlnano
or
yarn add -D htmlnano
```
> [!NOTE]
> If you want `html` minification, you will need to also install `posthtml` <br>
> If you want `html` minification, you will need to also install `postcss` and `cssnano` <br>
> If you want `js` minification, you will need to also install `terser` <br>
> If you want `svg` minification, you will need to also install `svgo`
More information about the `htmlnano` options can be found [here](https://htmlnano.netlify.app/).
### 4. Update the plugin options by removing `htmlMinifierOptions` and adding `templateMinifierOptions` with your desired options
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> [!WARNING]
>Migration guide from 1.3.x to 1.4.0 can be found [here](./MIGRATION_GUIDES/FROM_1.3.X_TO_1.4.md)
<h1 align="center">
<br>
Expand Down Expand Up @@ -151,10 +153,8 @@ sendTemplatedEmail();
| templateFolder | string | Path of the dir containing your **MJML** template | undefined |
| templatePartialsFolder? | string | Path relative to **templateFolder**, if defined when using a template layout it will be folder where **nodemailer-mjml** while try to find fallback slots if one or more is undefined | undefined |
| mjmlOptions? | MJMLParsingOptions | Options that would be passed to **MJML** compiler (see more) [mjml doc](https://github.com/mjmlio/mjml) | {validationLevel: "strict"} |
| minifyHtmlOutput? | boolean | use to enable/disable html minification using **html-minifier** | true |
| htmlMinifierOptions? | Options | Options that would be passed to **html-minifier** (see more) [html-minifier doc](https://github.com/kangax/html-minifier) | undefined |

### Send mail options
| minifyHtmlOutput? | boolean | use to enable/disable html minification using **htmlnano**, if enabled make sure to install **htmlnano** as a devdependencies | false |
| htmlMinifierOptions? | {options?: HtmlnanoOptions; preset?: HtmlnanoPreset} | Options that would be passed to **htmlnano** (see more) [htmlnano doc](https://htmlnano.netlify.app/) | undefined |

> **nodemailer-mjml** bring 4 new params to the `sendMail` function
Expand Down
4,056 changes: 796 additions & 3,260 deletions __tests__/unit/__snapshots__/template_render.spec.ts.snap

Large diffs are not rendered by default.

62 changes: 58 additions & 4 deletions __tests__/unit/template_render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ describe("Template render", () => {
const buildedTemplate = await buildMjmlTemplate({
templateFolder: join(__dirname, "../resources"),
minifyHtmlOutput: true,
templateMinifierOptions: {
options: {
removeComments: false,
collapseWhitespace: "all",
minifyCss: true,
minifyJs: false,
minifySvg: false,
},
}
}, {
templateName: "test",
});
Expand Down Expand Up @@ -58,6 +67,15 @@ describe("Template render", () => {
const buildedTemplate = await buildMjmlTemplate({
templateFolder: join(__dirname, "../resources"),
minifyHtmlOutput: true,
templateMinifierOptions: {
options: {
removeComments: false,
collapseWhitespace: "all",
minifyCss: true,
minifyJs: false,
minifySvg: false,
},
}
}, {
templateName: "test-mustache",
templateData
Expand Down Expand Up @@ -87,7 +105,16 @@ describe("Template render", () => {
const buildedTemplate = await buildMjmlTemplate({
templateFolder: join(__dirname, "../resources"),
templatePartialsFolder: "/include",
minifyHtmlOutput: true
minifyHtmlOutput: true,
templateMinifierOptions: {
options: {
removeComments: false,
collapseWhitespace: "all",
minifyCss: true,
minifyJs: false,
minifySvg: false,
},
}
}, {
templateLayoutName: "layout/layout-single-slot"
});
Expand All @@ -111,7 +138,16 @@ describe("Template render", () => {
it("should send an email with a layout and fallback header with html minification and snapshot should match", async () => {
const buildedTemplate = await buildMjmlTemplate({
templateFolder: join(__dirname, "../resources"),
minifyHtmlOutput: true
minifyHtmlOutput: true,
templateMinifierOptions: {
options: {
removeComments: false,
collapseWhitespace: "all",
minifyCss: true,
minifyJs: false,
minifySvg: false,
},
}
}, {
templateLayoutName: "layout/layout-single-slot"
});
Expand Down Expand Up @@ -163,7 +199,16 @@ describe("Template render", () => {
const buildedTemplate = await buildMjmlTemplate({
templateFolder: join(__dirname, "../resources"),
templatePartialsFolder: "/include",
minifyHtmlOutput: true
minifyHtmlOutput: true,
templateMinifierOptions: {
options: {
removeComments: false,
collapseWhitespace: "all",
minifyCss: true,
minifyJs: false,
minifySvg: false,
},
}
}, {
templateLayoutName: "layout/layout-single-slot",
templateLayoutSlots,
Expand Down Expand Up @@ -215,7 +260,16 @@ describe("Template render", () => {

const buildedTemplate = await buildMjmlTemplate({
templateFolder: join(__dirname, "../resources"),
minifyHtmlOutput: true
minifyHtmlOutput: true,
templateMinifierOptions: {
options: {
removeComments: false,
collapseWhitespace: "all",
minifyCss: true,
minifyJs: false,
minifySvg: false,
},
}
}, {
templateLayoutName: "layout/layout-single-slot",
templateLayoutSlots,
Expand Down
Loading

0 comments on commit 430aad5

Please sign in to comment.