xyproto / algernon

Small self-contained pure-Go web server with Lua, Teal, Markdown, Ollama, HTTP/2, QUIC, Redis, SQLite and PostgreSQL support ++
https://algernon.roboticoverlords.org
BSD 3-Clause "New" or "Revised" License
2.79k stars 137 forks source link

Integrate pure-go Svelte compiler just like plenti #125

Open diyism opened 1 year ago

diyism commented 1 year ago

The project Plenti(https://github.com/plentico/plenti) has built-in pure-go Svelte compiler, I'm dreaming an algernon version of built-in Svelete compiler.

tooolbox commented 1 year ago

Lots of interesting data here: https://github.com/plentico/plenti/issues/3

And follow-up here: https://github.com/plentico/plenti/issues/169

Looks like Matthew Mueller wound up using v8 for Bud though: https://github.com/livebud/bud/tree/de977798451d9b3f84695254a84377581a653286/package/svelte

diyism commented 1 year ago

@tooolbox yes, the plenti(v8go) performance is very close to the nodejs: Screenshot 2022-11-15 at 14-20-32 Remove nodejs dependency · Issue #3 · plentico_plenti

xyproto commented 1 year ago

Thanks for the feature request!

jimafisk commented 1 year ago

Hey :wave:

Achieving a zero dependency, reactive UI for Go is a problem we're still trying to solve with Plenti. We're currently compiling Svelte in V8 at the moment, and that works, but it's not without blemishes. If you're ever interested in talking through what we've tried, I'd be happy to hop on a call. Thanks!

xyproto commented 1 year ago

@jimafisk Sounds interesting! 👍 I'm on vacation, but I want to take a look at Plenti when I get back.

diyism commented 1 year ago

I found svelte-bun (https://github.com/terrywh/svelte-bun) which realized realtime building of svelte components on dev environment. The performance of Bun is touted to be twice that of Deno and six times that of Node. But Bun is not on golang.

diyism commented 11 months ago

I've tested svelte-bun with bun, its performance is amazing, the building is realtime. And I've tried to run svelte-bun with v8go, but I failed.

I packaged the whole svelte-bun project with: ./node_modules/.bin/esbuild ./sbin/server.js --bundle --outfile=out.js --format=esm --platform=node then run it with test.go:

package main

import (
    "fmt"
    "io/ioutil"

    v8 "rogchap.com/v8go"
)

func main() {
    js, _ := ioutil.ReadFile("./out.js")
    ctx:= v8.NewContext()
    val, err := ctx.RunScript(string(js), "main.js")
    if err != nil {
        fmt.Printf("failed to run JavaScript file: %v\n", err)
        return
    }

    fmt.Println(val)
}

it shows error: failed to run JavaScript file: SyntaxError: Cannot use import statement outside a module

I guess the corresponding lines are:

import { stat as asyncStat } from "fs/promises";
import { extname, join as join2 } from "path";
import { resolve as resolve2 } from "path";

Maybe an experienced guy can work around it, but I can't.

ref: https://github.com/plentico/plenti/issues/276 ref: https://github.com/terrywh/svelte-bun/issues/2