←back to thread

153 points yar-kravtsov | 7 comments | | HN request time: 0.001s | source | bottom

I built a Vite plugin that lets you write Go code directly in .js files using a "use golang" directive. It compiles to WebAssembly automatically.
1. tkzed49 ◴[] No.45719084[source]
Beautiful. Minor feedback: rather than having a "use golang" directive, just allow imports of .go files. This is more idiomatic for JS bundlers.
replies(4): >>45720617 #>>45720828 #>>45721171 #>>45727246 #
2. whizzter ◴[] No.45720617[source]
Should also help with syntax highlighting.
3. halapro ◴[] No.45720828[source]
Definitely not a minor feedback, there's no reason to write go in a .js file. Vite/rollup are perfectly able to "load" certain file types and parse them however you like.
replies(1): >>45726093 #
4. CamouflagedKiwi ◴[] No.45721171[source]
That would also avoid the problem with this syntax, that it's not a valid Go file (it doesn't start with `package ...` and I don't think a bare top-level string is valid), which lots of editors will be pretty unhappy about.
5. joshribakoff ◴[] No.45726093[source]
There’s no reason to unilaterally dismiss others use cases, this debate is as old as ReactJS (mixed JS and HTML).

Modern tools often make this tradeoff, like Astro, and none of the tools authors are claiming you need to use the tool.

Yes, the pattern can be abused, but dogmatic rules against mixing languages may also entail downsides.

replies(1): >>45729529 #
6. ◴[] No.45727246[source]
7. halapro ◴[] No.45729529{3}[source]
I stand firm that there's no reason to write go in a .js file other than ragebaiting, especially with that "use" directive that clearly everyone is hating on Twitter at the moment (due to Vercel, etc)

To be clear I'm fine with importing .go from JS, it's the "go in file.js" thing I don't like.