vegafusion icon indicating copy to clipboard operation
vegafusion copied to clipboard

Provide .js build with --target web that works in simple .html file.

Open MarcSkovMadsen opened this issue 4 years ago • 5 comments

I believe a lot of the struggles I'm having in https://github.com/vegafusion/vegafusion/issues/62 could be avoided if I could have accessed a js file targetted for the web.

See https://stackoverflow.com/questions/64308461/failed-to-load-wasm-application

(I'm not sure because the world of rust, wasm etc. is not familiar to me. So I'm walking around like a blind here. I don't yet understand the terminologi).

MarcSkovMadsen avatar Jan 29 '22 06:01 MarcSkovMadsen

I have now tried to build for the web on binder. But unfortunately it is not bundled (I believe) so it raises all kinds of import errors in the browser console for 'vega', 'vega-util', 'vega-tooltip' and 'loadash'.

My steps where

Binder

curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/en
rustup update
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
git clone https://github.com/vegafusion/vegafusion.git
cd vegafusion
cd vegafusion-wasm
wasm-pack build --target web --dev # add --release if ready for it

MarcSkovMadsen avatar Jan 29 '22 08:01 MarcSkovMadsen

I would like to get to a place something like this would work (or I can bokeh build)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Simple template</title>
  </head>
  <script type="module">
      import { render_vegafusion } from "./some_file.js"
      console.log("hello world")
  </script>
  <body>
    
  </body>
</html>

Feel free to replace "./some_file.js" with a url. But I need something self contained and well described.

For now I have to give up on https://github.com/vegafusion/vegafusion/issues/62. I need help from someone who is more capable than I am in this environment.

MarcSkovMadsen avatar Jan 29 '22 08:01 MarcSkovMadsen

I got to a place where I could manually replace import from 'xzy' with urls in the files in the pkg in scripts.zip

image

and serve the index.html file on a simple web server. It almost worked but failed on require.

image

scripts.zip

MarcSkovMadsen avatar Jan 29 '22 08:01 MarcSkovMadsen

Ok. A starting point is this code sandbox. Here I seem to be able to import and use vegafusion-wasm.

https://codesandbox.io/s/panelvegafusion-2dqdt

image

MarcSkovMadsen avatar Jan 29 '22 11:01 MarcSkovMadsen

Hi Marc, I didn't quite follow whether you successfully rebuilt the vegafusion-wasm package with the --target web flag. That does look like a good approach.

In case it helps, here is the resulting directory I get when building with

wasm-pack build --release --target web -d pkg-web/ && cp package.json pkg-web/

from the vegafusion-wasm/ directory.

pkg-web.zip

jonmmease avatar Jan 29 '22 12:01 jonmmease