scalajs-bundler: which compiled file should be included in HTML?

336 views Asked by At

I'm trying to handle my JS dependencies with scalajs-bundler for my Scala.js project. It successfully downloads my dependency (d3.js), but I don't know how to include my code and the dependency in my HTML file.

I tried every files I found on target/scala-2.12/ but it didn't work.

  • with target/scala-2.12/*-jsdeps.js it doesn't run my main method.
  • with target/scala-2.12/scalajs-bundler/main/*-fastopt.js I get ReferenceError: exports is not defined in Firefox.

I don't want to use a facade, this is a short-term project and I plan to use js.Dynamic.

A side question: can I still use source maps with scalajs-bundler ?

Thanks.

2

There are 2 answers

0
Timothée Jourde On BEST ANSWER

Ok, the problem was that the final bundle file *-fastopt-bundle.js (the one to include) was missing, and apparently it was because webpack was silently unable to run because npm packages are referring to node (and not nodejs) in their shebang.

So the solution was to install nodejs-legacy on Ubuntu.

1
gzm0 On

You will need to include both the *-jsdeps.js and the *-fastopt.js.

*-jsdeps.js contains your dependencies, *-fastopt.js contains the Scala.js code (and the invocation of the main method if you enable scalaJSUseMainModuleInitializer).