5

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.

4
  • This should help you: scala-js.org/doc/project/module.html Commented Nov 26, 2016 at 13:10
  • This link Is about emitting a module and not about how to use an existing one. Commented Nov 26, 2016 at 13:41
  • You need to emit a module to be able to import other modules. There is a link from that page to further documentation on @JSImport which shows how to define types for things you need to import. Commented Nov 26, 2016 at 15:12
  • To be able to further help you, it would be good to edit your question with a concrete example of a module you wish to import, and what you want to do with it. Commented Nov 26, 2016 at 15:13

1 Answer 1

7

This takes a few steps:

  • add the ScalaJSBundlerPlugin to your plugins.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 npmDependencies in your build.sbt (example)
  • create a custom webpack config which configures node as a target (example)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.