1
1
import { pluginSymbol , type JsxEmailPlugin } from 'jsx-email' ;
2
- // Note: tshy has some bugs with dual-mode package importing in the cjs build https://github.com/isaacs/tshy/issues/50
3
- // @ts -ignore
4
- import type { Pluggable , Preset , Settings } from 'unified' ;
5
-
6
- // Note: rehype is all ESM-only, so for CJS compat we're dynamically importing
7
- // No, we're not going to force ESM on users
8
- const importPlugins = async ( ) => {
9
- const rehypeMinifyAttributeWhitespace = await import ( 'rehype-minify-attribute-whitespace' ) ;
10
- const rehypeMinifyCssStyle = await import ( 'rehype-minify-css-style' ) ;
11
- const rehypeMinifyEnumeratedAttribute = await import ( 'rehype-minify-enumerated-attribute' ) ;
12
- const rehypeMinifyMediaAttribute = await import ( 'rehype-minify-media-attribute' ) ;
13
- const rehypeMinifyMetaColor = await import ( 'rehype-minify-meta-color' ) ;
14
- const rehypeMinifyMetaContent = await import ( 'rehype-minify-meta-content' ) ;
15
- const rehypeMinifyStyleAttribute = await import ( 'rehype-minify-style-attribute' ) ;
16
- const rehypeMinifyWhitespace = await import ( 'rehype-minify-whitespace' ) ;
17
- const rehypeNormalizeAttributeValueCase = await import ( 'rehype-normalize-attribute-value-case' ) ;
18
- const rehypeRemoveComments = await import ( 'rehype-remove-comments' ) ;
19
- const rehypeRemoveDuplicateAttributeValues = await import (
20
- 'rehype-remove-duplicate-attribute-values'
21
- ) ;
22
- const rehypeRemoveEmptyAttribute = await import ( 'rehype-remove-empty-attribute' ) ;
23
- const rehypeRemoveExternalScriptContent = await import ( 'rehype-remove-external-script-content' ) ;
24
- const rehypeRemoveMetaHttpEquiv = await import ( 'rehype-remove-meta-http-equiv' ) ;
25
- const rehypeRemoveStyleTypeCss = await import ( 'rehype-remove-style-type-css' ) ;
26
- const rehypeSortAttributeValues = await import ( 'rehype-sort-attribute-values' ) ;
27
- const rehypeSortAttributes = await import ( 'rehype-sort-attributes' ) ;
28
-
29
- return [
30
- rehypeMinifyAttributeWhitespace ,
31
- rehypeMinifyCssStyle ,
32
- // Note: `rehypeRemoveMetaHttpEquiv` goes before
33
- // `rehypeMinifyEnumeratedAttribute`, as the latter might minify things further.
34
- rehypeRemoveMetaHttpEquiv ,
35
- rehypeMinifyEnumeratedAttribute ,
36
- rehypeMinifyMediaAttribute ,
37
- rehypeMinifyMetaColor ,
38
- rehypeMinifyMetaContent ,
39
- rehypeMinifyStyleAttribute ,
40
- rehypeMinifyWhitespace ,
41
- rehypeNormalizeAttributeValueCase ,
42
- rehypeRemoveComments ,
43
- rehypeRemoveDuplicateAttributeValues ,
44
- rehypeRemoveEmptyAttribute ,
45
- rehypeRemoveExternalScriptContent ,
46
- rehypeRemoveStyleTypeCss ,
47
- rehypeSortAttributeValues ,
48
- rehypeSortAttributes
49
- ] . map ( ( mod ) => mod . default ) as Pluggable [ ] ;
50
- } ;
2
+ import rehypeMinifyAttributeWhitespace from 'rehype-minify-attribute-whitespace' ;
3
+ import rehypeMinifyCssStyle from 'rehype-minify-css-style' ;
4
+ import rehypeMinifyEnumeratedAttribute from 'rehype-minify-enumerated-attribute' ;
5
+ import rehypeMinifyMediaAttribute from 'rehype-minify-media-attribute' ;
6
+ import rehypeMinifyMetaColor from 'rehype-minify-meta-color' ;
7
+ import rehypeMinifyMetaContent from 'rehype-minify-meta-content' ;
8
+ import rehypeMinifyStyleAttribute from 'rehype-minify-style-attribute' ;
9
+ import rehypeMinifyWhitespace from 'rehype-minify-whitespace' ;
10
+ import rehypeNormalizeAttributeValueCase from 'rehype-normalize-attribute-value-case' ;
11
+ import rehypeRemoveComments from 'rehype-remove-comments' ;
12
+ import rehypeRemoveDuplicateAttributeValues from 'rehype-remove-duplicate-attribute-values' ;
13
+ import rehypeRemoveEmptyAttribute from 'rehype-remove-empty-attribute' ;
14
+ import rehypeRemoveExternalScriptContent from 'rehype-remove-external-script-content' ;
15
+ import rehypeRemoveMetaHttpEquiv from 'rehype-remove-meta-http-equiv' ;
16
+ import rehypeRemoveStyleTypeCss from 'rehype-remove-style-type-css' ;
17
+ import rehypeSortAttributeValues from 'rehype-sort-attribute-values' ;
18
+ import rehypeSortAttributes from 'rehype-sort-attributes' ;
19
+ import type { Preset , Settings } from 'unified' ;
51
20
52
21
const settings = {
53
22
allowParseErrors : true ,
@@ -69,7 +38,27 @@ const settings = {
69
38
export const plugin : JsxEmailPlugin = {
70
39
name : 'root/minify' ,
71
40
process : async ( ) : Promise < Preset > => {
72
- const plugins = await importPlugins ( ) ;
41
+ const plugins = [
42
+ rehypeMinifyAttributeWhitespace ,
43
+ rehypeMinifyCssStyle ,
44
+ // Note: `rehypeRemoveMetaHttpEquiv` goes before
45
+ // `rehypeMinifyEnumeratedAttribute`, as the latter might minify things further.
46
+ rehypeRemoveMetaHttpEquiv ,
47
+ rehypeMinifyEnumeratedAttribute ,
48
+ rehypeMinifyMediaAttribute ,
49
+ rehypeMinifyMetaColor ,
50
+ rehypeMinifyMetaContent ,
51
+ rehypeMinifyStyleAttribute ,
52
+ rehypeMinifyWhitespace ,
53
+ rehypeNormalizeAttributeValueCase ,
54
+ rehypeRemoveComments ,
55
+ rehypeRemoveDuplicateAttributeValues ,
56
+ rehypeRemoveEmptyAttribute ,
57
+ rehypeRemoveExternalScriptContent ,
58
+ rehypeRemoveStyleTypeCss ,
59
+ rehypeSortAttributeValues ,
60
+ rehypeSortAttributes
61
+ ] ;
73
62
74
63
return { plugins, settings } ;
75
64
} ,
0 commit comments