Open jorgeluismireles opened 6 days ago
For the example wasm/mandelbrot replace the vweb serve_folder.v
file with this veb main.v
file to compile and serve the wasm:
import veb
import os
const http_port = 3001
struct Context {
veb.Context
}
pub struct App {
veb.StaticHandler
}
fn main() {
os.chdir(os.dir(os.executable()))!
mut app := &App{}
veb.run_at[App, Context](mut app, port: http_port)!
}
pub fn (mut app App) before_accept_loop() {
os.execute_or_panic('v -b wasm -os browser mandelbrot.wasm.v ')
app.handle_static('.', true) or { panic('${err}') }
}
Rename mandelbrot.html
to index.html
to keep the server simple. Then:
$ v run examples/wasm/mandelbrot/main.v
[veb] Running app on http://localhost:3001/
Describe the issue
Examples
js_dom_draw
and others (js_dom_cube
) haveREADME.md
files describing how to compile v code to browser javascript manually for anode
server or automatically forvweb
to serve thehtml
andjs
files.You can delete
node/vweb
readme files and include a veb server as amain.v
like this:Is important to compile first the files
js.v
before callingapp.handle_static
otherwise, the first time whendraw.js
is not available at the current folder the server can't load it.For the example at
js_dom_cube
use a similarmain.v
changingdraw.js.v
bycube.js.v
.I tested both examples and worked without touching
index.html
and*.js.v
files:Links
https://github.com/vlang/v/tree/master/examples/js_dom_cube
https://github.com/vlang/v/tree/master/examples/js_dom_draw
Huly®: V_0.6-21052