Skip to content

Commit a1265be

Browse files
committed
Improvements to the tutorial. Thanks @akauppi for the feedback.
1 parent eac8caa commit a1265be

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

doc/tutorial.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ To setup Scala.js in a new sbt project, we need to do two things:
2121
1. Add the Scala.js sbt plugin
2222
2. Apply the Scala.js specific settings to the project
2323

24-
Adding the Scala.js sbt plugin is a one-liner in `project/build.sbt`:
24+
Adding the Scala.js sbt plugin is a one-liner in `project/plugins.sbt` (all file names we write in this tutorial are relative to the project root):
2525

2626
addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.0")
2727

28-
We also setup basic project settings and Scala.js settings in the sbt build file (`build.sbt`):
28+
We also setup basic project settings and Scala.js settings in the sbt build file (`build.sbt`, in the project root directory):
2929

3030
scalaJSSettings
3131

@@ -41,6 +41,10 @@ That is all we need to configure the build.
4141

4242
If at this point you prefer to use Eclipse or IDEA as your IDE, you may use [sbteclipse](https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse) or [idea-eclipse](https://github.com/mpeltonen/sbt-idea) project files for the IDE. Note that for compiling and running your application, you will still need to use sbt from the command line.
4343

44+
#### Alternative versions
45+
46+
You may instead use 2.10.2, 2.10.3, 2.10.4 or 2.11.0 for `scalaVersion` if you so wish. Similarly, any 0.13.x version of sbt should work without itch, for example 0.13.5.
47+
4448
### HelloWorld application
4549

4650
For starters, we add a very simple `TutorialApp` in the `tutorial.webapp` package. Create the file `src/main/scala/tutorial/webapp/TutorialApp.scala`:
@@ -66,6 +70,8 @@ As you expect, this will simply print "HelloWorld" when run. To run this, simply
6670
Hello world!
6771
[success] (...)
6872

73+
**Troubleshooting**: Should you experience errors with the `PermGen` size of the JVM at this point, you can increase it. Refer, for example, to [this StackOverflow question](http://stackoverflow.com/questions/8331135/transient-outofmemoryerror-when-compiling-scala-classes).
74+
6975
Congratulations! You have successfully compiled and run your first Scala.js application. The code is actually run by a JavaScript interpreter. If you do not believe this (it happens to us occasionally), you can use sbt's `last`:
7076

7177
> last
@@ -92,11 +98,11 @@ To generate a single JavaScript file using sbt, just use the `fastOptJS` task:
9298
[info] Fast optimizing (...)/scala-js-tutorial/target/scala-2.11/scala-js-tutorial-fastopt.js
9399
[success] (...)
94100

95-
This will perform some dead-code elimination and generate the `scala-js-tutorial-fastopt.js` file containing reachable JavaScript code.
101+
This will perform some fast optimizations and generate the `target/scala-2.11/scala-js-tutorial-fastopt.js` file containing the JavaScript code.
96102

97103
### Create the HTML Page
98104

99-
The only thing which is specific to Scala.js, is how we can call the Scala code from JavaScript. First have a look at our HTML page (`scalajs-tutorial-fastopt.html` in the project root), we will go in the details right after.
105+
To load and launch the created JavaScript, you will need an HTML file. Create the file `scalajs-tutorial-fastopt.html` (or whatever name you prefer, for example `index-fastopt.html`) in the project root with the following content. We will go in the details right after.
100106

101107
{% highlight html %}
102108
<!DOCTYPE html>
@@ -130,7 +136,7 @@ As the last step has shown, running JavaScript inside a HTML page is not particu
130136

131137
### Adding the DOM Library
132138

133-
To use the JavaScript DOM library in Scala.js, it is best to use the Scala.js DOM library which provides types for the DOM. To add it to your sbt project, add the following line to your `build.sbt`:
139+
To use the DOM, it is best to use the statically typed Scala.js DOM library. To add it to your sbt project, add the following line to your `build.sbt`:
134140

135141
libraryDependencies += "org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6"
136142

@@ -263,11 +269,11 @@ jQuery("body").append("<p>[message]</p>")
263269

264270
Where `[message]` is the string originally passed to `appendPar`.
265271

266-
### Adding JavaScript libraries
272+
If you try to reload your webpage now, it will not work (typically a `TypeError` would be reported in the console). The problem is that we haven't included the jQuery library itself, which is a plain JavaScript library.
267273

268-
You can now try and reload your webpage. You will observe that - although it seems we have done everything right - you don't see a "Hello World" message. Some browsers might give you a `TypeError`. The problem is that we haven't included the jQuery library itself, which is a plain JavaScript library.
274+
### Adding JavaScript libraries
269275

270-
An option is to include `jquery.js` from an external source, such as [jsDelivr](http://www.jsdelivr.com/)
276+
An option is to include `jquery.js` from an external source, such as [jsDelivr](http://www.jsdelivr.com/).
271277

272278
{% highlight html %}
273279
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery/2.1.1/jquery.js"></script>
@@ -375,7 +381,7 @@ According to the [explanation in uTest's readme](http://github.com/lihaoyi/utest
375381

376382
testLoader := scala.scalajs.sbtplugin.testing.JSClasspathLoader((ScalaJSKeys.execClasspath in Compile).value)
377383

378-
And the following to our `project/build.sbt`:
384+
And the following to our `project/plugins.sbt`:
379385

380386
addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.1.6")
381387

0 commit comments

Comments
 (0)