xyproto/algernon

Integrate pure-go Svelte compiler just like plenti

diyism opened this issue · 7 comments

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.

Lots of interesting data here: plentico/plenti#3

And follow-up here: plentico/plenti#169

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

@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

Thanks for the feature request!

Hey 👋

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!

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

diyism commented

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

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: plentico/plenti#276
ref: terrywh/svelte-bun#2