write WeApp with scalajs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
components/popup use component Mar 19, 2018



WeApp meets Scala.js

By implementing WeUI demo, this project is a POC that WeChat App can be implemented with Scala.js and SBT, specifically, it uses the Scala.js plugin to compile Scala sources and sbt-less to compile style sources.

A few motivations behind the project :

  1. Enjoy the Scala ecosystem !
  2. Avoid this and that of JavaScript and all of its hells and pitfalls, Scala causes much less hassles.
  3. WePY, the Tencent backed framework, only created extra boilerplates.

Following is a typical array of asynchronous calls, written in Scala way

def onLoad(): Unit = {
  val info = for {
    msg  <- Wechat.login{}
    info <- Wechat.getUserInfo(false,"en"){}
  } yield info

  Wechat.setData("userInfo", info)

How to use

sbt > assets
sbt > fullOptJS

Then use WeApp Development Tool to open the target directory. Under WeApp circumstances it makes no sense to do fastOptJS, since fullOptJS generates highly optimized JavaScript already, these options will need to be turned OFF from the project's settings:

  • convert Es6 to Es5
  • autocomplete on upload
  • compress on upload

Each page is built as a separate sbt project, so one can always use the project specific sbt tasks, for example

sbt > progress/fullOptJS
sbt > images/assets



Scala.js supports component based development, as illustrated by page example/component/component, if a component is written in Javascript it can be used directly in pages. If a component is written in Scala.js and it defines custom event, be careful to resolve the needed handlers from onReady of Pages instead of methods of Components, because Scala.js cannot (for the good) declare a magic this, which is a major sources of mystery of Javascript


For demo purpose, it does not complete the entire WeApp facade, nevertheless, this work is straightforward and could be supplemented as WeApp itself is evolving.


SBT is hard


To use Less and the sbt plugin, all the secondary component files are prefixed with underscore, such as _weui.wxss


Scala.js compiler keeps bundling those Javascript sources in the webjar, which will be picked up and loaded by WeApp. Since WeApp requires the size be less than 2M, we can simply remove the unneeded classes folders.

project $ find target/ -name classes -print | xargs rm -rf