import { unknownElement } from "@opticss/element-analysis" ; import { Template , TemplateAnalysis , TemplateIntegrationOptions } from "@opticss/template-api" ; import * as fs from "fs" ; import { OptiCSSOptions , Optimizer } from "opticss" ; const options = { rewriteIdents : { id : false , class : true } , } ; const templateOptions = { rewriteIdents : { id : false , class : true } , analyzedTagnames : true , } ; let opticss = new Optimizer ( options , templateOptions ) ; let cssFile = "build/assets/myapp.css" ; opticss . addSource ( { filename : cssFile , content : fs . readFileSync ( cssFile , "utf-8" ) , sourceMap : fs . readFileSync ( `${ cssFile }.map` , "utf-8" ) , } ) ; let analysis = new TemplateAnalysis ( new Template ( "unknown.html" ) ) ; analysis . elements . push ( unknownElement ( ) ) ; opticss . addAnalysis ( analysis ) ; let outputName = "build/assets/optimized.css" ; opticss . optimize ( outputName ) . then ( result => { fs . writeFileSync ( outputName , result . output . content . toString ( ) , "utf-8" ) ; fs . writeFileSync ( `${ outputName }.log` , result . actions . logStrings ( ) . join ( "\n" ) , "utf-8" ) ; if ( result . output . sourceMap ) { fs . writeFileSync ( `${ outputName }.map` , result . output . sourceMap , "utf-8" ) ; } } ) ;