I just started to use Scala.js and want to port an existing node based JavaScript app to Scala.js. The first problem: I need to include the mysql module https://github.com/mysqljs/mysql to access MySQL from Scala.js.
1 Answer
This takes a few steps:
- add the
ScalaJSBundlerPluginto yourplugins.sbt(example) - enable the plugin in your
build.sbt(example) - create a facade (which can be minimal) for your Node module (example for
node-fetch) defining an object with something like@JSImport("node-fetch", JSImport.Namespace) - add
npmDependenciesin yourbuild.sbt(example) - create a custom webpack config which configures node as a target (example)
@JSImportwhich shows how to define types for things you need to import.