@@ -10,29 +10,46 @@ import (
1010esbuildApi "github.com/evanw/esbuild/pkg/api"
1111)
1212
13- func BuildFile (filePath , props string ) (string , error ){
13+ func BuildFile (filePath , props string ) (CachedBuild , error ){
14+ var cachedBuild CachedBuild
1415// Get the path of the renderer file
1516 newFilePath , err := makeRendererFile (filePath , props )
1617 if err != nil {
17- return "" , err
18+ return cachedBuild , err
1819 }
1920 result := esbuildApi .Build (esbuildApi.BuildOptions {
2021 EntryPoints : []string {newFilePath },
2122 Bundle : true ,
2223 MinifyWhitespace : true ,
2324 MinifyIdentifiers : true ,
2425 MinifySyntax : true ,
25- // Outfile: ".tmp/out.js",
26+ Outdir : "/Users/nwong/Code/go-ssr/.tmp" ,
27+ Loader : map [string ]esbuildApi.Loader {
28+ ".png" : esbuildApi .LoaderDataURL ,
29+ ".svg" : esbuildApi .LoaderDataURL ,
30+ ".jpg" : esbuildApi .LoaderDataURL ,
31+ ".jpeg" : esbuildApi .LoaderDataURL ,
32+ ".gif" : esbuildApi .LoaderDataURL ,
33+ ".bmp" : esbuildApi .LoaderDataURL ,
34+ },
35+ // Outfile: "/Users/nwong/Code/go-ssr/tmp/out.js",
2636 })
2737 err = os .Remove (newFilePath )
2838 if err != nil {
29- return "" , err
39+ return cachedBuild , err
3040 }
3141 if len (result .Errors ) > 0 {
32- return "" , errors .New (result .Errors [0 ].Text )
42+ return cachedBuild , errors .New (result .Errors [0 ].Text )
43+ }
44+ cachedBuild .CompiledJS = string (result .OutputFiles [0 ].Contents )
45+ for _ , file := range result .OutputFiles {
46+ if (strings .HasSuffix (string (file .Path ), ".css" )){
47+ cachedBuild .CompiledCSS = string (file .Contents )
48+ break
49+ }
3350 }
34- // Return the compiled Javascript
35- return string ( result . OutputFiles [ 0 ]. Contents ) , nil
51+ // Return the compiled build
52+ return cachedBuild , nil
3653}
3754
3855// Creates a temporary file that imports the file to be rendered
0 commit comments