Skip to content

Commit 1114c3a

Browse files
committed
Update tutorial for Scala.js 1.3.x
This basically means: - Using xLinkJS instead of xOptJS - Include JS code from the linked directory
1 parent 960c460 commit 1114c3a

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

doc/tutorial/basic/index.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ As you expect, this will simply print "HelloWorld" when run. To run this, simply
7474
$ sbt
7575
sbt:Scala.js Tutorial> run
7676
[info] Compiling 1 Scala source to (...)/scalajs-tutorial/target/scala-2.13/classes ...
77-
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt.js
77+
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt
7878
[info] Running tutorial.webapp.TutorialApp. Hit any key to interrupt.
7979
Hello world!
8080
[success] (...)
@@ -95,13 +95,13 @@ Now that we have a simple JavaScript application, we would like to use it in an
9595

9696
### Generate JavaScript
9797

98-
To generate a single JavaScript file using sbt, just use the `fastOptJS` task:
98+
To generate JavaScript using sbt, use the `fastLinkJS` task:
9999

100-
> fastOptJS
101-
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt.js
100+
> fastLinkJS
101+
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt
102102
[success] (...)
103103

104-
This will perform some fast optimizations and generate the `target/scala-2.13/scala-js-tutorial-fastopt.js` file containing the JavaScript code.
104+
This will perform some fast optimizations and generate the `target/scala-2.13/scala-js-tutorial-fastopt/main.js` file containing the JavaScript code.
105105

106106
(It is possible that the `[info]` does not appear, if you have just run the program and not made any change to it.)
107107

@@ -118,7 +118,7 @@ To load and launch the created JavaScript, you will need an HTML file. Create th
118118
</head>
119119
<body>
120120
<!-- Include Scala.js compiled code -->
121-
<script type="text/javascript" src="./target/scala-2.13/scala-js-tutorial-fastopt.js"></script>
121+
<script type="text/javascript" src="./target/scala-2.13/scala-js-tutorial-fastopt/main.js"></script>
122122
</body>
123123
</html>
124124
{% endhighlight %}
@@ -192,20 +192,20 @@ def main(args: Array[String]): Unit = {
192192

193193
To rebuild the JavaScript, simply invoke `fastOptJS` again:
194194

195-
sbt:Scala.js Tutorial> fastOptJS
195+
sbt:Scala.js Tutorial> fastLinkJS
196196
[info] Compiling 1 Scala source to (...)/scalajs-tutorial/target/scala-2.13/classes ...
197-
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt.js
197+
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt
198198
[success] (...)
199199

200200
As you can see from the log, sbt automatically detects that the sources must be recompiled before fast optimizing.
201201

202202
You can now reload the HTML in your browser and you should see a nice "Hello World" message.
203203

204-
Re-typing `fastOptJS` each time you change your source file is cumbersome. Luckily sbt is able to watch your files and recompile as needed:
204+
Re-typing `fastLinkJS` each time you change your source file is cumbersome. Luckily sbt is able to watch your files and recompile as needed:
205205

206-
sbt:Scala.js Tutorial> ~fastOptJS
206+
sbt:Scala.js Tutorial> ~fastLinkJS
207207
[success] (...)
208-
[info] 1. Monitoring source files for scalajs-tutorial/fastOptJS...
208+
[info] 1. Monitoring source files for scalajs-tutorial/fastLinkJS...
209209
[info] Press <enter> to interrupt or '?' for more options.
210210

211211
From this point in the tutorial we assume you have an sbt with this command running, so we don't need to bother with rebuilding each time.
@@ -307,7 +307,7 @@ issue. Remember the task `run`? If you try to invoke it now, you will see someth
307307

308308
sbt:Scala.js Tutorial> run
309309
[info] Running tutorial.webapp.TutorialApp. Hit any key to interrupt.
310-
(...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt.js:819
310+
(...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-fastopt/main.js:819
311311
$thiz.Lorg_scalajs_dom_package$__f_window = window;
312312
^
313313

@@ -398,7 +398,7 @@ To run this test, simply invoke the `test` task:
398398

399399
> test
400400
[info] Compiling 1 Scala source to (...)/scalajs-tutorial/target/scala-2.13/test-classes...
401-
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-test-fastopt.js
401+
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-test-fastopt
402402
-------------------------------- Running Tests --------------------------------
403403
+ tutorial.webapp.TutorialTest.HelloWorld 2ms
404404
Tests: 1, Passed: 1, Failed: 0
@@ -435,7 +435,7 @@ You can now call the `test` task again:
435435

436436
> test
437437
[info] Compiling 1 Scala source to (...)/scalajs-tutorial/target/scala-2.13/test-classes...
438-
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-test-fastopt.js
438+
[info] Fast optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-test-fastopt
439439
-------------------------------- Running Tests --------------------------------
440440
+ tutorial.webapp.TutorialTest.HelloWorld 3ms
441441
+ tutorial.webapp.TutorialTest.ButtonClick 6ms
@@ -452,15 +452,15 @@ Here we show a couple of things you might want to do when you promote your appli
452452

453453
Size is critical for JavaScript code on the web. To compress the compiled code even further, the Scala.js sbt plugin
454454
uses the advanced optimizations of the [Google Closure Compiler](http://developers.google.com/closure/compiler/). To run
455-
full optimizations, simply use the `fullOptJS` task:
455+
full optimizations, simply use the `fullLinkJS` task:
456456

457-
> fullOptJS
458-
[info] Full optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-opt.js
457+
> fullLinkJS
458+
[info] Full optimizing (...)/scalajs-tutorial/target/scala-2.13/scala-js-tutorial-opt
459459
[info] Closure: 0 error(s), 0 warning(s)
460460
[success] (...)
461461

462-
Note that this can take a while on a larger project (tens of seconds), which is why we typically don't use `fullOptJS`
463-
during development, but `fastOptJS` instead. If you want to `run` and `test` the full-optimized version from sbt,
462+
Note that this can take a while on a larger project (tens of seconds), which is why we typically don't use `fullLinkJS`
463+
during development, but `fastLinkJS` instead. If you want to `run` and `test` the full-optimized version from sbt,
464464
you need to change the *stage* using the following sbt setting:
465465

466466
> set scalaJSStage in Global := FullOptStage
@@ -478,7 +478,7 @@ We also need to create our final production HTML file `scalajs-tutorial.html` wh
478478
</head>
479479
<body>
480480
<!-- Include Scala.js compiled code -->
481-
<script type="text/javascript" src="./target/scala-2.13/scala-js-tutorial-opt.js"></script>
481+
<script type="text/javascript" src="./target/scala-2.13/scala-js-tutorial-opt/main.js"></script>
482482
</body>
483483
</html>
484484
{% endhighlight %}

0 commit comments

Comments
 (0)