v86 icon indicating copy to clipboard operation
v86 copied to clipboard

Webpack support

Open parkertomatoes opened this issue 5 years ago • 2 comments

All the files in the v86 npm package seem to want to import fs when run in node. This means that my webpack build fails if I include V86.

Is there a way to import the browser libv86.js in node without manually managing the files?

parkertomatoes avatar Nov 14 '20 21:11 parkertomatoes

I'd be surprised if Webpack didn't have a way to support this scenario.

We could move the code into a separate file and conditionally include it in the build process. I'm not enthusiastic, but I'd probably accept a PR. Any other suggestions?

copy avatar Nov 29 '20 06:11 copy

I ran into a similar issue with a different build tool. This may seem a bit hacky, but I was able to get it working by re-compiling libv86.js with SWC.

npx \
  --package=@swc/cli \
  --package=@swc/core \
  -- swc \
    -C jsc.target=es2020 \
    -C jsc.transform.optimizer.globals.typeofs.window=object \
    -C jsc.transform.optimizer.globals.typeofs.require=undefined \
    -C jsc.transform.optimizer.globals.typeofs.XMLHttpRequest=function \
    -C jsc.transform.optimizer.globals.typeofs.process=undefined \
    --out-file=libv86-web.js \
    libv86.js

It might be better to do this with Closure Compiler (if it has a similar feature) since that's what is being used to build libv86.js.

jmezzacappa avatar Aug 15 '22 19:08 jmezzacappa