You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
29
29
30
30
scalaJSSettings
31
31
@@ -41,6 +41,10 @@ That is all we need to configure the build.
41
41
42
42
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.
43
43
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
+
44
48
### HelloWorld application
45
49
46
50
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
66
70
Hello world!
67
71
[success] (...)
68
72
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
+
69
75
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`:
70
76
71
77
> last
@@ -92,11 +98,11 @@ To generate a single JavaScript file using sbt, just use the `fastOptJS` task:
92
98
[info] Fast optimizing (...)/scala-js-tutorial/target/scala-2.11/scala-js-tutorial-fastopt.js
93
99
[success] (...)
94
100
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.
96
102
97
103
### Create the HTML Page
98
104
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.
100
106
101
107
{% highlight html %}
102
108
<!DOCTYPE html>
@@ -130,7 +136,7 @@ As the last step has shown, running JavaScript inside a HTML page is not particu
130
136
131
137
### Adding the DOM Library
132
138
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`:
Where `[message]` is the string originally passed to `appendPar`.
265
271
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.
267
273
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
269
275
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/).
0 commit comments