-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminify.js
More file actions
47 lines (44 loc) · 1.37 KB
/
minify.js
File metadata and controls
47 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { minify as minifyJS } from 'npm:terser'
import { minify as minifyHTML } from 'npm:html-minifier-next'
const toKB = n => `${(n / 1000).toFixed(2)}kb`
const minifyOpts = {
caseSensitive: false,
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
html5: true,
includeAutoGeneratedTags: true,
keepClosingSlash: false,
maxLineLength: false,
minifyCSS: true,
minifyJS: async js => (await minifyJS(js)).code,
minifyURLs: true,
preserveLineBreaks: false,
preventAttributesEscaping: true,
processConditionalComments: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeEmptyElements: false,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeTagWhitespace: true,
sortAttributes: true,
sortClassName: true,
trimCustomFragments: true,
useShortDoctype: true,
}
export const minify = async () => {
const file = await Deno.readTextFile('index.html')
const content = await minifyHTML(file, minifyOpts)
console.log(
`index.html: ${toKB(content.length)}`,
`(${toKB(file.length - content.length)} saved)`,
)
await Deno.mkdir('build', { recursive: true })
return Deno.writeTextFile('build/index.html', content)
}