Skip to content

Commit 7e68749

Browse files
authored
feat(minify-preset)!: initial release (#172)
1 parent afd9ca8 commit 7e68749

File tree

5 files changed

+250
-0
lines changed

5 files changed

+250
-0
lines changed

packages/minify-preset/moon.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://moonrepo.dev/docs/config/tasks
2+
$schema: 'https://moonrepo.dev/schemas/tasks.json'
3+
4+
workspace:
5+
inheritedTasks:
6+
exclude: ['compile']
7+
8+
tasks:
9+
build:
10+
command: rm -f tsconfig.json
11+
deps:
12+
- ~:clean.dist
13+
- ~:compile
14+
inputs:
15+
- src
16+
- package.json
17+
options:
18+
cache: false
19+
outputStyle: 'stream'
20+
runDepsInParallel: false
21+
22+
compile:
23+
command: tsup --config tsup.config.ts
24+
inputs:
25+
- src
26+
- package.json
27+
deps:
28+
- ~:tsconfig.link
29+
options:
30+
runDepsInParallel: false

packages/minify-preset/package.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"name": "@jsx-email/minify-preset",
3+
"version": "0.0.0",
4+
"publishConfig": {
5+
"access": "public"
6+
},
7+
"description": "A rehype-minify preset for jsx-email",
8+
"license": "MIT",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/shellscape/jsx-email.git",
12+
"directory": "packages/minify-preset"
13+
},
14+
"author": "Andrew Powell <andrew@shellscape.org>",
15+
"homepage": "https://jsx.email/",
16+
"bugs": "https://github.com/rehypejs/rehype-minify/issues",
17+
"main": "dist/index.js",
18+
"module": "dist/index.mjs",
19+
"exports": {
20+
".": {
21+
"import": {
22+
"types": "./dist/index.d.mts",
23+
"default": "./dist/index.mjs"
24+
},
25+
"require": {
26+
"types": "./dist/index.d.ts",
27+
"default": "./dist/index.js"
28+
}
29+
},
30+
"./package.json": "./package.json"
31+
},
32+
"engines": {
33+
"node": ">=18.0.0"
34+
},
35+
"files": [
36+
"dist/**"
37+
],
38+
"keywords": [
39+
"email",
40+
"html",
41+
"jsx",
42+
"jsx-email",
43+
"mangle",
44+
"min",
45+
"minify",
46+
"plugin",
47+
"preset",
48+
"react",
49+
"rehype",
50+
"rehype-plugin",
51+
"unified"
52+
],
53+
"dependencies": {
54+
"rehype-minify-attribute-whitespace": "^4.0.0",
55+
"rehype-minify-css-style": "^4.0.0",
56+
"rehype-minify-enumerated-attribute": "^5.0.0",
57+
"rehype-minify-media-attribute": "^4.0.0",
58+
"rehype-minify-meta-color": "^4.0.0",
59+
"rehype-minify-meta-content": "^4.0.0",
60+
"rehype-minify-style-attribute": "^4.0.0",
61+
"rehype-minify-whitespace": "^6.0.0",
62+
"rehype-normalize-attribute-value-case": "^4.0.0",
63+
"rehype-remove-comments": "^6.0.0",
64+
"rehype-remove-duplicate-attribute-values": "^4.0.0",
65+
"rehype-remove-empty-attribute": "^4.0.0",
66+
"rehype-remove-external-script-content": "^4.0.0",
67+
"rehype-remove-meta-http-equiv": "^4.0.0",
68+
"rehype-remove-style-type-css": "^4.0.0",
69+
"rehype-sort-attribute-values": "^5.0.0",
70+
"rehype-sort-attributes": "^5.0.0",
71+
"unified": "^11.0.0"
72+
},
73+
"types": "dist/index.d.mts",
74+
"funding": {
75+
"type": "github",
76+
"url": "https://github.com/sponsors/shellscape"
77+
},
78+
"sideEffects": false
79+
}

