gopherjs / gopherjs.github.io

GopherJS Playground
https://gopherjs.github.io/playground/
23 stars 12 forks source link

Question: (How) Does the GopherJS playground handle includes? #73

Closed Potherca closed 2 years ago

Potherca commented 4 years ago

I have a simple piece of code.

When I run it in the Go Playground it works as expected.

However, when I run similar code in the GopherJS payground it gets an error:

failed to load package "github.com/asciitosvg/asciitosvg" 

Am I doing something wrong or does the GopherJS playground not support includes in the same way the Go Playground does?

Click to expand/collapse code ``` package main import ( "fmt" "github.com/asciitosvg/asciitosvg" ) const logo = ` .-------------------------. | | | .---.-. .-----. .-----. | | | .-. | +--> | | <--+ | | | '-' | | <--+ +--> | | | '---'-' '-----' '-----' | | ascii 2 svg | | | '-------------------------' https://github.com/asciit osvg [1,0]: {"fill":"#88d","a2s:delref":1} ` func main() { input := []byte(logo) font := "Consolas,Monaco,Anonymous Pro,Anonymous,Bitstream Sans Mono,monospace" // Font family to use noBlur := false // Disable drop-shadow blur scaleX := 9 // X grid scale in pixels scaleY := 16 // Y grid scale in pixels tabWidth := 8 // Tab width. canvas, err := asciitosvg.NewCanvas(input, tabWidth, true) if err == nil { svg := asciitosvg.CanvasToSVG(canvas, noBlur, font, scaleX, scaleY) fmt.Printf("%s\n", svg) } } ```
neelance commented 4 years ago

The GopherJS playground currently does not support importing packages that are not part of the standard library.

Potherca commented 4 years ago

Do you happen to know if that is a design choice or if bringing the functionality up to date with the Go Playground (thus allowing includes) will be welcomed as a contribution?

Potherca commented 2 years ago

Closing issue due to lack of activity.

nevkontakte commented 2 years ago

@Potherca I only noticed this issue now, and I'm not the original author of the GopherJS playground, but I would guess that this is probably a technical limitation coming from the fact that the playground is purely client-side.

Standard library packages are precompiled and packaged ahead of time, which allows them to be used. However, to import third-party packages, some kind of backend would have to be implemented and, more importantly, paid for. I presume the latter is why it wasn't done.

dmitshur commented 2 years ago

Also see #26.

Its "Implementation" section discussed two approaches, though more relevant to the GOPATH mode. The Go module mode was added 3 years later and creates new possibilities to fetch dependencies. The module mirror also allows CORS requests. So more frontend heavy implementations (i.e., the GopherJS Playground could download and compile third party dependencies... inside the user's browser) should also be viable now.

Potherca commented 2 years ago

Thanks for the clarification @nevkontakte and @dmitshur!