Closed danchenkov closed 8 years ago
it appears libSass won't create a source map unless you ask it to embed it into the file or give libSass a path to write one. Your example is using file compiling b/c of the libsass.Path() so no source map is being embedded. The file compiler isn't currently working with sourcemaps. I'll publish a fix.
You can try removing libsass.Path() and passing a reader to libsass.New() to get source maps going in your example.
r, _ := os.Open(source_file)
libsass.new(w,r,...)
I pushed a breaking change to the SourceMap call. libSass expects a source map embed or a source map file path in order to generate a source map. pull latest master to see the change.
This generates map files with content
package main
import (
"fmt"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
libsass "github.com/wellington/go-libsass"
)
func main() {
wd, _ := os.Getwd()
http.ListenAndServe(":1111", &SassHandler{Root: wd})
}
type SassHandler struct {
Root string
}
func (h *SassHandler) ServeHTTP(w http.ResponseWriter, reader *http.Request) {
if path.Ext(reader.URL.Path) != ".css" {
return
}
request_file := filepath.Join(h.Root, "assets", reader.URL.Path)
fmt.Println(request_file)
source_file := strings.TrimSuffix(request_file, ".css") + ".scss"
rf, _ := os.Open(source_file)
w.Header().Set("Content-Type", "text/css")
out, _ := os.Create(request_file)
comp, err := libsass.New(out, rf,
libsass.Path(source_file),
libsass.IncludePaths([]string{filepath.Join(h.Root, "assets")}),
// libsass.LineComments(true),
// libsass.Comments(true),
libsass.SourceMap(true, request_file+".map"),
// libsass.OutputStyle(1),
)
if err != nil {
log.Printf("ERROR: libsass error: %#v", err.Error())
http.Error(w, err.Error(), 500)
return
}
if err = comp.Run(); err != nil {
log.Printf("ERROR: libsass compile error: %#v", err.Error())
http.Error(w, err.Error(), 500)
return
}
}
fixed in b03355aa272f6b2d76fa1179ff872219dad34b81
I don't understand why maps are not generated (neither by FileCompile nor Compile) - I get empty output. The code is below, the source maps are enabled in line 40.