packages/minify-preset/src/index.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import type { Pluggable, Preset, Settings } from 'unified';
2+
3+
// Note: rehype is all ESM-only, so for CJS compat we're dynamically importing
4+
// No, we're not going to force ESM on users'
5+
const importPlugins = async () => {
6+
const rehypeMinifyAttributeWhitespace = await import('rehype-minify-attribute-whitespace');
7+
const rehypeMinifyCssStyle = await import('rehype-minify-css-style');
8+
const rehypeMinifyEnumeratedAttribute = await import('rehype-minify-enumerated-attribute');
9+
const rehypeMinifyMediaAttribute = await import('rehype-minify-media-attribute');
10+
const rehypeMinifyMetaColor = await import('rehype-minify-meta-color');
11+
const rehypeMinifyMetaContent = await import('rehype-minify-meta-content');
12+
const rehypeMinifyStyleAttribute = await import('rehype-minify-style-attribute');
13+
const rehypeMinifyWhitespace = await import('rehype-minify-whitespace');
14+
const rehypeNormalizeAttributeValueCase = await import('rehype-normalize-attribute-value-case');
15+
const rehypeRemoveComments = await import('rehype-remove-comments');
16+
const rehypeRemoveDuplicateAttributeValues = await import(
17+
'rehype-remove-duplicate-attribute-values'
18+
);
19+
const rehypeRemoveEmptyAttribute = await import('rehype-remove-empty-attribute');
20+
const rehypeRemoveExternalScriptContent = await import('rehype-remove-external-script-content');
21+
const rehypeRemoveMetaHttpEquiv = await import('rehype-remove-meta-http-equiv');
22+
const rehypeRemoveStyleTypeCss = await import('rehype-remove-style-type-css');
23+
const rehypeSortAttributeValues = await import('rehype-sort-attribute-values');
24+
const rehypeSortAttributes = await import('rehype-sort-attributes');
25+
26+
return [
27+
rehypeMinifyAttributeWhitespace,
28+
rehypeMinifyCssStyle,
29+
// Note: `rehypeRemoveMetaHttpEquiv` goes before
30+
// `rehypeMinifyEnumeratedAttribute`, as the latter might minify things further.
31+
rehypeRemoveMetaHttpEquiv,
32+
rehypeMinifyEnumeratedAttribute,
33+
rehypeMinifyMediaAttribute,
34+
rehypeMinifyMetaColor,
35+
rehypeMinifyMetaContent,
36+
rehypeMinifyStyleAttribute,
37+
rehypeMinifyWhitespace,
38+
rehypeNormalizeAttributeValueCase,
39+
rehypeRemoveComments,
40+
rehypeRemoveDuplicateAttributeValues,
41+
rehypeRemoveEmptyAttribute,
42+
rehypeRemoveExternalScriptContent,
43+
rehypeRemoveStyleTypeCss,
44+
rehypeSortAttributeValues,
45+
rehypeSortAttributes
46+
] as Pluggable[];
47+
};
48+
49+
const settings = {
50+
allowParseErrors: true,
51+
bogusComments: true,
52+
characterReferences: {
53+
omitOptionalSemicolons: true,
54+
useShortestReferences: true
55+
},
56+
closeEmptyElements: true,
57+
collapseEmptyAttributes: true,
58+
omitOptionalTags: true,
59+
preferUnquoted: true,
60+
quoteSmart: true,
61+
tightAttributes: true,
62+
tightCommaSeparatedLists: true,
63+
tightDoctype: true,
64+
tightSelfClosing: true
65+
} as Settings;
66+
67+
export const minifyPreset = async (): Promise<Preset> => {
68+
const plugins = await importPlugins();
69+
70+
return { plugins, settings };
71+
};

packages/minify-preset/tsup.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable import/no-extraneous-dependencies, import/no-default-export */
2+
import { defineConfig } from 'tsup';
3+
4+
export default defineConfig({
5+
clean: true,
6+
dts: true,
7+
entry: ['src/index.ts'],
8+
format: ['cjs', 'esm'],
9+
keepNames: true,
10+
outDir: 'dist',
11+
sourcemap: true,
12+
target: ['es2022', 'node18']
13+
});

pnpm-lock.yaml

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)