All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Vite Plugin Enables Writing Go Code in JavaScript Files That Compiles to WebAssembly

By

yar-kravtsov

7mo ago· 3 min readen

Summary

A Vite plugin called 'vite-plugin-use-golang' enables developers to write Go code directly in JavaScript files, which then compiles to WebAssembly at build time. The compiled Go functions become available as JavaScript functions on the window object, allowing developers to leverage Go's standard libraries and performance in browser applications. The article demonstrates this with an example of image perceptual hashing, showing how Go's image library can replace complex JavaScript implementations.

Key quotes

· 4 pulled
Write Go code in JavaScript files. It compiles to WebAssembly. Actually works.
You drop 'use golang' at the top of a JS file, write Go code, and Vite compiles it to WASM at build time.
The compiled functions show up on window like any other JavaScript function. It's absurd, but it's real.
Let's say you want to do image perceptual hashing in the browser. You could wrestle with Canvas APIs and write 200 lines of JavaScript. Or you could use Go's image standard library and let it handle the heavy lifting.
Snippet from the RSS feed
Write Go code in JavaScript files. Compiles to WebAssembly. Actually works.. Latest version: 0.1.1, last published: 4 months ago. Start using vite-plugin-use-golang in your project by running `npm i vite-plugin-use-golang`. There are no other projects in

You might also wanna read