11import * as esbuild from "https://deno.land/x/[email protected] /mod.js" ; 22import { copy } from "https://deno.land/[email protected] /fs/mod.ts" ; 3- import { minify as minifyCss } from "https://esm.sh/[email protected] " ; 3+ import init , { minify } from "https://wilsonl.in/minify-html/deno/0.9.2/index.js" ;
4+
5+ await init ( ) ;
6+ const encoder = new TextEncoder ( ) ;
7+ const decoder = new TextDecoder ( ) ;
48
59export async function buildComponent ( componentName : string ) {
610 console . log ( `Building ${ componentName } ` ) ;
@@ -47,6 +51,11 @@ async function copy_files(componentName: string) {
4751 await copyCSSFiles ( `${ srcFolder } /${ entry . name } ` , `${ distFolder } /${ entry . name } ` ) ;
4852 continue ;
4953 }
54+
55+ if ( entry . name . endsWith ( ".html" ) ) {
56+ await copyHTMLFiles ( `${ srcFolder } /${ entry . name } ` , `${ distFolder } /${ entry . name } ` ) ;
57+ continue ;
58+ }
5059
5160 const srcPath = `${ srcFolder } /${ entry . name } ` ;
5261 const distPath = `${ distFolder } /${ entry . name } ` ;
@@ -56,12 +65,26 @@ async function copy_files(componentName: string) {
5665
5766async function copyCSSFiles ( srcFile : string , distFile : string ) {
5867 const css = await Deno . readTextFile ( srcFile ) ;
59- const result = await minifyCss ( css ) ;
60- await Deno . writeTextFile ( distFile , result . css ) ;
68+
69+ const result = await esbuild . transform ( css , {
70+ loader : "css" ,
71+ minify : true ,
72+ } ) ;
73+
74+ await Deno . writeTextFile ( distFile , result . code ) ;
6175}
6276
63- async function copyHTMLFiles ( srcFolder : string , distFolder : string ) {
77+ async function copyHTMLFiles ( srcFolder : string , distFile : string ) {
78+ const html = await Deno . readTextFile ( srcFolder ) ;
79+
80+ const result = decoder . decode ( minify ( encoder . encode ( html ) , {
81+ minify_css : true ,
82+ minify_js : true ,
83+ do_not_minify_doctype : true ,
84+ keep_closing_tags : true
85+ } ) ) ;
6486
87+ await Deno . writeTextFile ( distFile , result ) ;
6588}
6689
6790async function copyFilesToFolder ( sourceDir : string , targetDir : string ) {
0 commit comments