LoginSignup
11

More than 5 years have passed since last update.

Scala.js v0.6試してみた

Posted at

Announcing Scala.js 0.6.0 http://www.scala-js.org/news/2015/02/05/announcing-scalajs-0.6.0/

事実上のstableらしいので久しぶりにやってみる。

tutorial

scalaのためにsbtを入れておく(brew install sbt等)

$ git clone git@github.com:scala-js/scalajs-tutorial.git
$ cd scalajs-tutorial
$ sbt run

scala本体とか色々インストールするんで最初は時間かかる

Node.jsで実行

build.sbtに次の一行を追加

scalaJSStage in Global := FastOptStage

sbt runするにはphantom.js入れておく必要はあった。デフォルトはrhinoでクッソ遅いとのこと。

サイズ比較

本当に最小限のhelloworldです。

package tutorial.webapp
import scala.scalajs.js.JSApp
object TutorialApp extends JSApp {
  def main(): Unit = {
    println("hello!");
  }
}

fastOptJS

開発時のビルドモード

約2sでビルド後が138k

~/s/scalajs-tutorial (0.6.x) $ sbt fastOptJS
[info] Loading project definition from /Users/mizchi/sandbox/scalajs-tutorial/project
[info] Set current project to Scala.js Tutorial (in build file:/Users/mizchi/sandbox/scalajs-tutorial/)
[info] Fast optimizing /Users/mizchi/sandbox/scalajs-tutorial/target/scala-2.11/scala-js-tutorial-fastopt.js
[success] Total time: 2 s, completed 2015/02/07 3:40:17

fullOptJS

productionビルド相当

約4sでビルド後が19k

~/s/scalajs-tutorial (0.6.x) $ sbt fullOptJS
[info] Loading project definition from /Users/mizchi/sandbox/scalajs-tutorial/project
[info] Set current project to Scala.js Tutorial (in build file:/Users/mizchi/sandbox/scalajs-tutorial/)
[info] Full Optimizing /Users/mizchi/sandbox/scalajs-tutorial/target/scala-2.11/scala-js-tutorial-opt.js
[info] Closure: 0 error(s), 0 warning(s)
[success] Total time: 4 s, completed 2015/02/07 3:42:08

サイズ

~/s/scalajs-tutorial (0.6.x) $ la target/scala-2.11/
total 1256
drwxr-xr-x  9 mizchi  staff   306B  2  7 03:42 .
drwxr-xr-x  6 mizchi  staff   204B  2  7 03:14 ..
drwxr-xr-x  4 mizchi  staff   136B  2  7 03:30 classes
-rw-r--r--  1 mizchi  staff   138K  2  7 03:40 scala-js-tutorial-fastopt.js
-rw-r--r--  1 mizchi  staff   157K  2  7 03:40 scala-js-tutorial-fastopt.js.map
-rw-r--r--  1 mizchi  staff   242K  2  7 03:40 scala-js-tutorial-jsdeps.js
-rw-r--r--  1 mizchi  staff   144B  2  7 03:40 scala-js-tutorial-launcher.js
-rw-r--r--  1 mizchi  staff    19K  2  7 03:42 scala-js-tutorial-opt.js
-rw-r--r--  1 mizchi  staff    59K  2  7 03:42 scala-js-tutorial-opt.js.map

感想

昔はビルドに3分、出力40MBとかあったのだが、すごく軽くなっててすごい(小学生並みの感想)

実行速度とライブラリの充実次第で、今選択するの全然アリな気がする。

次は周辺ツールを探す。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11