@@ -10,7 +10,11 @@ import { exec } from "child_process";
10
10
import mime from "mime" ;
11
11
import workerpool from "workerpool" ;
12
12
import os from "os" ;
13
- const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
13
+ import process from "process" ;
14
+ import { minify } from "html-minifier" ;
15
+
16
+ const __filename = fileURLToPath ( import . meta. url ) ;
17
+ const __dirname = dirname ( __filename ) ;
14
18
15
19
export const distDir = join ( __dirname , "../dist" ) ;
16
20
export const docsDir = join ( __dirname , "../docs" ) ;
@@ -30,6 +34,9 @@ console.timeEnd("HTML 生成");
30
34
console . time ( "gzip 压缩" ) ;
31
35
await compression ( ) ;
32
36
console . timeEnd ( "gzip 压缩" ) ;
37
+ if ( process . argv [ 1 ] === __filename ) {
38
+ process . exit ( 0 ) ;
39
+ }
33
40
34
41
export async function build ( ) {
35
42
await clean ( ) ;
@@ -38,6 +45,20 @@ export async function build() {
38
45
genContent ( ) ,
39
46
] ) ;
40
47
template = template . replaceAll ( "{{content}}" , content ) ;
48
+ template = minify ( template , {
49
+ collapseWhitespace : true ,
50
+ conservativeCollapse : true ,
51
+ minifyCSS : true ,
52
+ minifyJS : true ,
53
+ minifyURLs : true ,
54
+ removeComments : true ,
55
+ removeRedundantAttributes : true ,
56
+ removeScriptTypeAttributes : true ,
57
+ removeStyleLinkTypeAttributes : true ,
58
+ sortAttributes : true ,
59
+ sortClassName : true ,
60
+ useShortDoctype : true ,
61
+ } ) ;
41
62
await genDir ( docsDir , publicDir , themeDir ) ;
42
63
}
43
64
0 commit comments