-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(minify-preset)!: initial release (#172)
- Loading branch information
1 parent
afd9ca8
commit 7e68749
Showing
5 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# https://moonrepo.dev/docs/config/tasks | ||
$schema: 'https://moonrepo.dev/schemas/tasks.json' | ||
|
||
workspace: | ||
inheritedTasks: | ||
exclude: ['compile'] | ||
|
||
tasks: | ||
build: | ||
command: rm -f tsconfig.json | ||
deps: | ||
- ~:clean.dist | ||
- ~:compile | ||
inputs: | ||
- src | ||
- package.json | ||
options: | ||
cache: false | ||
outputStyle: 'stream' | ||
runDepsInParallel: false | ||
|
||
compile: | ||
command: tsup --config tsup.config.ts | ||
inputs: | ||
- src | ||
- package.json | ||
deps: | ||
- ~:tsconfig.link | ||
options: | ||
runDepsInParallel: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"name": "@jsx-email/minify-preset", | ||
"version": "0.0.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "A rehype-minify preset for jsx-email", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/shellscape/jsx-email.git", | ||
"directory": "packages/minify-preset" | ||
}, | ||
"author": "Andrew Powell <andrew@shellscape.org>", | ||
"homepage": "https://jsx.email/", | ||
"bugs": "https://github.com/rehypejs/rehype-minify/issues", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"files": [ | ||
"dist/**" | ||
], | ||
"keywords": [ | ||
"email", | ||
"html", | ||
"jsx", | ||
"jsx-email", | ||
"mangle", | ||
"min", | ||
"minify", | ||
"plugin", | ||
"preset", | ||
"react", | ||
"rehype", | ||
"rehype-plugin", | ||
"unified" | ||
], | ||
"dependencies": { | ||
"rehype-minify-attribute-whitespace": "^4.0.0", | ||
"rehype-minify-css-style": "^4.0.0", | ||
"rehype-minify-enumerated-attribute": "^5.0.0", | ||
"rehype-minify-media-attribute": "^4.0.0", | ||
"rehype-minify-meta-color": "^4.0.0", | ||
"rehype-minify-meta-content": "^4.0.0", | ||
"rehype-minify-style-attribute": "^4.0.0", | ||
"rehype-minify-whitespace": "^6.0.0", | ||
"rehype-normalize-attribute-value-case": "^4.0.0", | ||
"rehype-remove-comments": "^6.0.0", | ||
"rehype-remove-duplicate-attribute-values": "^4.0.0", | ||
"rehype-remove-empty-attribute": "^4.0.0", | ||
"rehype-remove-external-script-content": "^4.0.0", | ||
"rehype-remove-meta-http-equiv": "^4.0.0", | ||
"rehype-remove-style-type-css": "^4.0.0", | ||
"rehype-sort-attribute-values": "^5.0.0", | ||
"rehype-sort-attributes": "^5.0.0", | ||
"unified": "^11.0.0" | ||
}, | ||
"types": "dist/index.d.mts", | ||
"funding": { | ||
"type": "github", | ||
"url": "https://github.com/sponsors/shellscape" | ||
}, | ||
"sideEffects": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Pluggable, Preset, Settings } from 'unified'; | ||
|
||
// Note: rehype is all ESM-only, so for CJS compat we're dynamically importing | ||
// No, we're not going to force ESM on users' | ||
const importPlugins = async () => { | ||
const rehypeMinifyAttributeWhitespace = await import('rehype-minify-attribute-whitespace'); | ||
const rehypeMinifyCssStyle = await import('rehype-minify-css-style'); | ||
const rehypeMinifyEnumeratedAttribute = await import('rehype-minify-enumerated-attribute'); | ||
const rehypeMinifyMediaAttribute = await import('rehype-minify-media-attribute'); | ||
const rehypeMinifyMetaColor = await import('rehype-minify-meta-color'); | ||
const rehypeMinifyMetaContent = await import('rehype-minify-meta-content'); | ||
const rehypeMinifyStyleAttribute = await import('rehype-minify-style-attribute'); | ||
const rehypeMinifyWhitespace = await import('rehype-minify-whitespace'); | ||
const rehypeNormalizeAttributeValueCase = await import('rehype-normalize-attribute-value-case'); | ||
const rehypeRemoveComments = await import('rehype-remove-comments'); | ||
const rehypeRemoveDuplicateAttributeValues = await import( | ||
'rehype-remove-duplicate-attribute-values' | ||
); | ||
const rehypeRemoveEmptyAttribute = await import('rehype-remove-empty-attribute'); | ||
const rehypeRemoveExternalScriptContent = await import('rehype-remove-external-script-content'); | ||
const rehypeRemoveMetaHttpEquiv = await import('rehype-remove-meta-http-equiv'); | ||
const rehypeRemoveStyleTypeCss = await import('rehype-remove-style-type-css'); | ||
const rehypeSortAttributeValues = await import('rehype-sort-attribute-values'); | ||
const rehypeSortAttributes = await import('rehype-sort-attributes'); | ||
|
||
return [ | ||
rehypeMinifyAttributeWhitespace, | ||
rehypeMinifyCssStyle, | ||
// Note: `rehypeRemoveMetaHttpEquiv` goes before | ||
// `rehypeMinifyEnumeratedAttribute`, as the latter might minify things further. | ||
rehypeRemoveMetaHttpEquiv, | ||
rehypeMinifyEnumeratedAttribute, | ||
rehypeMinifyMediaAttribute, | ||
rehypeMinifyMetaColor, | ||
rehypeMinifyMetaContent, | ||
rehypeMinifyStyleAttribute, | ||
rehypeMinifyWhitespace, | ||
rehypeNormalizeAttributeValueCase, | ||
rehypeRemoveComments, | ||
rehypeRemoveDuplicateAttributeValues, | ||
rehypeRemoveEmptyAttribute, | ||
rehypeRemoveExternalScriptContent, | ||
rehypeRemoveStyleTypeCss, | ||
rehypeSortAttributeValues, | ||
rehypeSortAttributes | ||
] as Pluggable[]; | ||
}; | ||
|
||
const settings = { | ||
allowParseErrors: true, | ||
bogusComments: true, | ||
characterReferences: { | ||
omitOptionalSemicolons: true, | ||
useShortestReferences: true | ||
}, | ||
closeEmptyElements: true, | ||
collapseEmptyAttributes: true, | ||
omitOptionalTags: true, | ||
preferUnquoted: true, | ||
quoteSmart: true, | ||
tightAttributes: true, | ||
tightCommaSeparatedLists: true, | ||
tightDoctype: true, | ||
tightSelfClosing: true | ||
} as Settings; | ||
|
||
export const minifyPreset = async (): Promise<Preset> => { | ||
const plugins = await importPlugins(); | ||
|
||
return { plugins, settings }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-default-export */ | ||
import { defineConfig } from 'tsup'; | ||
|
||
export default defineConfig({ | ||
clean: true, | ||
dts: true, | ||
entry: ['src/index.ts'], | ||
format: ['cjs', 'esm'], | ||
keepNames: true, | ||
outDir: 'dist', | ||
sourcemap: true, | ||
target: ['es2022', 'node18'] | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.